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>
This commit is contained in:
Tomaz Canabrava 2014-01-21 18:16:19 -02:00 committed by Dirk Hohndel
parent b08da94007
commit bd96036892
2 changed files with 33 additions and 8 deletions

View file

@ -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);

View file

@ -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