mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-20 06:45:27 +00:00
Started the code for a grid that knows how to handle itself.
The code for this item is a bit too big to be just the grid of the dives and I know that, don't bully me. :) The main idea of this grid is that it knows when it should be updated. this is a bit different than the old code where all the painting happened on the same method. This is bad because it's more code, but it's better because if I break the grid, only the grid will be broken, and it's easyer to spot the breakage. in the old code if I did the wrong thing with the graphics context, the whole graph gots messed out. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
793879b6fa
commit
9cb5ea45d8
4 changed files with 119 additions and 2 deletions
|
@ -13,11 +13,13 @@
|
||||||
void DiveCartesianAxis::setMaximum(double maximum)
|
void DiveCartesianAxis::setMaximum(double maximum)
|
||||||
{
|
{
|
||||||
max = maximum;
|
max = maximum;
|
||||||
|
emit sizeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveCartesianAxis::setMinimum(double minimum)
|
void DiveCartesianAxis::setMinimum(double minimum)
|
||||||
{
|
{
|
||||||
min = minimum;
|
min = minimum;
|
||||||
|
emit sizeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveCartesianAxis::setTextColor(const QColor& color)
|
void DiveCartesianAxis::setTextColor(const QColor& color)
|
||||||
|
@ -189,3 +191,84 @@ QString TimeAxis::textForValue(double value)
|
||||||
{
|
{
|
||||||
return QString::number(value / 60);
|
return QString::number(value / 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiveCartesianPlane::setLeftAxis(DiveCartesianAxis* axis)
|
||||||
|
{
|
||||||
|
leftAxis = axis;
|
||||||
|
connect(leftAxis, SIGNAL(sizeChanged()), this, SLOT(setup()));
|
||||||
|
if (bottomAxis)
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveCartesianPlane::setBottomAxis(DiveCartesianAxis* axis)
|
||||||
|
{
|
||||||
|
bottomAxis = axis;
|
||||||
|
connect(bottomAxis, SIGNAL(sizeChanged()), this, SLOT(setup()));
|
||||||
|
if (leftAxis)
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
QLineF DiveCartesianPlane::horizontalLine() const
|
||||||
|
{
|
||||||
|
return (bottomAxis) ? bottomAxis->line() : QLineF() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveCartesianPlane::setHorizontalLine(QLineF line)
|
||||||
|
{
|
||||||
|
if ( horizontalSize == line.length())
|
||||||
|
return;
|
||||||
|
horizontalSize = line.length();
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveCartesianPlane::setVerticalLine(QLineF line)
|
||||||
|
{
|
||||||
|
if (verticalSize == line.length())
|
||||||
|
return;
|
||||||
|
verticalSize = line.length();
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
QLineF DiveCartesianPlane::verticalLine() const
|
||||||
|
{
|
||||||
|
return (leftAxis) ? leftAxis->line() : QLineF() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveCartesianPlane::setup()
|
||||||
|
{
|
||||||
|
if (!leftAxis || !bottomAxis || !scene())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// This creates a Grid around the axis, creating the cartesian plane.
|
||||||
|
const int top = leftAxis->posAtValue(leftAxis->minimum());
|
||||||
|
const int bottom = leftAxis->posAtValue(leftAxis->maximum());
|
||||||
|
const int left = bottomAxis->posAtValue(bottomAxis->minimum());
|
||||||
|
const int right = bottomAxis->posAtValue(bottomAxis->maximum());
|
||||||
|
|
||||||
|
setRect(0, 0, horizontalSize, verticalSize);
|
||||||
|
setPos(left, top);
|
||||||
|
|
||||||
|
qDeleteAll(horizontalLines);
|
||||||
|
qDeleteAll(verticalLines);
|
||||||
|
horizontalLines.clear();
|
||||||
|
verticalLines.clear();
|
||||||
|
|
||||||
|
// DEPTH is M_OR_FEET(10,30), Minutes are 600, per line.
|
||||||
|
for (int i = leftAxis->minimum(), max = leftAxis->maximum(); i < max; i += M_OR_FT(10,30)) {
|
||||||
|
DiveLineItem *line = new DiveLineItem();
|
||||||
|
line->setLine(0, 0, horizontalSize, 0);
|
||||||
|
line->setPos(left,leftAxis->posAtValue(i));
|
||||||
|
line->setZValue(-1);
|
||||||
|
horizontalLines.push_back(line);
|
||||||
|
scene()->addItem(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = bottomAxis->minimum(), max = bottomAxis->maximum(); i < max; i += 600) { // increments by 10 minutes.
|
||||||
|
DiveLineItem *line = new DiveLineItem();
|
||||||
|
line->setLine(0, 0, 0, verticalSize);
|
||||||
|
line->setPos(bottomAxis->posAtValue(i), top);
|
||||||
|
line->setZValue(-1);
|
||||||
|
verticalLines.push_back(line);
|
||||||
|
scene()->addItem(line);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,8 @@ public:
|
||||||
void setColor(const QColor& color);
|
void setColor(const QColor& color);
|
||||||
void setTextColor(const QColor& color);
|
void setTextColor(const QColor& color);
|
||||||
int unitSystem;
|
int unitSystem;
|
||||||
|
signals:
|
||||||
|
void sizeChanged();
|
||||||
protected:
|
protected:
|
||||||
virtual QString textForValue(double value);
|
virtual QString textForValue(double value);
|
||||||
|
|
||||||
|
@ -52,4 +53,28 @@ class TimeAxis : public DiveCartesianAxis {
|
||||||
protected:
|
protected:
|
||||||
QString textForValue(double value);
|
QString textForValue(double value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is a try. Maybe the CartesianPlane should have the X and Y
|
||||||
|
// axis and handle things internally?
|
||||||
|
class DiveCartesianPlane :public QObject, public QGraphicsRectItem{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QLineF verticalLine READ verticalLine WRITE setVerticalLine)
|
||||||
|
Q_PROPERTY(QLineF horizontalLine READ horizontalLine WRITE setHorizontalLine)
|
||||||
|
public:
|
||||||
|
void setLeftAxis(DiveCartesianAxis *axis);
|
||||||
|
void setBottomAxis(DiveCartesianAxis *axis);
|
||||||
|
void setHorizontalLine(QLineF line);
|
||||||
|
void setVerticalLine(QLineF line);
|
||||||
|
QLineF horizontalLine() const;
|
||||||
|
QLineF verticalLine() const;
|
||||||
|
public slots:
|
||||||
|
void setup();
|
||||||
|
private:
|
||||||
|
DiveCartesianAxis *leftAxis;
|
||||||
|
DiveCartesianAxis *bottomAxis;
|
||||||
|
QList<DiveLineItem*> verticalLines;
|
||||||
|
QList<DiveLineItem*> horizontalLines;
|
||||||
|
qreal verticalSize;
|
||||||
|
qreal horizontalSize;
|
||||||
|
};
|
||||||
#endif
|
#endif
|
|
@ -29,7 +29,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
||||||
timeAxis(new TimeAxis()),
|
timeAxis(new TimeAxis()),
|
||||||
depthController(new DiveRectItem()),
|
depthController(new DiveRectItem()),
|
||||||
timeController(new DiveRectItem()),
|
timeController(new DiveRectItem()),
|
||||||
diveProfileItem(new DiveProfileItem())
|
diveProfileItem(new DiveProfileItem()),
|
||||||
|
cartesianPlane(new DiveCartesianPlane())
|
||||||
{
|
{
|
||||||
setScene(new QGraphicsScene());
|
setScene(new QGraphicsScene());
|
||||||
scene()->setSceneRect(0, 0, 100, 100);
|
scene()->setSceneRect(0, 0, 100, 100);
|
||||||
|
@ -64,6 +65,10 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
||||||
timeController->setRect(0, 0, 10, 5);
|
timeController->setRect(0, 0, 10, 5);
|
||||||
timeController->setX(sceneRect().width() - timeController->boundingRect().width()); // Position it on the right spot.
|
timeController->setX(sceneRect().width() - timeController->boundingRect().width()); // Position it on the right spot.
|
||||||
|
|
||||||
|
cartesianPlane->setBottomAxis(timeAxis);
|
||||||
|
cartesianPlane->setLeftAxis(profileYAxis);
|
||||||
|
scene()->addItem(cartesianPlane);
|
||||||
|
|
||||||
// insert in the same way it's declared on the Enum. This is needed so we don't use an map.
|
// insert in the same way it's declared on the Enum. This is needed so we don't use an map.
|
||||||
QList<QGraphicsItem*> stateItems; stateItems << background << profileYAxis << gasYAxis <<
|
QList<QGraphicsItem*> stateItems; stateItems << background << profileYAxis << gasYAxis <<
|
||||||
timeAxis << depthController << timeController;
|
timeAxis << depthController << timeController;
|
||||||
|
@ -156,6 +161,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
||||||
profileState->assignProperty(timeAxis, "y", timeAxisOnCanvas);
|
profileState->assignProperty(timeAxis, "y", timeAxisOnCanvas);
|
||||||
profileState->assignProperty(depthController, "y", depthControllerOffCanvas);
|
profileState->assignProperty(depthController, "y", depthControllerOffCanvas);
|
||||||
profileState->assignProperty(timeController, "y", timeControllerOffCanvas);
|
profileState->assignProperty(timeController, "y", timeControllerOffCanvas);
|
||||||
|
profileState->assignProperty(cartesianPlane, "verticalLine", profileYAxisExpanded);
|
||||||
|
profileState->assignProperty(cartesianPlane, "horizontalLine", timeAxis->line());
|
||||||
|
|
||||||
// Edit, everything but the background and gasYAxis are shown.
|
// Edit, everything but the background and gasYAxis are shown.
|
||||||
editState->assignProperty(this, "backgroundBrush", QBrush(Qt::darkGray));
|
editState->assignProperty(this, "backgroundBrush", QBrush(Qt::darkGray));
|
||||||
|
|
|
@ -23,6 +23,7 @@ struct DiveProfileItem;
|
||||||
struct TimeAxis;
|
struct TimeAxis;
|
||||||
struct dive;
|
struct dive;
|
||||||
struct QStateMachine;
|
struct QStateMachine;
|
||||||
|
struct DiveCartesianPlane;
|
||||||
|
|
||||||
class ProfileWidget2 : public QGraphicsView {
|
class ProfileWidget2 : public QGraphicsView {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -62,6 +63,7 @@ private:
|
||||||
DiveRectItem *depthController;
|
DiveRectItem *depthController;
|
||||||
DiveRectItem *timeController;
|
DiveRectItem *timeController;
|
||||||
DiveProfileItem *diveProfileItem;
|
DiveProfileItem *diveProfileItem;
|
||||||
|
DiveCartesianPlane *cartesianPlane;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Add table
Reference in a new issue