Draw the Ceiling in red if preferences are marked for that.

This code actually uses the preferences for something. It will show and
hide the calculated ceiling in red if the prefrerences are changed for
that. One bad thing that I did in this commit ( so it was easy to try ) is
that a preference change will redraw the whole graph - not optimized. I'll
make this better in a later commit so that only the affected items will be
redrawn.

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 17:34:36 -02:00 committed by Dirk Hohndel
parent 8831bf6350
commit b08da94007
4 changed files with 63 additions and 1 deletions

View file

@ -364,3 +364,42 @@ void DiveCalculatedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsI
{ {
QGraphicsPolygonItem::paint(painter, option, widget); QGraphicsPolygonItem::paint(painter, option, widget);
} }
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();
for (int i = 0, count = dataModel->rowCount(); i < count; i++, entry++) {
if (entry->in_deco && entry->stopdepth) {
if (entry->stopdepth < entry->depth) {
p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->stopdepth)));
} else {
p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->depth)));
}
} else {
p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0)));
}
}
setPolygon(p);
QLinearGradient pat(0, p.boundingRect().top(), 0, p.boundingRect().bottom());
pat.setColorAt(0, getColor(CEILING_SHALLOW));
pat.setColorAt(1, getColor(CEILING_DEEP));
setPen(QPen(QBrush(Qt::NoBrush),0));
setBrush(pat);
}
void DiveReportedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
QGraphicsPolygonItem::paint(painter, option, widget);
}

View file

@ -87,4 +87,11 @@ public:
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
}; };
class DiveReportedCeiling : public AbstractProfilePolygonItem{
Q_OBJECT
public:
virtual void modelDataChanged();
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
};
#endif #endif

View file

@ -39,7 +39,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
cartesianPlane(new DiveCartesianPlane()), cartesianPlane(new DiveCartesianPlane()),
meanDepth(new DiveLineItem()), meanDepth(new DiveLineItem()),
diveComputerText(new DiveTextItem()), diveComputerText(new DiveTextItem()),
diveCeiling(NULL) diveCeiling(NULL),
reportedCeiling(NULL)
{ {
setScene(new QGraphicsScene()); setScene(new QGraphicsScene());
scene()->setSceneRect(0, 0, 100, 100); scene()->setSceneRect(0, 0, 100, 100);
@ -386,6 +387,18 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
allTissues.append(tissueItem); allTissues.append(tissueItem);
scene()->addItem(tissueItem); scene()->addItem(tissueItem);
} }
if(reportedCeiling){
scene()->removeItem(reportedCeiling);
delete reportedCeiling;
}
reportedCeiling = new DiveReportedCeiling();
reportedCeiling->setHorizontalAxis(timeAxis);
reportedCeiling->setVerticalAxis(profileYAxis);
reportedCeiling->setModel(dataModel);
reportedCeiling->setVerticalDataColumn(DivePlotDataModel::CEILING);
reportedCeiling->setHorizontalDataColumn(DivePlotDataModel::TIME);
scene()->addItem(reportedCeiling);
emit startProfileState(); emit startProfileState();
} }

View file

@ -16,6 +16,7 @@
#include "graphicsview-common.h" #include "graphicsview-common.h"
#include "divelineitem.h" #include "divelineitem.h"
class DiveReportedCeiling;
class DiveTextItem; class DiveTextItem;
class TemperatureAxis; class TemperatureAxis;
class DiveEventItem; class DiveEventItem;
@ -33,6 +34,7 @@ struct DiveTemperatureItem;
struct plot_info; struct plot_info;
struct DiveGasPressureItem; struct DiveGasPressureItem;
struct DiveCalculatedCeiling; struct DiveCalculatedCeiling;
struct DiveReportedCeiling;
class ProfileWidget2 : public QGraphicsView { class ProfileWidget2 : public QGraphicsView {
Q_OBJECT Q_OBJECT
@ -86,6 +88,7 @@ private:
DiveTextItem *diveComputerText; DiveTextItem *diveComputerText;
DiveCalculatedCeiling *diveCeiling; DiveCalculatedCeiling *diveCeiling;
QList<DiveCalculatedCeiling*> allTissues; QList<DiveCalculatedCeiling*> allTissues;
DiveReportedCeiling *reportedCeiling;
}; };
#endif #endif