@@ -482,6 +482,20 @@ size_t KsViewModel::search(int column,
return matchList->count();
}
+/** @brief Reimplements handler to return a flags that enables the item
+ * (ItemIsEnabled) and allows it to be selecte.
+ *
+ * @param index: The index of the item.
+ *
+ * @returns Returns the item flags for the given index.
+ */
+Qt::ItemFlags KsViewModel::flags(const QModelIndex &index) const {
+ if (!index.isValid())
+ return Qt::ItemIsEnabled;
+
+ return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
+}
+
/** Create a default (empty) KsFilterProxyModel object. */
KsGraphModel::KsGraphModel(QObject *parent)
: QAbstractTableModel(parent)
@@ -130,6 +130,8 @@ public:
TRACE_VIEW_N_COLUMNS,
};
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+
private:
void _updateHeader();
@@ -19,6 +19,26 @@
#include "KsTraceViewer.hpp"
#include "KsWidgetsLib.hpp"
+/**
+ * Reimplemented handler for creating delegate widget.
+ */
+QWidget *KsTableItemDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const {
+ QTextEdit *edit = new QTextEdit(parent);
+ edit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ edit->setReadOnly(true);
+ return edit;
+}
+
+/**
+ * Reimplemented handler setting the data shown by the delegate widget.
+ */
+void KsTableItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
+ QTextEdit *textEditor = qobject_cast<QTextEdit *>(editor);
+ textEditor->setPlainText(_model->getValueStr(index.column(), index.row()));
+}
+
/**
* Reimplemented handler for mouse press events. Right mouse click events will
* be ignored. This is done because we want the Right click is being used to
@@ -47,13 +67,13 @@ void KsTableView::scrollTo(const QModelIndex &index, ScrollHint hint)
QTableView::scrollTo(index, hint);
}
-
/** Create a default (empty) Trace viewer widget. */
KsTraceViewer::KsTraceViewer(QWidget *parent)
: KsWidgetsLib::KsDataWidget(parent),
_view(this),
_model(this),
_proxyModel(this),
+ _itemDelegate(&_model, this),
_toolbar(this),
_labelSearch("Search: Column", this),
_labelGrFollows("Graph follows ", this),
@@ -144,7 +164,7 @@ KsTraceViewer::KsTraceViewer(QWidget *parent)
/* Initialize the trace viewer. */
_view.horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
_view.verticalHeader()->setVisible(false);
- _view.setEditTriggers(QAbstractItemView::NoEditTriggers);
+ _view.setEditTriggers(QAbstractItemView::DoubleClicked);
_view.setSelectionBehavior(QAbstractItemView::SelectRows);
_view.setSelectionMode(QAbstractItemView::SingleSelection);
_view.verticalHeader()->setDefaultSectionSize(defaultRowHeight);
@@ -152,7 +172,8 @@ KsTraceViewer::KsTraceViewer(QWidget *parent)
_view.horizontalHeader()->setFont(
QFontDatabase::systemFont(QFontDatabase::GeneralFont));
- _proxyModel.setSource(&_model);
+ _view.setItemDelegate(&_itemDelegate);
+ _proxyModel.setSource(&_model);
_selectionModel.setModel(&_proxyModel);
_view.setModel(&_proxyModel);
_view.setSelectionModel(&_selectionModel);
@@ -22,6 +22,26 @@
#include "KsDualMarker.hpp"
#include "KsWidgetsLib.hpp"
+/**
+ * Class used to customize the display of the data items from the model.
+ */
+class KsTableItemDelegate : public QItemDelegate
+{
+public:
+ /** Create KsTableItemDelegate. */
+ KsTableItemDelegate(KsViewModel *model, QWidget *parent = nullptr)
+ : QItemDelegate(parent),
+ _model(model) {};
+
+private:
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override;
+
+ void setEditorData(QWidget *editor, const QModelIndex &index) const override;
+
+ KsViewModel *_model;
+};
+
/**
* Table View class, needed in order to reimplemented the handler for mouse
* press events.
@@ -108,6 +128,8 @@ private:
QItemSelectionModel _selectionModel;
+ KsTableItemDelegate _itemDelegate;
+
QToolBar _toolbar;
QLabel _labelSearch, _labelGrFollows;
Implement an item delegate class for the Table widget. This will make possible the text of the records to be selected and copied so that it can be pasted into another windows. Signed-off-by: Yordan Karadzhov <y.karadz@gmail.com> --- src/KsModels.cpp | 14 ++++++++++++++ src/KsModels.hpp | 2 ++ src/KsTraceViewer.cpp | 27 ++++++++++++++++++++++++--- src/KsTraceViewer.hpp | 22 ++++++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-)