mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Save Properties for each State of the mainWindow
Each state can have the same widgets but with different properties - currently I'm using "enabled" : true and false for the DiveSiteEdit, it looks like a big amount of code for such a small thing but it was the cleaner way that I tougth of doing. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
307df53bb4
commit
0f096d0e53
2 changed files with 48 additions and 0 deletions
|
@ -119,6 +119,13 @@ MainWindow::MainWindow() : QMainWindow(),
|
||||||
|
|
||||||
QWidget *diveSitePictures = new QWidget(); // Placeholder
|
QWidget *diveSitePictures = new QWidget(); // Placeholder
|
||||||
|
|
||||||
|
std::pair<QByteArray, QVariant> enabled = std::make_pair("enabled", QVariant(true));
|
||||||
|
std::pair<QByteArray, QVariant> disabled = std::make_pair("enabled", QVariant(false));
|
||||||
|
PropertyList enabledList;
|
||||||
|
PropertyList disabledList;
|
||||||
|
enabledList.push_back(enabled);
|
||||||
|
disabledList.push_back(disabled);
|
||||||
|
|
||||||
registerApplicationState("Default", mainTab, profileContainer, diveListView, globeGps );
|
registerApplicationState("Default", mainTab, profileContainer, diveListView, globeGps );
|
||||||
registerApplicationState("AddDive", mainTab, profileContainer, diveListView, globeGps );
|
registerApplicationState("AddDive", mainTab, profileContainer, diveListView, globeGps );
|
||||||
registerApplicationState("EditDive", mainTab, profileContainer, diveListView, globeGps );
|
registerApplicationState("EditDive", mainTab, profileContainer, diveListView, globeGps );
|
||||||
|
@ -126,6 +133,13 @@ MainWindow::MainWindow() : QMainWindow(),
|
||||||
registerApplicationState("EditPlannedDive", plannerWidget, profileContainer, diveListView, globeGps );
|
registerApplicationState("EditPlannedDive", plannerWidget, profileContainer, diveListView, globeGps );
|
||||||
registerApplicationState("EditDiveSite", diveSiteEdit, diveSitePictures, diveListView, globeGps);
|
registerApplicationState("EditDiveSite", diveSiteEdit, diveSitePictures, diveListView, globeGps);
|
||||||
|
|
||||||
|
setStateProperties("Default", enabledList, enabledList, enabledList,enabledList);
|
||||||
|
setStateProperties("AddDive", enabledList, enabledList, enabledList,enabledList);
|
||||||
|
setStateProperties("EditDive", enabledList, enabledList, enabledList,enabledList);
|
||||||
|
setStateProperties("PlanDive", enabledList, enabledList, enabledList,enabledList);
|
||||||
|
setStateProperties("EditPlannedDive", enabledList, enabledList, enabledList,enabledList);
|
||||||
|
setStateProperties("EditDiveSite", enabledList, enabledList, disabledList, enabledList);
|
||||||
|
|
||||||
setApplicationState("Default");
|
setApplicationState("Default");
|
||||||
|
|
||||||
ui.multiFilter->hide();
|
ui.multiFilter->hide();
|
||||||
|
@ -213,6 +227,11 @@ MainWindow::~MainWindow()
|
||||||
m_Instance = NULL;
|
m_Instance = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setStateProperties(const QByteArray& state, const PropertyList& tl, const PropertyList& tr, const PropertyList& bl, const PropertyList& br)
|
||||||
|
{
|
||||||
|
stateProperties[state] = PropertiesForQuadrant(tl, tr, bl, br);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionDiveSiteEdit_triggered() {
|
void MainWindow::on_actionDiveSiteEdit_triggered() {
|
||||||
setApplicationState("EditDiveSite");
|
setApplicationState("EditDiveSite");
|
||||||
}
|
}
|
||||||
|
@ -1726,9 +1745,21 @@ void MainWindow::setApplicationState(const QByteArray& state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SET_CURRENT_INDEX( topLeft )
|
SET_CURRENT_INDEX( topLeft )
|
||||||
|
Q_FOREACH(const WidgetProperty& p, stateProperties[state].topLeft) {
|
||||||
|
ui.topLeft->currentWidget()->setProperty( p.first.data(), p.second);
|
||||||
|
}
|
||||||
SET_CURRENT_INDEX( topRight )
|
SET_CURRENT_INDEX( topRight )
|
||||||
|
Q_FOREACH(const WidgetProperty& p, stateProperties[state].topRight) {
|
||||||
|
ui.topRight->currentWidget()->setProperty( p.first.data(), p.second);
|
||||||
|
}
|
||||||
SET_CURRENT_INDEX( bottomLeft )
|
SET_CURRENT_INDEX( bottomLeft )
|
||||||
|
Q_FOREACH(const WidgetProperty& p, stateProperties[state].bottomLeft) {
|
||||||
|
ui.bottomLeft->currentWidget()->setProperty( p.first.data(), p.second);
|
||||||
|
}
|
||||||
SET_CURRENT_INDEX( bottomRight )
|
SET_CURRENT_INDEX( bottomRight )
|
||||||
|
Q_FOREACH(const WidgetProperty& p, stateProperties[state].bottomRight) {
|
||||||
|
ui.bottomRight->currentWidget()->setProperty( p.first.data(), p.second);
|
||||||
|
}
|
||||||
#undef SET_CURRENT_INDEX
|
#undef SET_CURRENT_INDEX
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,9 @@ class PlannerSettingsWidget;
|
||||||
class QUndoStack;
|
class QUndoStack;
|
||||||
class LocationInformationWidget;
|
class LocationInformationWidget;
|
||||||
|
|
||||||
|
typedef std::pair<QByteArray, QVariant> WidgetProperty;
|
||||||
|
typedef QVector<WidgetProperty> PropertyList;
|
||||||
|
|
||||||
enum MainWindowTitleFormat {
|
enum MainWindowTitleFormat {
|
||||||
MWTF_DEFAULT,
|
MWTF_DEFAULT,
|
||||||
MWTF_FILENAME
|
MWTF_FILENAME
|
||||||
|
@ -89,6 +92,7 @@ public:
|
||||||
void printPlan();
|
void printPlan();
|
||||||
void checkSurvey(QSettings *s);
|
void checkSurvey(QSettings *s);
|
||||||
void setApplicationState(const QByteArray& state);
|
void setApplicationState(const QByteArray& state);
|
||||||
|
void setStateProperties(const QByteArray& state, const PropertyList& tl, const PropertyList& tr, const PropertyList& bl,const PropertyList& br);
|
||||||
bool inPlanner();
|
bool inPlanner();
|
||||||
QUndoStack *undoStack;
|
QUndoStack *undoStack;
|
||||||
NotificationWidget *getNotificationWidget();
|
NotificationWidget *getNotificationWidget();
|
||||||
|
@ -225,7 +229,20 @@ private:
|
||||||
QWidget *bottomLeft;
|
QWidget *bottomLeft;
|
||||||
QWidget *bottomRight;
|
QWidget *bottomRight;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
QHash<QByteArray, WidgetForQuadrant> applicationState;
|
QHash<QByteArray, WidgetForQuadrant> applicationState;
|
||||||
|
QHash<QByteArray, PropertiesForQuadrant> stateProperties;
|
||||||
|
|
||||||
QByteArray currentApplicationState;
|
QByteArray currentApplicationState;
|
||||||
WindowTitleUpdate *wtu;
|
WindowTitleUpdate *wtu;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue