mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Cleanup: move common code into TankItem::createBar() function
Calculation of the x-position and the width of the tank-bar was done outside of the function. Move it into the function to make the caller a bit more readable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
6d78e63d19
commit
bc11097ded
2 changed files with 7 additions and 10 deletions
|
@ -46,8 +46,11 @@ void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, str
|
||||||
modelDataChanged();
|
modelDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TankItem::createBar(qreal x, qreal w, struct gasmix gas)
|
void TankItem::createBar(int startTime, int stopTime, struct gasmix gas)
|
||||||
{
|
{
|
||||||
|
qreal x = hAxis->posAtValue(startTime);
|
||||||
|
qreal w = hAxis->posAtValue(stopTime) - hAxis->posAtValue(startTime);
|
||||||
|
|
||||||
// pick the right gradient, size, position and text
|
// pick the right gradient, size, position and text
|
||||||
QGraphicsRectItem *rect = new QGraphicsRectItem(x, 0, w, height, this);
|
QGraphicsRectItem *rect = new QGraphicsRectItem(x, 0, w, height, this);
|
||||||
if (gasmix_is_air(gas))
|
if (gasmix_is_air(gas))
|
||||||
|
@ -81,8 +84,6 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&)
|
||||||
qDeleteAll(rects);
|
qDeleteAll(rects);
|
||||||
rects.clear();
|
rects.clear();
|
||||||
|
|
||||||
qreal width, left;
|
|
||||||
|
|
||||||
// Find correct end of the dive plot for correct end of the tankbar
|
// Find correct end of the dive plot for correct end of the tankbar
|
||||||
struct plot_data *last_entry = &pInfoEntry[pInfoNr-1];
|
struct plot_data *last_entry = &pInfoEntry[pInfoNr-1];
|
||||||
|
|
||||||
|
@ -97,16 +98,12 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&)
|
||||||
// work through all the gas changes and add the rectangle for each gas while it was used
|
// work through all the gas changes and add the rectangle for each gas while it was used
|
||||||
const struct event *ev = get_next_event(dc->events, "gaschange");
|
const struct event *ev = get_next_event(dc->events, "gaschange");
|
||||||
while (ev && (int)ev->time.seconds < last_entry->sec) {
|
while (ev && (int)ev->time.seconds < last_entry->sec) {
|
||||||
width = hAxis->posAtValue(ev->time.seconds) - hAxis->posAtValue(startTime);
|
createBar(startTime, ev->time.seconds, gasmix);
|
||||||
left = hAxis->posAtValue(startTime);
|
|
||||||
createBar(left, width, gasmix);
|
|
||||||
startTime = ev->time.seconds;
|
startTime = ev->time.seconds;
|
||||||
gasmix = get_gasmix_from_event(&displayed_dive, ev);
|
gasmix = get_gasmix_from_event(&displayed_dive, ev);
|
||||||
ev = get_next_event(ev->next, "gaschange");
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
}
|
}
|
||||||
width = hAxis->posAtValue(last_entry->sec) - hAxis->posAtValue(startTime);
|
createBar(startTime, last_entry->sec, gasmix);
|
||||||
left = hAxis->posAtValue(startTime);
|
|
||||||
createBar(left, width, gasmix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal)
|
void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal)
|
||||||
|
|
|
@ -24,7 +24,7 @@ public slots:
|
||||||
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createBar(qreal x, qreal w, struct gasmix gas);
|
void createBar(int startTime, int stopTime, struct gasmix gas);
|
||||||
DiveCartesianAxis *hAxis;
|
DiveCartesianAxis *hAxis;
|
||||||
struct plot_data *pInfoEntry;
|
struct plot_data *pInfoEntry;
|
||||||
int pInfoNr;
|
int pInfoNr;
|
||||||
|
|
Loading…
Add table
Reference in a new issue