From 051d56a9609ac1ba28f4a268f0f4edffabd29592 Mon Sep 17 00:00:00 2001 From: Michael Carpenter Date: Tue, 28 May 2013 13:59:33 -0400 Subject: [PATCH] Abstraction of UASQuickViewItem, and addition of new Text item to use the abstraction --- qgroundcontrol.pro | 6 +++-- src/ui/uas/UASQuickView.cc | 5 ++-- src/ui/uas/UASQuickViewItem.cc | 19 --------------- src/ui/uas/UASQuickViewItem.h | 11 ++------- ...emSelect.cpp => UASQuickViewItemSelect.cc} | 0 src/ui/uas/UASQuickViewTextItem.cc | 24 +++++++++++++++++++ src/ui/uas/UASQuickViewTextItem.h | 17 +++++++++++++ 7 files changed, 50 insertions(+), 32 deletions(-) rename src/ui/uas/{UASQuickViewItemSelect.cpp => UASQuickViewItemSelect.cc} (100%) create mode 100644 src/ui/uas/UASQuickViewTextItem.cc create mode 100644 src/ui/uas/UASQuickViewTextItem.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index d45b69cac..583264d96 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -378,7 +378,8 @@ HEADERS += src/MG.h \ src/ui/dockwidgettitlebareventfilter.h \ src/ui/uas/UASQuickView.h \ src/ui/uas/UASQuickViewItem.h \ - src/ui/uas/UASQuickViewItemSelect.h + src/ui/uas/UASQuickViewItemSelect.h \ + src/ui/uas/UASQuickViewTextItem.h # Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::HEADERS += src/ui/map3D/QGCGoogleEarthView.h @@ -547,7 +548,8 @@ SOURCES += src/main.cc \ src/ui/dockwidgettitlebareventfilter.cpp \ src/ui/uas/UASQuickViewItem.cc \ src/ui/uas/UASQuickView.cc \ - src/ui/uas/UASQuickViewItemSelect.cpp + src/ui/uas/UASQuickViewTextItem.cc \ + src/ui/uas/UASQuickViewItemSelect.cc # Enable Google Earth only on Mac OS and Windows with Visual Studio compiler macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc diff --git a/src/ui/uas/UASQuickView.cc b/src/ui/uas/UASQuickView.cc index 63bd952ab..aea0a83f7 100644 --- a/src/ui/uas/UASQuickView.cc +++ b/src/ui/uas/UASQuickView.cc @@ -2,6 +2,7 @@ #include #include #include "UASQuickViewItemSelect.h" +#include "UASQuickViewTextItem.h" #include UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent) { @@ -146,7 +147,7 @@ void UASQuickView::loadSettings() void UASQuickView::valueEnabled(QString value) { - UASQuickViewItem *item = new UASQuickViewItem(this); + UASQuickViewItem *item = new UASQuickViewTextItem(this); item->setTitle(value); ui.verticalLayout->addWidget(item); uasPropertyToLabelMap[value] = item; @@ -359,7 +360,7 @@ void UASQuickView::actionTriggered(bool checked) } if (checked) { - UASQuickViewItem *item = new UASQuickViewItem(this); + UASQuickViewItem *item = new UASQuickViewTextItem(this); item->setTitle(senderlabel->text()); ui.verticalLayout->addWidget(item); uasPropertyToLabelMap[senderlabel->text()] = item; diff --git a/src/ui/uas/UASQuickViewItem.cc b/src/ui/uas/UASQuickViewItem.cc index 6c075c64d..421a14ef6 100644 --- a/src/ui/uas/UASQuickViewItem.cc +++ b/src/ui/uas/UASQuickViewItem.cc @@ -3,24 +3,5 @@ UASQuickViewItem::UASQuickViewItem(QWidget *parent) : QWidget(parent) { - QVBoxLayout *layout = new QVBoxLayout(); - this->setLayout(layout); - titleLabel = new QLabel(this); - titleLabel->setAlignment(Qt::AlignHCenter); - this->layout()->addWidget(titleLabel); - valueLabel = new QLabel(this); - valueLabel->setAlignment(Qt::AlignHCenter); - valueLabel->setText("

0.00

"); - this->layout()->addWidget(valueLabel); - layout->addSpacerItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding)); -} -void UASQuickViewItem::setValue(double value) -{ - valueLabel->setText("

" + QString::number(value,'f',4) + "

"); -} - -void UASQuickViewItem::setTitle(QString title) -{ - titleLabel->setText(title); } diff --git a/src/ui/uas/UASQuickViewItem.h b/src/ui/uas/UASQuickViewItem.h index d6b1b12e0..a406c4a2a 100644 --- a/src/ui/uas/UASQuickViewItem.h +++ b/src/ui/uas/UASQuickViewItem.h @@ -8,15 +8,8 @@ class UASQuickViewItem : public QWidget Q_OBJECT public: explicit UASQuickViewItem(QWidget *parent = 0); - void setValue(double value); - void setTitle(QString title); -private: - QLabel *titleLabel; - QLabel *valueLabel; -signals: - -public slots: - + virtual void setValue(double value)=0; + virtual void setTitle(QString title)=0; }; #endif // UASQUICKVIEWITEM_H diff --git a/src/ui/uas/UASQuickViewItemSelect.cpp b/src/ui/uas/UASQuickViewItemSelect.cc similarity index 100% rename from src/ui/uas/UASQuickViewItemSelect.cpp rename to src/ui/uas/UASQuickViewItemSelect.cc diff --git a/src/ui/uas/UASQuickViewTextItem.cc b/src/ui/uas/UASQuickViewTextItem.cc new file mode 100644 index 000000000..a3ec42adb --- /dev/null +++ b/src/ui/uas/UASQuickViewTextItem.cc @@ -0,0 +1,24 @@ +#include "UASQuickViewTextItem.h" +#include +UASQuickViewTextItem::UASQuickViewTextItem(QWidget *parent) : UASQuickViewItem(parent) +{ + QVBoxLayout *layout = new QVBoxLayout(); + this->setLayout(layout); + titleLabel = new QLabel(this); + titleLabel->setAlignment(Qt::AlignHCenter); + this->layout()->addWidget(titleLabel); + valueLabel = new QLabel(this); + valueLabel->setAlignment(Qt::AlignHCenter); + valueLabel->setText("

0.00

"); + this->layout()->addWidget(valueLabel); + layout->addSpacerItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding)); +} +void UASQuickViewTextItem::setValue(double value) +{ + valueLabel->setText("

" + QString::number(value,'f',4) + "

"); +} + +void UASQuickViewTextItem::setTitle(QString title) +{ + titleLabel->setText(title); +} diff --git a/src/ui/uas/UASQuickViewTextItem.h b/src/ui/uas/UASQuickViewTextItem.h new file mode 100644 index 000000000..620420576 --- /dev/null +++ b/src/ui/uas/UASQuickViewTextItem.h @@ -0,0 +1,17 @@ +#ifndef UASQUICKVIEWTEXTITEM_H +#define UASQUICKVIEWTEXTITEM_H + +#include "UASQuickViewItem.h" +#include +class UASQuickViewTextItem : public UASQuickViewItem +{ +public: + UASQuickViewTextItem(QWidget *parent=0); + void setValue(double value); + void setTitle(QString title); +private: + QLabel *titleLabel; + QLabel *valueLabel; +}; + +#endif // UASQUICKVIEWTEXTITEM_H -- 2.22.0