diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2017-11-30 17:44:32 +0100 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-12-01 03:39:10 +0100 |
commit | 4296ca11a6a663dd61ec917efd6f50016709b25a (patch) | |
tree | f45b834ac730295ee5a0b9265c16a32e42ddeca4 /desktop-widgets/mainwindow.cpp | |
parent | 1208bc8428baae28ebf24a3cdf00bf4b0c030fd7 (diff) | |
download | subsurface-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/mainwindow.cpp')
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 13 |
1 files changed, 7 insertions, 6 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)); |