summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2017-11-30 17:44:32 +0100
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-12-01 03:39:10 +0100
commit4296ca11a6a663dd61ec917efd6f50016709b25a (patch)
treef45b834ac730295ee5a0b9265c16a32e42ddeca4 /desktop-widgets
parent1208bc8428baae28ebf24a3cdf00bf4b0c030fd7 (diff)
downloadsubsurface-4296ca11a6a663dd61ec917efd6f50016709b25a.tar.gz
Dynamically generate recent files actions
Instead of using four recent files actions defined in mainwindow.ui, generate these actions dynamically depending on the macro NUM_RECENT_FILES. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/mainwindow.cpp13
-rw-r--r--desktop-widgets/mainwindow.h1
-rw-r--r--desktop-widgets/mainwindow.ui25
3 files changed, 8 insertions, 31 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 3c331b5fb..01b09e04c 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -201,11 +201,12 @@ MainWindow::MainWindow() : QMainWindow(),
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), divePlannerWidget(), SLOT(settingsChanged()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), divePlannerSettingsWidget(), SLOT(settingsChanged()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), TankInfoModel::instance(), SLOT(update()));
- // TODO: Make the number of actions depend on NUM_RECENT_FILES
- connect(ui.actionRecent1, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
- connect(ui.actionRecent2, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
- connect(ui.actionRecent3, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
- connect(ui.actionRecent4, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
+ for (int i = 0; i < NUM_RECENT_FILES; i++) {
+ actionsRecent[i] = new QAction(this);
+ ui.menuFile->insertAction(ui.actionQuit, actionsRecent[i]);
+ connect(actionsRecent[i], SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
+ }
+ ui.menuFile->insertSeparator(ui.actionQuit);
connect(information(), SIGNAL(addDiveFinished()), graphics(), SLOT(setProfileState()));
connect(information(), SIGNAL(dateTimeChanged()), graphics(), SLOT(dateTimeChanged()));
connect(DivePlannerPointsModel::instance(), SIGNAL(planCreated()), this, SLOT(planCreated()));
@@ -1543,7 +1544,7 @@ void MainWindow::loadRecentFiles()
void MainWindow::updateRecentFilesMenu()
{
for (int c = 0; c < NUM_RECENT_FILES; c++) {
- QAction *action = this->findChild<QAction *>(QString("actionRecent%1").arg(c + 1));
+ QAction *action = actionsRecent[c];
if (recentFiles.count() > c) {
QFileInfo fi(recentFiles.at(c));
diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h
index 237efd993..75c32c2e4 100644
--- a/desktop-widgets/mainwindow.h
+++ b/desktop-widgets/mainwindow.h
@@ -222,6 +222,7 @@ private:
struct dive_components what;
QList<QAction *> profileToolbarActions;
QStringList recentFiles;
+ QAction *actionsRecent[NUM_RECENT_FILES];
struct WidgetForQuadrant {
WidgetForQuadrant(QWidget *tl = 0, QWidget *tr = 0, QWidget *bl = 0, QWidget *br = 0) :
diff --git a/desktop-widgets/mainwindow.ui b/desktop-widgets/mainwindow.ui
index 67adccb23..8c8de5507 100644
--- a/desktop-widgets/mainwindow.ui
+++ b/desktop-widgets/mainwindow.ui
@@ -75,11 +75,6 @@
<addaction name="separator"/>
<addaction name="actionHash_images"/>
<addaction name="actionConfigure_Dive_Computer"/>
- <addaction name="actionRecent1"/>
- <addaction name="actionRecent2"/>
- <addaction name="actionRecent3"/>
- <addaction name="actionRecent4"/>
- <addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuLog">
@@ -421,26 +416,6 @@
<string notr="true">F11</string>
</property>
</action>
- <action name="actionRecent1">
- <property name="visible">
- <bool>false</bool>
- </property>
- </action>
- <action name="actionRecent2">
- <property name="visible">
- <bool>false</bool>
- </property>
- </action>
- <action name="actionRecent3">
- <property name="visible">
- <bool>false</bool>
- </property>
- </action>
- <action name="actionRecent4">
- <property name="visible">
- <bool>false</bool>
- </property>
- </action>
<action name="action_Check_for_Updates">
<property name="text">
<string>&amp;Check for updates</string>