implify recent file handling in mainwindow.cpp

The old code used to be unnecessarily complex: the recent files list
was extended for each file and shrunk if a load failed.

By adding a file to the recent file list only if the load succeeded, a
whole method could be removed.

Other changes: keep track of the recent files using a QStringList and
clearly separate the actions:
 - Read recent files from settings [loadRecentFiles()]
 - Write recent files to settings [updateRecentFiles()]
 - Update the recent files actions in the menu [updateRecentFilesMenu()]
 - Add a file to the list of recent files [addRecentFile()]
With this reorganization the code hopefully became more clear.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2017-11-30 11:52:42 +01:00 committed by Lubomir I. Ivanov
parent 625298a7b8
commit 135ea00d88
2 changed files with 49 additions and 134 deletions

View file

@ -19,6 +19,8 @@
#include "core/windowtitleupdate.h"
#include "core/gpslocation.h"
#define NUM_RECENT_FILES 4
class QSortFilterProxyModel;
class DiveTripModel;
class QItemSelection;
@ -63,9 +65,10 @@ public:
virtual ~MainWindow();
static MainWindow *instance();
MainTab *information();
void loadRecentFiles(QSettings *s);
void addRecentFile(const QStringList &newFiles);
void removeRecentFile(QStringList failedFiles);
void loadRecentFiles();
void updateRecentFiles();
void updateRecentFilesMenu();
void addRecentFile(const QString &file, bool update);
DiveListView *dive_list();
DivePlannerWidget *divePlannerWidget();
PlannerSettingsWidget *divePlannerSettingsWidget();
@ -218,6 +221,7 @@ private:
struct dive copyPasteDive;
struct dive_components what;
QList<QAction *> profileToolbarActions;
QStringList recentFiles;
struct WidgetForQuadrant {
WidgetForQuadrant(QWidget *tl = 0, QWidget *tr = 0, QWidget *bl = 0, QWidget *br = 0) :