From 48dda4192f5e82fcaa7a04577a8a0b9aea1a00c8 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 4 Jun 2013 18:51:27 -0300 Subject: [PATCH] Added a new widget 'MinMaxAvgWidget' Added a new widget, MinMaxAvgWidget, a simple widget that displays values in 'min, max, avg' fashion. it has a setMaximum, setAverage and setMinimum methods, that is userful for setting the minimum, maximum and average of stuff. Ah, it also shows the minimum, maximum and average of things. Signed-off-by: Tomaz Canabrava --- Makefile | 2 + icons/average.svg | 66 ++++++++++++ icons/maximum.svg | 66 ++++++++++++ icons/minimum.svg | 66 ++++++++++++ qt-ui/maintab.cpp | 56 ++++------ qt-ui/maintab.ui | 230 +++++----------------------------------- qt-ui/simplewidgets.cpp | 92 ++++++++++++++++ qt-ui/simplewidgets.h | 28 +++++ subsurface.qrc | 3 + 9 files changed, 370 insertions(+), 239 deletions(-) create mode 100644 icons/average.svg create mode 100644 icons/maximum.svg create mode 100644 icons/minimum.svg create mode 100644 qt-ui/simplewidgets.cpp create mode 100644 qt-ui/simplewidgets.h diff --git a/Makefile b/Makefile index 4ada94bc2..e870fa3b9 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ HEADERS = \ qt-ui/kmessagewidget.h \ qt-ui/downloadfromdivecomputer.h \ qt-ui/preferences.h \ + qt-ui/simplewidgets.h \ SOURCES = \ @@ -78,6 +79,7 @@ SOURCES = \ qt-ui/kmessagewidget.cpp \ qt-ui/downloadfromdivecomputer.cpp \ qt-ui/preferences.cpp \ + qt-ui/simplewidgets.cpp \ $(RESFILE) diff --git a/icons/average.svg b/icons/average.svg new file mode 100644 index 000000000..5eb21fae2 --- /dev/null +++ b/icons/average.svg @@ -0,0 +1,66 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/icons/maximum.svg b/icons/maximum.svg new file mode 100644 index 000000000..7c21360d5 --- /dev/null +++ b/icons/maximum.svg @@ -0,0 +1,66 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/icons/minimum.svg b/icons/minimum.svg new file mode 100644 index 000000000..c0fce4b65 --- /dev/null +++ b/icons/minimum.svg @@ -0,0 +1,66 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 55f11789f..07e1d9749 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -137,20 +137,12 @@ void MainTab::clearInfo() void MainTab::clearStats() { - ui->maximumDepthAllText->clear(); - ui->minimumDepthAllText->clear(); - ui->averageDepthAllText->clear(); - ui->maximumSacAllText->clear(); - ui->minimumSacAllText->clear(); - ui->averageSacAllText->clear(); + ui->depthLimits->clear(); + ui->sacLimits->clear(); ui->divesAllText->clear(); - ui->maximumTemperatureAllText->clear(); - ui->minimumTemperatureAllText->clear(); - ui->averageTemperatureAllText->clear(); + ui->tempLimits->clear(); ui->totalTimeAllText->clear(); - ui->averageTimeAllText->clear(); - ui->longestAllText->clear(); - ui->shortestAllText->clear(); + ui->timeLimits->clear(); } #define UPDATE_TEXT(d, field) \ @@ -217,29 +209,29 @@ void MainTab::updateDiveInfo(int dive) else ui->airPressureText->clear(); ui->visibility->setCurrentStars(d->visibility); - ui->maximumDepthAllText->setText(get_depth_string(stats_selection.max_depth, TRUE)); - ui->minimumDepthAllText->setText(get_depth_string(stats_selection.min_depth, TRUE)); - ui->averageDepthAllText->setText(get_depth_string(stats_selection.avg_depth, TRUE)); - ui->maximumSacAllText->setText(get_volume_string(stats_selection.max_sac, TRUE).append(tr("/min"))); - ui->minimumSacAllText->setText(get_volume_string(stats_selection.min_sac, TRUE).append(tr("/min"))); - ui->averageSacAllText->setText(get_volume_string(stats_selection.avg_sac, TRUE).append(tr("/min"))); + ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, TRUE)); + ui->depthLimits->setMinimum(get_depth_string(stats_selection.min_depth, TRUE)); + ui->depthLimits->setAverage(get_depth_string(stats_selection.avg_depth, TRUE)); + ui->sacLimits->setMaximum(get_volume_string(stats_selection.max_sac, TRUE).append(tr("/min"))); + ui->sacLimits->setMinimum(get_volume_string(stats_selection.min_sac, TRUE).append(tr("/min"))); + ui->sacLimits->setAverage(get_volume_string(stats_selection.avg_sac, TRUE).append(tr("/min"))); ui->divesAllText->setText(QString::number(stats_selection.selection_size)); temp.mkelvin = stats_selection.max_temp; - ui->maximumTemperatureAllText->setText(get_temperature_string(temp, TRUE)); + ui->tempLimits->setMaximum(get_temperature_string(temp, TRUE)); temp.mkelvin = stats_selection.min_temp; - ui->minimumTemperatureAllText->setText(get_temperature_string(temp, TRUE)); + ui->tempLimits->setMinimum(get_temperature_string(temp, TRUE)); if (stats_selection.combined_temp && stats_selection.combined_count) { const char *unit; get_temp_units(0, &unit); - ui->averageTemperatureAllText->setText(QString("%1%2").arg(stats_selection.combined_temp / stats_selection.combined_count, 0, 'f', 1).arg(unit)); + ui->tempLimits->setAverage(QString("%1%2").arg(stats_selection.combined_temp / stats_selection.combined_count, 0, 'f', 1).arg(unit)); } ui->totalTimeAllText->setText(get_time_string(stats_selection.total_time.seconds, 0)); int seconds = stats_selection.total_time.seconds; if (stats_selection.selection_size) seconds /= stats_selection.selection_size; - ui->averageTimeAllText->setText(get_time_string(seconds, 0)); - ui->longestAllText->setText(get_time_string(stats_selection.longest_time.seconds, 0)); - ui->shortestAllText->setText(get_time_string(stats_selection.shortest_time.seconds, 0)); + ui->timeLimits->setAverage(get_time_string(seconds, 0)); + ui->timeLimits->setMaximum(get_time_string(stats_selection.longest_time.seconds, 0)); + ui->timeLimits->setMinimum(get_time_string(stats_selection.shortest_time.seconds, 0)); cylindersModel->setDive(d); weightModel->setDive(d); addCylinder->setEnabled(true); @@ -272,20 +264,12 @@ void MainTab::updateDiveInfo(int dive) weightModel->clear(); addCylinder->setEnabled(false); addWeight->setEnabled(false); - ui->maximumDepthAllText->clear(); - ui->minimumDepthAllText->clear(); - ui->averageDepthAllText->clear(); - ui->maximumSacAllText->clear(); - ui->minimumSacAllText->clear(); - ui->averageSacAllText->clear(); + ui->depthLimits->clear(); + ui->sacLimits->clear(); ui->divesAllText->clear(); - ui->maximumTemperatureAllText->clear(); - ui->minimumTemperatureAllText->clear(); - ui->averageTemperatureAllText->clear(); + ui->tempLimits->clear(); ui->totalTimeAllText->clear(); - ui->averageTimeAllText->clear(); - ui->longestAllText->clear(); - ui->shortestAllText->clear(); + ui->timeLimits->clear(); } /* statisticsTab*/ /* we can access the stats_selection struct, but how do we ensure the relevant dives are selected diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 854e67940..55d4f3a54 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -14,7 +14,7 @@ TabWidget - 2 + 3 true @@ -453,40 +453,26 @@ Stats - - + + - Max. Temp. + SAC - + - - - TextLabel - - - Qt::AlignCenter - - + - + - Min Depth + Temperature - + - - - TextLabel - - - Qt::AlignCenter - - + @@ -494,196 +480,28 @@ - Max. Depth + Depth - - - TextLabel - - - Qt::AlignCenter - - - - - maximumDepthAllText - minimumDepthAllText - - - - - - Ave. Temp. - - - - - - TextLabel - - - Qt::AlignCenter - - + - - - - Ave. Time - - - - - - TextLabel - - - Qt::AlignCenter - - - - - - - - - - Min. Temp. - - - - - - TextLabel - - - Qt::AlignCenter - - - - - - - - - - Ave. Depth - - - - - - TextLabel - - - Qt::AlignCenter - - - - - - - - - - Max. SAC - - - - - - TextLabel - - - Qt::AlignCenter - - - - - - - - - - Min. SAC - - - - - - TextLabel - - - Qt::AlignCenter - - - - - - - - - - Ave. SAC - - - - - - TextLabel - - - Qt::AlignCenter - - - - - - - - - - Dives - - - - - - TextLabel - - - Qt::AlignCenter - - - - - - - + - Longest + Duration - - - TextLabel - - - Qt::AlignCenter - - + - + Total Time @@ -702,14 +520,14 @@ - - + + - Shortest + Dives - + - + TextLabel @@ -737,6 +555,12 @@
starwidget.h
1 + + MinMaxAvgWidget + QWidget +
simplewidgets.h
+ 1 +
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp new file mode 100644 index 000000000..c389a34c3 --- /dev/null +++ b/qt-ui/simplewidgets.cpp @@ -0,0 +1,92 @@ +#include "simplewidgets.h" + +#include +#include +#include +#include + +class MinMaxAvgWidgetPrivate{ +public: + QLabel *avgIco, *avgValue; + QLabel *minIco, *minValue; + QLabel *maxIco, *maxValue; + + MinMaxAvgWidgetPrivate(MinMaxAvgWidget *owner){ + avgIco = new QLabel(owner); + avgIco->setPixmap(QIcon(":/average").pixmap(16,16)); + avgIco->setToolTip(QObject::tr("Average")); + minIco = new QLabel(owner); + minIco->setPixmap(QIcon(":/minimum").pixmap(16,16)); + minIco->setToolTip(QObject::tr("Minimum")); + maxIco = new QLabel(owner); + maxIco->setPixmap(QIcon(":/maximum").pixmap(16,16)); + maxIco->setToolTip(QObject::tr("Maximum")); + avgValue = new QLabel(owner); + minValue = new QLabel(owner); + maxValue = new QLabel(owner); + + QGridLayout *formLayout = new QGridLayout(); + formLayout->addWidget(maxIco, 0, 0); + formLayout->addWidget(maxValue, 0, 1); + formLayout->addWidget(avgIco, 1, 0); + formLayout->addWidget(avgValue, 1, 1); + formLayout->addWidget(minIco, 2, 0); + formLayout->addWidget(minValue, 2, 1); + owner->setLayout(formLayout); + } +}; + +double MinMaxAvgWidget::average() const +{ + return d->avgValue->text().toDouble(); +} + +double MinMaxAvgWidget::maximum() const +{ + return d->maxValue->text().toDouble(); +} +double MinMaxAvgWidget::minimum() const +{ + return d->minValue->text().toDouble(); +} + +MinMaxAvgWidget::MinMaxAvgWidget(QWidget* parent) +: d(new MinMaxAvgWidgetPrivate(this)){ + +} + +void MinMaxAvgWidget::clear() +{ + d->avgValue->setText(QString()); + d->maxValue->setText(QString()); + d->minValue->setText(QString()); +} + +void MinMaxAvgWidget::setAverage(double average) +{ + d->avgValue->setText(QString::number(average)); +} + +void MinMaxAvgWidget::setMaximum(double maximum) +{ + d->maxValue->setText(QString::number(maximum)); +} +void MinMaxAvgWidget::setMinimum(double minimum) +{ + d->minValue->setText(QString::number(minimum)); +} + +void MinMaxAvgWidget::setAverage(const QString& average) +{ + d->avgValue->setText(average); +} + +void MinMaxAvgWidget::setMaximum(const QString& maximum) +{ + d->maxValue->setText(maximum); +} + +void MinMaxAvgWidget::setMinimum(const QString& minimum) +{ + d->minValue->setText(minimum); +} diff --git a/qt-ui/simplewidgets.h b/qt-ui/simplewidgets.h new file mode 100644 index 000000000..b05dd8f0e --- /dev/null +++ b/qt-ui/simplewidgets.h @@ -0,0 +1,28 @@ +#ifndef SIMPLEWIDGETS_H +#define SIMPLEWIDGETS_H + +class MinMaxAvgWidgetPrivate; +#include + +class MinMaxAvgWidget : public QWidget{ + Q_OBJECT + Q_PROPERTY(double minimum READ minimum WRITE setMinimum) + Q_PROPERTY(double maximum READ maximum WRITE setMaximum) + Q_PROPERTY(double average READ average WRITE setAverage) +public: + MinMaxAvgWidget(QWidget *parent); + double minimum() const; + double maximum() const; + double average() const; + void setMinimum(double minimum); + void setMaximum(double maximum); + void setAverage(double average); + void setMinimum(const QString& minimum); + void setMaximum(const QString& maximum); + void setAverage(const QString& average); + void clear(); +private: + MinMaxAvgWidgetPrivate *d; +}; + +#endif \ No newline at end of file diff --git a/subsurface.qrc b/subsurface.qrc index fa514cb94..e94505cea 100644 --- a/subsurface.qrc +++ b/subsurface.qrc @@ -7,5 +7,8 @@ icons/units.png icons/advanced.png icons/graph.png + icons/minimum.svg + icons/maximum.svg + icons/average.svg