<p dir="ltr">Answering by phone. <br>
1 - why std::pair instead of qpair </p>
<p dir="ltr">Because qpair gave me a compilation error that I couldn't solve. </p>
<p dir="ltr">2 - 23 refererences to enableList and one to disable list</p>
<p dir="ltr">Read as "references for each list of properties that will be activated for each widget when the state changes" (state being add Dive, editDiveSite, etc). </p>
<p dir="ltr">Right now the only that actually makes a difference is the editDiveSite that needs to block the dive list. </p>
<p dir="ltr">3 - I'm confused by this. </p>
<p dir="ltr">Loop thru all of the pairs of "property, value" and set the property on the widget, one loop for each quadrant. When a property is set it will call a callback that will apply the correct behavior. So, if I pass the "enabled" : false as pair, setProperty("enabled", false) will call setEnabled(false) </p>
<p dir="ltr">If you dislike or have a better idea on how to achieve the same thing, I'm all ears. This one is somewhat clean and I can export later when I clean the code for the next version easily. <br><br><br></p>
<br><div class="gmail_quote"><div dir="ltr">Em sex, 21 de ago de 2015 02:27, Dirk Hohndel <<a href="mailto:dirk@hohndel.org">dirk@hohndel.org</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Aug 20, 2015 at 10:34:03PM -0300, Tomaz Canabrava wrote:<br>
> From 7129f1b4530febcffcb5729cbf918133d64f51c0 Mon Sep 17 00:00:00 2001<br>
> From: Tomaz Canabrava <<a href="mailto:tomaz.canabrava@intel.com" target="_blank">tomaz.canabrava@intel.com</a>><br>
> Date: Thu, 20 Aug 2015 22:24:49 -0300<br>
> Subject: [PATCH 2/2] Save Properties for each State of the mainWindow<br>
><br>
> Each state can have the same widgets but with different<br>
> properties - currently I'm using "enabled" : true and false<br>
> for the DiveSiteEdit, it looks like a big amount of code<br>
> for such a small thing but it was the cleaner way that<br>
> I tougth of doing.<br>
><br>
> Signed-off-by: Tomaz Canabrava <<a href="mailto:tomaz.canabrava@intel.com" target="_blank">tomaz.canabrava@intel.com</a>><br>
> ---<br>
> qt-ui/mainwindow.cpp | 31 +++++++++++++++++++++++++++++++<br>
> qt-ui/mainwindow.h | 17 +++++++++++++++++<br>
> 2 files changed, 48 insertions(+)<br>
><br>
> diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp<br>
> index 1a12305..dec5503 100644<br>
> --- a/qt-ui/mainwindow.cpp<br>
> +++ b/qt-ui/mainwindow.cpp<br>
> @@ -119,6 +119,13 @@ MainWindow::MainWindow() : QMainWindow(),<br>
><br>
> QWidget *diveSitePictures = new QWidget(); // Placeholder<br>
><br>
> + std::pair<QByteArray, QVariant> enabled = std::make_pair("enabled", QVariant(true));<br>
> + std::pair<QByteArray, QVariant> disabled = std::make_pair("enabled", QVariant(false));<br>
<br>
Why std::pair instead of QPair which we use in many other places?<br>
<br>
> + PropertyList enabledList;<br>
> + PropertyList disabledList;<br>
> + enabledList.push_back(enabled);<br>
> + disabledList.push_back(disabled);<br>
> +<br>
> registerApplicationState("Default", mainTab, profileContainer, diveListView, globeGps );<br>
> registerApplicationState("AddDive", mainTab, profileContainer, diveListView, globeGps );<br>
> registerApplicationState("EditDive", mainTab, profileContainer, diveListView, globeGps );<br>
> @@ -126,6 +133,13 @@ MainWindow::MainWindow() : QMainWindow(),<br>
> registerApplicationState("EditPlannedDive", plannerWidget, profileContainer, diveListView, globeGps );<br>
> registerApplicationState("EditDiveSite", diveSiteEdit, diveSitePictures, diveListView, globeGps);<br>
><br>
> + setStateProperties("Default", enabledList, enabledList, enabledList,enabledList);<br>
> + setStateProperties("AddDive", enabledList, enabledList, enabledList,enabledList);<br>
> + setStateProperties("EditDive", enabledList, enabledList, enabledList,enabledList);<br>
> + setStateProperties("PlanDive", enabledList, enabledList, enabledList,enabledList);<br>
> + setStateProperties("EditPlannedDive", enabledList, enabledList, enabledList,enabledList);<br>
> + setStateProperties("EditDiveSite", enabledList, enabledList, disabledList, enabledList);<br>
<br>
I'm completely baffled by this. There is one disabledList hiding in here<br>
and 23 references to enabledList.<br>
<br>
> +<br>
> setApplicationState("Default");<br>
><br>
> ui.multiFilter->hide();<br>
> @@ -213,6 +227,11 @@ MainWindow::~MainWindow()<br>
> m_Instance = NULL;<br>
> }<br>
><br>
> +void MainWindow::setStateProperties(const QByteArray& state, const PropertyList& tl, const PropertyList& tr, const PropertyList& bl, const PropertyList& br)<br>
> +{<br>
> + stateProperties[state] = PropertiesForQuadrant(tl, tr, bl, br);<br>
> +}<br>
> +<br>
> void MainWindow::on_actionDiveSiteEdit_triggered() {<br>
> setApplicationState("EditDiveSite");<br>
> }<br>
> @@ -1726,9 +1745,21 @@ void MainWindow::setApplicationState(const QByteArray& state) {<br>
> }<br>
><br>
> SET_CURRENT_INDEX( topLeft )<br>
> + Q_FOREACH(const WidgetProperty& p, stateProperties[state].topLeft) {<br>
> + ui.topLeft->currentWidget()->setProperty( p.first.data(), p.second);<br>
> + }<br>
> SET_CURRENT_INDEX( topRight )<br>
> + Q_FOREACH(const WidgetProperty& p, stateProperties[state].topRight) {<br>
> + ui.topRight->currentWidget()->setProperty( p.first.data(), p.second);<br>
> + }<br>
> SET_CURRENT_INDEX( bottomLeft )<br>
> + Q_FOREACH(const WidgetProperty& p, stateProperties[state].bottomLeft) {<br>
> + ui.bottomLeft->currentWidget()->setProperty( p.first.data(), p.second);<br>
> + }<br>
> SET_CURRENT_INDEX( bottomRight )<br>
> + Q_FOREACH(const WidgetProperty& p, stateProperties[state].bottomRight) {<br>
> + ui.bottomRight->currentWidget()->setProperty( p.first.data(), p.second);<br>
> + }<br>
<br>
So what does this do? I'm confused.<br>
<br>
> diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h<br>
> index 4df1d12..2d2ea88 100644<br>
> --- a/qt-ui/mainwindow.h<br>
> +++ b/qt-ui/mainwindow.h<br>
> @@ -39,6 +39,9 @@ class PlannerSettingsWidget;<br>
> class QUndoStack;<br>
> class LocationInformationWidget;<br>
><br>
> +typedef std::pair<QByteArray, QVariant> WidgetProperty;<br>
> +typedef QVector<WidgetProperty> PropertyList;<br>
> +<br>
> enum MainWindowTitleFormat {<br>
> MWTF_DEFAULT,<br>
> MWTF_FILENAME<br>
> @@ -89,6 +92,7 @@ public:<br>
> void printPlan();<br>
> void checkSurvey(QSettings *s);<br>
> void setApplicationState(const QByteArray& state);<br>
> + void setStateProperties(const QByteArray& state, const PropertyList& tl, const PropertyList& tr, const PropertyList& bl,const PropertyList& br);<br>
> bool inPlanner();<br>
> QUndoStack *undoStack;<br>
> NotificationWidget *getNotificationWidget();<br>
> @@ -225,7 +229,20 @@ private:<br>
> QWidget *bottomLeft;<br>
> QWidget *bottomRight;<br>
> };<br>
> +<br>
> + struct PropertiesForQuadrant {<br>
> + PropertiesForQuadrant(){}<br>
> + PropertiesForQuadrant(const PropertyList& tl, const PropertyList& tr,const PropertyList& bl,const PropertyList& br) :<br>
> + topLeft(tl), topRight(tr), bottomLeft(bl), bottomRight(br) {}<br>
> + PropertyList topLeft;<br>
> + PropertyList topRight;<br>
> + PropertyList bottomLeft;<br>
> + PropertyList bottomRight;<br>
> + };<br>
> +<br>
> QHash<QByteArray, WidgetForQuadrant> applicationState;<br>
> + QHash<QByteArray, PropertiesForQuadrant> stateProperties;<br>
> +<br>
> QByteArray currentApplicationState;<br>
> WindowTitleUpdate *wtu;<br>
> };<br>
<br>
OK, I need a bit more of an explanation before I accept this patch.<br>
<br>
/D<br>
</blockquote></div>