Answering by phone.
1 - why std::pair instead of qpair

Because qpair gave me a compilation error that I couldn't solve.

2 - 23 refererences to enableList and one to disable list

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).

Right now the only that actually makes a difference is the editDiveSite
that needs to block the dive list.

3 - I'm confused by this.

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)

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.



Em sex, 21 de ago de 2015 02:27, Dirk Hohndel <[email protected]> escreveu:

> On Thu, Aug 20, 2015 at 10:34:03PM -0300, Tomaz Canabrava wrote:
> > From 7129f1b4530febcffcb5729cbf918133d64f51c0 Mon Sep 17 00:00:00 2001
> > From: Tomaz Canabrava <[email protected]>
> > Date: Thu, 20 Aug 2015 22:24:49 -0300
> > Subject: [PATCH 2/2] 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 <[email protected]>
> > ---
> >  qt-ui/mainwindow.cpp | 31 +++++++++++++++++++++++++++++++
> >  qt-ui/mainwindow.h   | 17 +++++++++++++++++
> >  2 files changed, 48 insertions(+)
> >
> > diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
> > index 1a12305..dec5503 100644
> > --- a/qt-ui/mainwindow.cpp
> > +++ b/qt-ui/mainwindow.cpp
> > @@ -119,6 +119,13 @@ MainWindow::MainWindow() : QMainWindow(),
> >
> >       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));
>
> Why std::pair instead of QPair which we use in many other places?
>
> > +     PropertyList enabledList;
> > +     PropertyList disabledList;
> > +     enabledList.push_back(enabled);
> > +     disabledList.push_back(disabled);
> > +
> >       registerApplicationState("Default", mainTab, profileContainer,
> diveListView, globeGps );
> >       registerApplicationState("AddDive", mainTab, profileContainer,
> diveListView, globeGps );
> >       registerApplicationState("EditDive", mainTab, profileContainer,
> diveListView, globeGps );
> > @@ -126,6 +133,13 @@ MainWindow::MainWindow() : QMainWindow(),
> >       registerApplicationState("EditPlannedDive", plannerWidget,
> profileContainer, 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);
>
> I'm completely baffled by this. There is one disabledList hiding in here
> and 23 references to enabledList.
>
> > +
> >       setApplicationState("Default");
> >
> >       ui.multiFilter->hide();
> > @@ -213,6 +227,11 @@ MainWindow::~MainWindow()
> >       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() {
> >       setApplicationState("EditDiveSite");
> >  }
> > @@ -1726,9 +1745,21 @@ void MainWindow::setApplicationState(const
> QByteArray& state) {
> >       }
> >
> >       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 )
> > +     Q_FOREACH(const WidgetProperty& p,
> stateProperties[state].topRight) {
> > +             ui.topRight->currentWidget()->setProperty( p.first.data(),
> p.second);
> > +     }
> >       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 )
> > +     Q_FOREACH(const WidgetProperty& p,
> stateProperties[state].bottomRight) {
> > +             ui.bottomRight->currentWidget()->setProperty(
> p.first.data(), p.second);
> > +     }
>
> So what does this do? I'm confused.
>
> > diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
> > index 4df1d12..2d2ea88 100644
> > --- a/qt-ui/mainwindow.h
> > +++ b/qt-ui/mainwindow.h
> > @@ -39,6 +39,9 @@ class PlannerSettingsWidget;
> >  class QUndoStack;
> >  class LocationInformationWidget;
> >
> > +typedef std::pair<QByteArray, QVariant> WidgetProperty;
> > +typedef QVector<WidgetProperty> PropertyList;
> > +
> >  enum MainWindowTitleFormat {
> >       MWTF_DEFAULT,
> >       MWTF_FILENAME
> > @@ -89,6 +92,7 @@ public:
> >       void printPlan();
> >       void checkSurvey(QSettings *s);
> >       void setApplicationState(const QByteArray& state);
> > +     void setStateProperties(const QByteArray& state, const
> PropertyList& tl, const PropertyList& tr, const PropertyList& bl,const
> PropertyList& br);
> >       bool inPlanner();
> >       QUndoStack *undoStack;
> >       NotificationWidget *getNotificationWidget();
> > @@ -225,7 +229,20 @@ private:
> >               QWidget *bottomLeft;
> >               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, PropertiesForQuadrant> stateProperties;
> > +
> >       QByteArray currentApplicationState;
> >       WindowTitleUpdate *wtu;
> >  };
>
> OK, I need a bit more of an explanation before I accept this patch.
>
> /D
>
_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to