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); 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) GlobalsWidget::GlobalsWidget(MainWindow *main)
: CutterDockWidget(main), ui(new Ui::GlobalsWidget), tree(new CutterTreeWidget(this)) : CutterDockWidget(main), ui(new Ui::GlobalsWidget), tree(new CutterTreeWidget(this))
{ {
@ -175,6 +161,8 @@ GlobalsWidget::GlobalsWidget(MainWindow *main)
// Set single select mode // Set single select mode
ui->treeView->setSelectionMode(QAbstractItemView::SingleSelection); ui->treeView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->treeView->setMainWindow(mainWindow);
// Setup up the model and the proxy model // Setup up the model and the proxy model
globalsModel = new GlobalsModel(&globals, this); globalsModel = new GlobalsModel(&globals, this);
globalsProxyModel = new GlobalsProxyModel(globalsModel, this); globalsProxyModel = new GlobalsProxyModel(globalsModel, this);
@ -182,9 +170,6 @@ GlobalsWidget::GlobalsWidget(MainWindow *main)
ui->treeView->sortByColumn(GlobalsModel::AddressColumn, Qt::AscendingOrder); ui->treeView->sortByColumn(GlobalsModel::AddressColumn, Qt::AscendingOrder);
// Setup custom context menu // Setup custom context menu
connect(ui->treeView, &QWidget::customContextMenuRequested, this,
&GlobalsWidget::showGlobalsContextMenu);
ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->quickFilterView, &ComboQuickFilterView::filterTextChanged, globalsProxyModel, connect(ui->quickFilterView, &ComboQuickFilterView::filterTextChanged, globalsProxyModel,
@ -206,8 +191,12 @@ GlobalsWidget::GlobalsWidget(MainWindow *main)
actionEditGlobal = new QAction(tr("Edit Global Variable"), this); actionEditGlobal = new QAction(tr("Edit Global Variable"), this);
actionDeleteGlobal = new QAction(tr("Delete Global Variable"), this); actionDeleteGlobal = new QAction(tr("Delete Global Variable"), this);
connect(actionEditGlobal, &QAction::triggered, [this]() { editGlobal(); }); auto menu = ui->treeView->getItemContextMenu();
connect(actionDeleteGlobal, &QAction::triggered, [this]() { deleteGlobal(); }); 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::globalVarsChanged, this, &GlobalsWidget::refreshGlobals);
connect(Core(), &CutterCore::codeRebased, this, &GlobalsWidget::refreshGlobals); connect(Core(), &CutterCore::codeRebased, this, &GlobalsWidget::refreshGlobals);

View File

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

View File

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