From: Rene Gassmoeller Date: Fri, 31 Mar 2017 16:42:06 +0000 (-0600) Subject: Add context menu and set to default X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fc179e3e025513f978cdcd0db0b9a40a2e92514;p=parameter_gui.git Add context menu and set to default --- diff --git a/mainwindow.cpp b/mainwindow.cpp index 3b75cb9..615e521 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -50,6 +50,11 @@ namespace dealii tree_widget->setEditTriggers(QAbstractItemView::DoubleClicked| QAbstractItemView::SelectedClicked| QAbstractItemView::EditKeyPressed); + + //Enable right click menu in tree + tree_widget->setContextMenuPolicy(Qt::ActionsContextMenu); + context_menu = new QMenu(tree_widget); + // set which actions will initiate item editing: Editing starts when: // DoubleClicked: an item is double clicked // SelectedClicked: clicking on an already selected item @@ -94,6 +99,14 @@ namespace dealii + void MainWindow::set_to_default() + { + QTreeWidgetItem * current_item = tree_widget->currentItem(); + current_item->setText(1,current_item->text(2)); + } + + + void MainWindow::open() { if (maybe_save()) // check, if the content was modified @@ -275,6 +288,10 @@ namespace dealii about_qt_act = new QAction(tr("About &Qt"), this); about_qt_act->setStatusTip(tr("Show the Qt library's About box")); connect(about_qt_act, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + + set_to_default_act = new QAction("Set to default",context_menu); + tree_widget->addAction(set_to_default_act); + connect(set_to_default_act, SIGNAL(triggered()), this, SLOT(set_to_default())); } diff --git a/mainwindow.h b/mainwindow.h index a6eecfe..360d59b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -98,6 +98,12 @@ namespace dealii */ void set_documentation_text(QTreeWidgetItem *selected_item, QTreeWidgetItem *previous_item); + + /** + * A slot that is called when the active + * tree item should be set to its default value. + */ + void set_to_default(); private: /** * Show an information dialog, how @@ -150,6 +156,10 @@ namespace dealii * and about Qt */ QMenu * help_menu; + /** + * This menu provides context menu options for the active tree item. + */ + QMenu * context_menu; /** * QAction open a file. */ @@ -174,6 +184,11 @@ namespace dealii * QAction about Qt. */ QAction * about_qt_act; + /** + * QAction set_to_default. + */ + QAction * set_to_default_act; + /** * This value stores the current filename we work on. */