mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
fc55b2abfe
commit
0c5fd7db8e
2 changed files with 22 additions and 7 deletions
|
@ -64,7 +64,8 @@ DiveCartesianAxis::DiveCartesianAxis() : QObject(),
|
||||||
interval(1),
|
interval(1),
|
||||||
labelScale(1.0),
|
labelScale(1.0),
|
||||||
tick_size(0),
|
tick_size(0),
|
||||||
textVisibility(true)
|
textVisibility(true),
|
||||||
|
line_size(-1)
|
||||||
{
|
{
|
||||||
setPen(gridPen());
|
setPen(gridPen());
|
||||||
}
|
}
|
||||||
|
@ -74,6 +75,11 @@ DiveCartesianAxis::~DiveCartesianAxis()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiveCartesianAxis::setLineSize(qreal lineSize)
|
||||||
|
{
|
||||||
|
line_size = lineSize;
|
||||||
|
}
|
||||||
|
|
||||||
void DiveCartesianAxis::setOrientation(Orientation o)
|
void DiveCartesianAxis::setOrientation(Orientation o)
|
||||||
{
|
{
|
||||||
orientation = o;
|
orientation = o;
|
||||||
|
@ -95,6 +101,15 @@ void DiveCartesianAxis::setTextVisible(bool arg1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T> void emptyList( QList<T*>& list, double steps){
|
||||||
|
if (!list.isEmpty() && list.size() > steps) {
|
||||||
|
while (list.size() > steps) {
|
||||||
|
T *removedItem = list.takeLast();
|
||||||
|
Animations::animDelete(removedItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DiveCartesianAxis::updateTicks()
|
void DiveCartesianAxis::updateTicks()
|
||||||
{
|
{
|
||||||
if (!scene())
|
if (!scene())
|
||||||
|
@ -108,12 +123,9 @@ void DiveCartesianAxis::updateTicks()
|
||||||
if (steps < 1)
|
if (steps < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!labels.isEmpty() && labels.size() > steps) {
|
emptyList(labels, steps);
|
||||||
while (labels.size() > steps) {
|
emptyList(lines, steps);
|
||||||
DiveTextItem *removedText = labels.takeLast();
|
|
||||||
Animations::animDelete(removedText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Move the remaining Ticks / Text to it's corerct position
|
// Move the remaining Ticks / Text to it's corerct position
|
||||||
// Regartind the possibly new values for the Axis
|
// Regartind the possibly new values for the Axis
|
||||||
qreal begin, stepSize;
|
qreal begin, stepSize;
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
void setTextColor(const QColor& color);
|
void setTextColor(const QColor& color);
|
||||||
void animateChangeLine(const QLineF& newLine);
|
void animateChangeLine(const QLineF& newLine);
|
||||||
void setTextVisible(bool arg1);
|
void setTextVisible(bool arg1);
|
||||||
|
void setLineSize(qreal lineSize);
|
||||||
int unitSystem;
|
int unitSystem;
|
||||||
public slots:
|
public slots:
|
||||||
virtual void updateTicks();
|
virtual void updateTicks();
|
||||||
|
@ -49,6 +50,7 @@ protected:
|
||||||
virtual QColor colorForValue(double value);
|
virtual QColor colorForValue(double value);
|
||||||
Orientation orientation;
|
Orientation orientation;
|
||||||
QList<DiveTextItem*> labels;
|
QList<DiveTextItem*> labels;
|
||||||
|
QList<DiveLineItem*> lines;
|
||||||
double min;
|
double min;
|
||||||
double max;
|
double max;
|
||||||
double interval;
|
double interval;
|
||||||
|
@ -56,6 +58,7 @@ protected:
|
||||||
QColor textColor;
|
QColor textColor;
|
||||||
bool textVisibility;
|
bool textVisibility;
|
||||||
double labelScale;
|
double labelScale;
|
||||||
|
qreal line_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DepthAxis : public DiveCartesianAxis {
|
class DepthAxis : public DiveCartesianAxis {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue