Skip to content

Commit

Permalink
Use the addressable item list functionality for global varible widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
karliss committed May 19, 2024
1 parent 3e50e5f commit 8251f7e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
27 changes: 8 additions & 19 deletions src/widgets/GlobalsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -175,16 +161,15 @@ 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);
ui->treeView->setModel(globalsProxyModel);
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,
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/widgets/GlobalsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class GlobalsWidget : public CutterDockWidget
private slots:
void refreshGlobals();

void showGlobalsContextMenu(const QPoint &pt);

void editGlobal();
void deleteGlobal();

Expand Down
18 changes: 9 additions & 9 deletions src/widgets/GlobalsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -73,7 +73,7 @@
</widget>
<action name="actionEditGlobal">
<property name="text">
<string>Edit Global Variable</string>
<string>Edit Global Variable</string>
</property>
<property name="toolTip">
<string>Edit Global Variable</string>
Expand All @@ -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/>
Expand Down

0 comments on commit 8251f7e

Please sign in to comment.