diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2014-01-21 18:16:19 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-01-21 14:25:34 -0800 |
commit | bd960368922f16bc96d114c684cc381754c58a6a (patch) | |
tree | 7d96acab8b7b70d5b20093bd7237d4297397bb12 /qt-ui/profile/diveprofileitem.cpp | |
parent | b08da94007d7a2e71f932bff67750051c1ad5d65 (diff) | |
download | subsurface-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>
Diffstat (limited to 'qt-ui/profile/diveprofileitem.cpp')
-rw-r--r-- | qt-ui/profile/diveprofileitem.cpp | 35 |
1 files changed, 27 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); |