From 0c5fd7db8eac11d74d27098b6f38d22e174f5439 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 15 Feb 2014 21:55:31 -0200 Subject: New template-based-function: remove the uneeded items on a QList. This function is for non-duplication of code for different QLists, since I now have Texts and Lines, I needed to make the code in a way that it worked without dupplication. It's a pretty standard use of templates, I think that even the C guys will not be offended by it. :) Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/divecartesianaxis.cpp | 26 +++++++++++++++++++------- qt-ui/profile/divecartesianaxis.h | 3 +++ 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'qt-ui/profile') diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp index dbcd82306..c272ffe70 100644 --- a/qt-ui/profile/divecartesianaxis.cpp +++ b/qt-ui/profile/divecartesianaxis.cpp @@ -64,7 +64,8 @@ DiveCartesianAxis::DiveCartesianAxis() : QObject(), interval(1), labelScale(1.0), tick_size(0), - textVisibility(true) + textVisibility(true), + line_size(-1) { setPen(gridPen()); } @@ -74,6 +75,11 @@ DiveCartesianAxis::~DiveCartesianAxis() } +void DiveCartesianAxis::setLineSize(qreal lineSize) +{ + line_size = lineSize; +} + void DiveCartesianAxis::setOrientation(Orientation o) { orientation = o; @@ -95,6 +101,15 @@ void DiveCartesianAxis::setTextVisible(bool arg1) } } +template void emptyList( QList& list, double steps){ + if (!list.isEmpty() && list.size() > steps) { + while (list.size() > steps) { + T *removedItem = list.takeLast(); + Animations::animDelete(removedItem); + } + } +} + void DiveCartesianAxis::updateTicks() { if (!scene()) @@ -108,12 +123,9 @@ void DiveCartesianAxis::updateTicks() if (steps < 1) return; - if (!labels.isEmpty() && labels.size() > steps) { - while (labels.size() > steps) { - DiveTextItem *removedText = labels.takeLast(); - Animations::animDelete(removedText); - } - } + emptyList(labels, steps); + emptyList(lines, steps); + // Move the remaining Ticks / Text to it's corerct position // Regartind the possibly new values for the Axis qreal begin, stepSize; diff --git a/qt-ui/profile/divecartesianaxis.h b/qt-ui/profile/divecartesianaxis.h index 58468f209..7db47ae9d 100644 --- a/qt-ui/profile/divecartesianaxis.h +++ b/qt-ui/profile/divecartesianaxis.h @@ -37,6 +37,7 @@ public: void setTextColor(const QColor& color); void animateChangeLine(const QLineF& newLine); void setTextVisible(bool arg1); + void setLineSize(qreal lineSize); int unitSystem; public slots: virtual void updateTicks(); @@ -49,6 +50,7 @@ protected: virtual QColor colorForValue(double value); Orientation orientation; QList labels; + QList lines; double min; double max; double interval; @@ -56,6 +58,7 @@ protected: QColor textColor; bool textVisibility; double labelScale; + qreal line_size; }; class DepthAxis : public DiveCartesianAxis { -- cgit v1.2.3-70-g09d2