Use the addressable item list functionality for global varible widget.

This commit is contained in:
Karliss 2024-05-18 19:25:32 +03:00 committed by karliss
parent 3e50e5f2ad
commit 8251f7ec68
3 changed files with 17 additions and 30 deletions

View File

@ -146,20 +146,6 @@ void GlobalsWidget::deleteGlobal()
Core()->delGlobalVariable(globalVariableAddress);
}
void GlobalsWidget::showGlobalsContextMenu(const QPoint &pt)
{
QModelIndex index = ui->treeView->indexAt(pt);
QMenu menu(ui->treeView);
if (index.isValid()) {
menu.addAction(actionEditGlobal);
menu.addAction(actionDeleteGlobal);
}
menu.exec(ui->treeView->mapToGlobal(pt));
}
GlobalsWidget::GlobalsWidget(MainWindow *main)
: CutterDockWidget(main), ui(new Ui::GlobalsWidget), tree(new CutterTreeWidget(this))
{
@ -175,6 +161,8 @@ GlobalsWidget::GlobalsWidget(MainWindow *main)
// Set single select mode
ui->treeView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->treeView->setMainWindow(mainWindow);
// Setup up the model and the proxy model
globalsModel = new GlobalsModel(&globals, this);
globalsProxyModel = new GlobalsProxyModel(globalsModel, this);
@ -182,9 +170,6 @@ GlobalsWidget::GlobalsWidget(MainWindow *main)
ui->treeView->sortByColumn(GlobalsModel::AddressColumn, Qt::AscendingOrder);
// Setup custom context menu
connect(ui->treeView, &QWidget::customContextMenuRequested, this,
&GlobalsWidget::showGlobalsContextMenu);
ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->quickFilterView, &ComboQuickFilterView::filterTextChanged, globalsProxyModel,
@ -206,8 +191,12 @@ GlobalsWidget::GlobalsWidget(MainWindow *main)
actionEditGlobal = new QAction(tr("Edit Global Variable"), this);
actionDeleteGlobal = new QAction(tr("Delete Global Variable"), this);
connect(actionEditGlobal, &QAction::triggered, [this]() { editGlobal(); });
connect(actionDeleteGlobal, &QAction::triggered, [this]() { deleteGlobal(); });
auto menu = ui->treeView->getItemContextMenu();
menu->addAction(actionEditGlobal);
menu->addAction(actionDeleteGlobal);
connect(actionEditGlobal, &QAction::triggered, this, [this]() { editGlobal(); });
connect(actionDeleteGlobal, &QAction::triggered, this, [this]() { deleteGlobal(); });
connect(Core(), &CutterCore::globalVarsChanged, this, &GlobalsWidget::refreshGlobals);
connect(Core(), &CutterCore::codeRebased, this, &GlobalsWidget::refreshGlobals);

View File

@ -69,8 +69,6 @@ public:
private slots:
void refreshGlobals();
void showGlobalsContextMenu(const QPoint &pt);
void editGlobal();
void deleteGlobal();

View File

@ -31,7 +31,7 @@
<number>0</number>
</property>
<item>
<widget class="CutterTreeView" name="treeView">
<widget class="AddressableItemList&lt;&gt;" name="treeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -46,7 +46,7 @@
}</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
@ -89,18 +89,18 @@
</action>
</widget>
<customwidgets>
<customwidget>
<class>CutterTreeView</class>
<extends>QTreeView</extends>
<header>widgets/CutterTreeView.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ComboQuickFilterView</class>
<extends>QWidget</extends>
<header>widgets/ComboQuickFilterView.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>AddressableItemList&lt;&gt;</class>
<extends>QTreeView</extends>
<header>widgets/AddressableItemList.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>