summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-21 18:16:19 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-21 14:25:34 -0800
commitbd960368922f16bc96d114c684cc381754c58a6a (patch)
tree7d96acab8b7b70d5b20093bd7237d4297397bb12
parentb08da94007d7a2e71f932bff67750051c1ad5d65 (diff)
downloadsubsurface-bd960368922f16bc96d114c684cc381754c58a6a.tar.gz
Better use of the preferences changed signal.
When the preferences changed signal is fired, the items that can change their visual based on the preferences now have to reimplement the preferencesChanged method, so they know if they need to be replotted on screen. I already implemented that for two of the items ( ProfileDepth and Ceiling ) but others might need that too. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/profile/diveprofileitem.cpp35
-rw-r--r--qt-ui/profile/diveprofileitem.h6
2 files changed, 33 insertions, 8 deletions
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index bf8af7956..158202638 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -18,7 +18,11 @@
AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(),
hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1)
{
- connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(modelDataChanged()));
+ connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(preferencesChanged()));
+}
+
+void AbstractProfilePolygonItem::preferencesChanged()
+{
}
void AbstractProfilePolygonItem::setHorizontalAxis(DiveCartesianAxis* horizontal)
@@ -36,6 +40,7 @@ void AbstractProfilePolygonItem::setHorizontalDataColumn(int column)
void AbstractProfilePolygonItem::setModel(DivePlotDataModel* model)
{
dataModel = model;
+ connect(dataModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelDataChanged()));
modelDataChanged();
}
@@ -102,6 +107,9 @@ void DiveProfileItem::modelDataChanged(){
if(polygon().isEmpty())
return;
+ show_reported_ceiling = prefs.profile_dc_ceiling;
+ reported_ceiling_in_red = prefs.profile_red_ceiling;
+
/* Show any ceiling we may have encountered */
if (prefs.profile_dc_ceiling && !prefs.profile_red_ceiling) {
QPolygonF p = polygon();
@@ -124,7 +132,7 @@ void DiveProfileItem::modelDataChanged(){
QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom());
pat.setColorAt(1, getColor(DEPTH_BOTTOM));
pat.setColorAt(0, getColor(DEPTH_TOP));
- setBrush(QBrush(pat));
+ setBrush(QBrush(pat));AbstractProfilePolygonItem::preferencesChanged();
int last = -1;
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
@@ -148,6 +156,14 @@ void DiveProfileItem::modelDataChanged(){
}
}
+void DiveProfileItem::preferencesChanged()
+{
+ //TODO: Only modelDataChanged() here if we need to rebuild the graph ( for instance,
+ // if the prefs.profile_dc_ceiling are enabled, but prefs.profile_red_ceiling is disabled
+ // and only if it changed something. let's not waste cpu cycles repoloting something we don't need to.
+ modelDataChanged();
+}
+
void DiveProfileItem::plot_depth_sample(struct plot_data *entry,QFlags<Qt::AlignmentFlag> flags,const QColor& color)
{
int decimals;
@@ -371,12 +387,6 @@ void DiveReportedCeiling::modelDataChanged()
if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
return;
- if (prefs.profile_dc_ceiling){
- setVisible(prefs.profile_red_ceiling);
- }else{
- setVisible(false);
- }
-
QPolygonF p;
p.append(QPointF(hAxis->posAtValue(0), vAxis->posAtValue(0)));
plot_data *entry = dataModel->data();
@@ -399,6 +409,15 @@ void DiveReportedCeiling::modelDataChanged()
setBrush(pat);
}
+void DiveReportedCeiling::preferencesChanged()
+{
+ if (prefs.profile_dc_ceiling){
+ setVisible(prefs.profile_red_ceiling);
+ }else{
+ setVisible(false);
+ }
+}
+
void DiveReportedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
QGraphicsPolygonItem::paint(painter, option, widget);
diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h
index 9b737db5e..57b1e70e8 100644
--- a/qt-ui/profile/diveprofileitem.h
+++ b/qt-ui/profile/diveprofileitem.h
@@ -38,6 +38,7 @@ public:
void setVerticalDataColumn(int column);
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) = 0;
public slots:
+ virtual void preferencesChanged();
virtual void modelDataChanged();
protected:
DiveCartesianAxis *hAxis;
@@ -54,7 +55,11 @@ class DiveProfileItem : public AbstractProfilePolygonItem{
public:
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
virtual void modelDataChanged();
+ virtual void preferencesChanged();
void plot_depth_sample(struct plot_data *entry,QFlags<Qt::AlignmentFlag> flags,const QColor& color);
+private:
+ unsigned int show_reported_ceiling;
+ unsigned int reported_ceiling_in_red;
};
class DiveTemperatureItem : public AbstractProfilePolygonItem{
@@ -93,5 +98,6 @@ class DiveReportedCeiling : public AbstractProfilePolygonItem{
public:
virtual void modelDataChanged();
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
+ virtual void preferencesChanged();
};
#endif \ No newline at end of file