feat: reimplement contextmenu
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
@ -89,6 +89,7 @@ void InstanceView::createTable() {
|
||||
connect(m_table, &QTableView::doubleClicked, this, &InstanceView::activateInstance);
|
||||
connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &InstanceView::currentRowChanged);
|
||||
connect(m_table->selectionModel(), &QItemSelectionModel::currentColumnChanged, this, &InstanceView::selectNameColumn);
|
||||
connect(m_table, &QWidget::customContextMenuRequested, this, &InstanceView::contextMenuRequested);
|
||||
}
|
||||
|
||||
InstancePtr InstanceView::currentInstance() {
|
||||
@ -137,6 +138,16 @@ void InstanceView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bo
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceView::contextMenuRequested(const QPoint pos) {
|
||||
QModelIndex index = m_table->indexAt(pos);
|
||||
|
||||
if (index.isValid()) {
|
||||
int row = mappedIndex(index).row();
|
||||
InstancePtr inst = m_instances->at(row);
|
||||
emit showContextMenu(m_table->mapToParent(pos), inst);
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex InstanceView::mappedIndex(const QModelIndex& index) const {
|
||||
return m_proxy->mapToSource(index);
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
signals:
|
||||
void instanceActivated(InstancePtr inst);
|
||||
void currentInstanceChanged(InstancePtr current, InstancePtr previous);
|
||||
void showContextMenu(const QPoint pos, InstancePtr inst);
|
||||
|
||||
private slots:
|
||||
void activateInstance(const QModelIndex& index);
|
||||
@ -51,6 +52,7 @@ private slots:
|
||||
void selectNameColumn(const QModelIndex& current, const QModelIndex& previous);
|
||||
// emits currentRowChanged if a data update affected the current instance
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||
void contextMenuRequested(const QPoint pos);
|
||||
|
||||
private:
|
||||
void createTable();
|
||||
|
Reference in New Issue
Block a user