diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-05-10 20:51:25 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-05-12 12:33:55 -0700 |
commit | ca6aa3813956b5e8be68b86ed36a5786b3ee746f (patch) | |
tree | 3c6760a3deebcc1dae8be6c1141fd9ed300c992f /desktop-widgets/mainwindow.h | |
parent | 75767c456a2889d213621866a9f7fbb108f3366d (diff) | |
download | subsurface-ca6aa3813956b5e8be68b86ed36a5786b3ee746f.tar.gz |
Mainwindow: simplify application-state code
The way the application state would enable/disable widgets was very
"dynamic". A property-list would be generated and put in a set
of arrays. Very hard to figure out what is going on.
Replace these property-list by flags and explicit old-fashioned boolean
expressions.
Join the two arrays (widget- and property-lists) into an array of
a unified data structure.
Replace the macro that sets the widgets by a simple static function.
Factor out the four loops that added widgets to the quadrants into
a simple static function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/mainwindow.h')
-rw-r--r-- | desktop-widgets/mainwindow.h | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h index a929cf764..67a253eca 100644 --- a/desktop-widgets/mainwindow.h +++ b/desktop-widgets/mainwindow.h @@ -77,7 +77,6 @@ public: void printPlan(); void checkSurvey(); void setApplicationState(ApplicationState state); - void setStateProperties(ApplicationState state, const PropertyList& tl, const PropertyList& tr, const PropertyList& bl,const PropertyList& br); bool inPlanner(); NotificationWidget *getNotificationWidget(); void enableDisableCloudActions(); @@ -213,7 +212,6 @@ private: void toggleCollapsible(bool toggle); void showFilterIfEnabled(); void updateLastUsedDir(const QString &s); - void registerApplicationState(ApplicationState state, QWidget *topLeft, QWidget *topRight, QWidget *bottomLeft, QWidget *bottomRight); void enterState(CurrentState); bool filesAsArguments; UpdateManager *updateManager; @@ -231,27 +229,27 @@ private: QStringList recentFiles; QAction *actionsRecent[NUM_RECENT_FILES]; - struct WidgetForQuadrant { - WidgetForQuadrant(QWidget *tl = 0, QWidget *tr = 0, QWidget *bl = 0, QWidget *br = 0) : - topLeft(tl), topRight(tr), bottomLeft(bl), bottomRight(br) {} - QWidget *topLeft; - QWidget *topRight; - QWidget *bottomLeft; - QWidget *bottomRight; + enum { + FLAG_NONE = 0, + FLAG_DISABLED = 1 + }; + + struct Quadrant { + QWidget *widget; + int flags; }; - struct PropertiesForQuadrant { - PropertiesForQuadrant(){} - PropertiesForQuadrant(const PropertyList& tl, const PropertyList& tr,const PropertyList& bl,const PropertyList& br) : - topLeft(tl), topRight(tr), bottomLeft(bl), bottomRight(br) {} - PropertyList topLeft; - PropertyList topRight; - PropertyList bottomLeft; - PropertyList bottomRight; + struct Quadrants { + Quadrant topLeft; + Quadrant topRight; + Quadrant bottomLeft; + Quadrant bottomRight; }; - WidgetForQuadrant applicationState[(size_t)ApplicationState::Count]; - PropertiesForQuadrant stateProperties[(size_t)ApplicationState::Count]; + Quadrants applicationState[(size_t)ApplicationState::Count]; + static void setQuadrant(const Quadrant &, QStackedWidget *); + static void addWidgets(const Quadrant &, QStackedWidget *); + void registerApplicationState(ApplicationState state, Quadrants q); GpsLocation *locationProvider; QMenu *connections; |