Commit 08abea5b authored by DonLakeFlyer's avatar DonLakeFlyer

Remove InfoView widget

parent 60cec130
......@@ -353,13 +353,9 @@ FORMS += \
src/ui/QGCMAVLinkInspector.ui \
src/ui/QGCMAVLinkLogPlayer.ui \
src/ui/QGCMapRCToParamDialog.ui \
src/ui/QGCTabbedInfoView.ui \
src/ui/QGCUASFileView.ui \
src/ui/QGCUASFileViewMulti.ui \
src/ui/uas/QGCUnconnectedInfoWidget.ui \
src/ui/uas/UASMessageView.ui \
src/ui/uas/UASQuickView.ui \
src/ui/uas/UASQuickViewItemSelect.ui \
}
#
......@@ -618,7 +614,6 @@ HEADERS += \
src/ui/QGCMAVLinkInspector.h \
src/ui/QGCMAVLinkLogPlayer.h \
src/ui/QGCMapRCToParamDialog.h \
src/ui/QGCTabbedInfoView.h \
src/ui/QGCUASFileView.h \
src/ui/QGCUASFileViewMulti.h \
src/ui/linechart/ChartPlot.h \
......@@ -629,12 +624,6 @@ HEADERS += \
src/ui/linechart/ScrollZoomer.h \
src/ui/linechart/Scrollbar.h \
src/ui/uas/QGCUnconnectedInfoWidget.h \
src/ui/uas/UASMessageView.h \
src/ui/uas/UASQuickView.h \
src/ui/uas/UASQuickViewGaugeItem.h \
src/ui/uas/UASQuickViewItem.h \
src/ui/uas/UASQuickViewItemSelect.h \
src/ui/uas/UASQuickViewTextItem.h \
}
iOSBuild {
......@@ -782,7 +771,6 @@ SOURCES += \
src/ui/QGCMAVLinkInspector.cc \
src/ui/QGCMAVLinkLogPlayer.cc \
src/ui/QGCMapRCToParamDialog.cpp \
src/ui/QGCTabbedInfoView.cpp \
src/ui/QGCUASFileView.cc \
src/ui/QGCUASFileViewMulti.cc \
src/ui/linechart/ChartPlot.cc \
......@@ -793,12 +781,6 @@ SOURCES += \
src/ui/linechart/ScrollZoomer.cc \
src/ui/linechart/Scrollbar.cc \
src/ui/uas/QGCUnconnectedInfoWidget.cc \
src/ui/uas/UASMessageView.cc \
src/ui/uas/UASQuickView.cc \
src/ui/uas/UASQuickViewGaugeItem.cc \
src/ui/uas/UASQuickViewItem.cc \
src/ui/uas/UASQuickViewItemSelect.cc \
src/ui/uas/UASQuickViewTextItem.cc \
}
# Palette test widget in debug builds
......
......@@ -45,8 +45,6 @@
#ifndef __mobile__
#include "Linecharts.h"
#include "QGCUASFileViewMulti.h"
#include "UASQuickView.h"
#include "QGCTabbedInfoView.h"
#include "CustomCommandWidget.h"
#include "QGCDockWidget.h"
#include "HILDockWidget.h"
......@@ -69,7 +67,7 @@ enum DockWidgetTypes {
MAVLINK_INSPECTOR,
CUSTOM_COMMAND,
ONBOARD_FILES,
INFO_VIEW,
DEPRECATED_WIDGET,
HIL_CONFIG,
ANALYZE
};
......@@ -78,7 +76,7 @@ static const char *rgDockWidgetNames[] = {
"MAVLink Inspector",
"Custom Command",
"Onboard Files",
"Info View",
"Deprecated Widget",
"HIL Config",
"Analyze"
};
......@@ -367,12 +365,6 @@ bool MainWindow::_createInnerDockWidget(const QString& widgetName)
case ANALYZE:
widget = new Linecharts(widgetName, action, mavlinkDecoder, this);
break;
case INFO_VIEW:
widget= new QGCTabbedInfoView(widgetName, action, this);
break;
}
if(action->data().toInt() == INFO_VIEW) {
qobject_cast<QGCTabbedInfoView*>(widget)->addSource(mavlinkDecoder);
}
if(widget) {
_mapName2DockWidget[widgetName] = widget;
......
#include "QGCTabbedInfoView.h"
#include "QGCApplication.h"
QGCTabbedInfoView::QGCTabbedInfoView(const QString& title, QAction* action, QWidget *parent)
: QGCDockWidget(title, action, parent)
{
ui.setupUi(this);
messageView = new UASMessageViewWidget(qgcApp()->toolbox()->uasMessageHandler(), this);
quickView = new UASQuickView(this);
ui.tabWidget->addTab(quickView,"Quick");
ui.tabWidget->addTab(messageView,"Messages");
loadSettings();
}
void QGCTabbedInfoView::addSource(MAVLinkDecoder *decoder)
{
m_decoder = decoder;
quickView->addSource(decoder);
}
QGCTabbedInfoView::~QGCTabbedInfoView()
{
}
#ifndef QGCTABBEDINFOVIEW_H
#define QGCTABBEDINFOVIEW_H
#include "QGCDockWidget.h"
#include "MAVLinkDecoder.h"
#include "UASMessageView.h"
#include "UASQuickView.h"
#include "ui_QGCTabbedInfoView.h"
class QGCTabbedInfoView : public QGCDockWidget
{
Q_OBJECT
public:
explicit QGCTabbedInfoView(const QString& title, QAction* action, QWidget *parent = 0);
~QGCTabbedInfoView();
void addSource(MAVLinkDecoder *decoder);
private:
MAVLinkDecoder *m_decoder;
Ui::QGCTabbedInfoView ui;
UASMessageViewWidget *messageView;
UASQuickView *quickView;
};
#endif // QGCTABBEDINFOVIEW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QGCTabbedInfoView</class>
<widget class="QWidget" name="QGCTabbedInfoView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>571</width>
<height>457</height>
</rect>
</property>
<property name="windowTitle">
<string>Info View</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include <QMenu>
#include <QScrollBar>
#include "UASMessageView.h"
#include "QGCUnconnectedInfoWidget.h"
#include "ui_UASMessageView.h"
/*-------------------------------------------------------------------------------------
UASMessageView
-------------------------------------------------------------------------------------*/
UASMessageView::UASMessageView(QWidget *parent) :
QWidget(parent),
_ui(new Ui::UASMessageView)
{
_ui->setupUi(this);
}
UASMessageView::~UASMessageView()
{
delete _ui;
}
/*-------------------------------------------------------------------------------------
UASMessageViewWidget
-------------------------------------------------------------------------------------*/
UASMessageViewWidget::UASMessageViewWidget(UASMessageHandler* uasMessageHandler, QWidget *parent)
: UASMessageView(parent)
, _unconnectedWidget(NULL)
, _uasMessageHandler(uasMessageHandler)
{
setStyleSheet("QPlainTextEdit { border: 0px }");
// Enable the right-click menu for the text editor. This works because the plainTextEdit
// widget has its context menu policy set to its actions list. So any actions we add
// to this widget's action list will be automatically displayed.
// We only have the clear action right now.
QAction* clearAction = new QAction(tr("Clear Messages"), this);
connect(clearAction, &QAction::triggered, this, &UASMessageViewWidget::clearMessages);
ui()->plainTextEdit->addAction(clearAction);
// Connect message handler
connect(_uasMessageHandler, &UASMessageHandler::textMessageReceived, this, &UASMessageViewWidget::handleTextMessage);
}
UASMessageViewWidget::~UASMessageViewWidget()
{
}
void UASMessageViewWidget::clearMessages()
{
ui()->plainTextEdit->clear();
_uasMessageHandler->clearMessages();
}
void UASMessageViewWidget::handleTextMessage(UASMessage *message)
{
// Reset
if(!message) {
ui()->plainTextEdit->clear();
} else {
QPlainTextEdit *msgWidget = ui()->plainTextEdit;
// Turn off updates while we're appending content to avoid breaking the autoscroll behavior
msgWidget->setUpdatesEnabled(false);
QScrollBar *scroller = msgWidget->verticalScrollBar();
QString messages = message->getFormatedText();
messages = messages.replace("<#E>", "color: #f95e5e; font: monospace;");
messages = messages.replace("<#I>", "color: #f9b55e; font: monospace;");
messages = messages.replace("<#N>", "color: #ffffff; font: monospace;");
msgWidget->appendHtml(messages);
// Ensure text area scrolls correctly
scroller->setValue(scroller->maximum());
msgWidget->setUpdatesEnabled(true);
}
}
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#ifndef QGCMESSAGEVIEW_H
#define QGCMESSAGEVIEW_H
#include <QWidget>
#include <UASInterface.h>
#include <QVBoxLayout>
#include <QAction>
#include "QGCUnconnectedInfoWidget.h"
#include "UASMessageHandler.h"
class UASMessage;
namespace Ui {
class UASMessageView;
}
// Message View base class
class UASMessageView : public QWidget
{
Q_OBJECT
public:
explicit UASMessageView(QWidget *parent = 0);
virtual ~UASMessageView();
Ui::UASMessageView* ui() { return _ui; }
private:
Ui::UASMessageView* _ui;
};
// Message View Widget (used in the Info View tabbed Widget)
class UASMessageViewWidget : public UASMessageView
{
Q_OBJECT
public:
explicit UASMessageViewWidget(UASMessageHandler* uasMessageHandler, QWidget *parent = 0);
~UASMessageViewWidget();
public slots:
void handleTextMessage(UASMessage* message);
void clearMessages();
private:
QGCUnconnectedInfoWidget* _unconnectedWidget;
UASMessageHandler* _uasMessageHandler;
};
#endif // QGCMESSAGEVIEW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UASMessageView</class>
<widget class="QWidget" name="UASMessageView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>248</width>
<height>249</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "UASQuickView.h"
#include "UASQuickViewItemSelect.h"
#include "UASQuickViewTextItem.h"
#include "MultiVehicleManager.h"
#include "UAS.h"
#include "QGCApplication.h"
#include <QMetaMethod>
#include <QDebug>
#include <QSettings>
#include <QInputDialog>
UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent),
uas(NULL)
{
quickViewSelectDialog=0;
m_columnCount=2;
m_currentColumn=0;
ui.setupUi(this);
ui.horizontalLayout->setMargin(0);
m_verticalLayoutList.append(new QVBoxLayout());
ui.horizontalLayout->addItem(m_verticalLayoutList[0]);
connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &UASQuickView::_activeVehicleChanged);
_activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
this->setContextMenuPolicy(Qt::ActionsContextMenu);
loadSettings();
//If we don't have any predefined settings, set some defaults.
if (uasPropertyValueMap.size() == 0)
{
valueEnabled("altitudeAMSL");
valueEnabled("altitudeAMSLFT");
valueEnabled("altitudeRelative");
valueEnabled("groundSpeed");
valueEnabled("distToWaypoint");
}
QAction *action = new QAction("Add/Remove Items",this);
action->setCheckable(false);
connect(action,&QAction::triggered,this, &UASQuickView::addActionTriggered);
this->addAction(action);
QAction *columnaction = new QAction("Set Column Count",this);
columnaction->setCheckable(false);
connect(columnaction,&QAction::triggered,this,&UASQuickView::columnActionTriggered);
this->addAction(columnaction);
updateTimer = new QTimer(this);
connect(updateTimer,&QTimer::timeout,this,&UASQuickView::updateTimerTick);
updateTimer->start(1000);
}
UASQuickView::~UASQuickView()
{
if (quickViewSelectDialog)
{
delete quickViewSelectDialog;
}
}
void UASQuickView::columnActionTriggered()
{
bool ok = false;
int newcolumns = QInputDialog::getInt(
this,"Columns","Enter number of columns", m_columnCount, 1, 10, 1, &ok);
if (!ok)
{
return;
}
m_columnCount = newcolumns;
sortItems(newcolumns);
saveSettings();
}
void UASQuickView::addActionTriggered()
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->show();
return;
}
quickViewSelectDialog = new UASQuickViewItemSelect();
connect(quickViewSelectDialog,&UASQuickViewItemSelect::destroyed,this,&UASQuickView::selectDialogClosed);
connect(quickViewSelectDialog,&UASQuickViewItemSelect::valueDisabled,this,&UASQuickView::valueDisabled);
connect(quickViewSelectDialog,&UASQuickViewItemSelect::valueEnabled,this,&UASQuickView::valueEnabled);
quickViewSelectDialog->setAttribute(Qt::WA_DeleteOnClose,true);
for (QMap<QString,double>::const_iterator i = uasPropertyValueMap.constBegin();i!=uasPropertyValueMap.constEnd();i++)
{
quickViewSelectDialog->addItem(i.key(),uasEnabledPropertyList.contains(i.key()));
}
quickViewSelectDialog->show();
}
void UASQuickView::saveSettings()
{
QSettings settings;
settings.beginWriteArray("UAS_QUICK_VIEW_ITEMS");
int count = 0;
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin();i!=uasPropertyToLabelMap.constEnd();i++)
{
settings.setArrayIndex(count++);
settings.setValue("name",i.key());
settings.setValue("type","text");
}
settings.endArray();
settings.setValue("UAS_QUICK_VIEW_COLUMNS",m_columnCount);
}
void UASQuickView::loadSettings()
{
QSettings settings;
m_columnCount = settings.value("UAS_QUICK_VIEW_COLUMNS",1).toInt();
int size = settings.beginReadArray("UAS_QUICK_VIEW_ITEMS");
for (int i = 0; i < size; i++)
{
settings.setArrayIndex(i);
QString nameval = settings.value("name").toString();
QString typeval = settings.value("type").toString();
if (typeval == "text" && !uasPropertyToLabelMap.contains(nameval))
{
valueEnabled(nameval);
}
}
settings.endArray();
sortItems(m_columnCount);
}
void UASQuickView::valueEnabled(QString value)
{
UASQuickViewItem *item = new UASQuickViewTextItem(this);
item->setTitle(value);
//ui.verticalLayout->addWidget(item);
//m_currentColumn
m_verticalLayoutList[m_currentColumn]->addWidget(item);
m_PropertyToLayoutIndexMap[value] = m_currentColumn;
m_currentColumn++;
if (m_currentColumn >= m_columnCount-1)
{
m_currentColumn = 0;
}
uasPropertyToLabelMap[value] = item;
uasEnabledPropertyList.append(value);
if (!uasPropertyValueMap.contains(value))
{
uasPropertyValueMap[value] = 0;
}
saveSettings();
item->show();
sortItems(m_columnCount);
}
void UASQuickView::sortItems(int columncount)
{
QList<QWidget*> itemlist;
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin();i!=uasPropertyToLabelMap.constEnd();i++)
{
m_verticalLayoutList[m_PropertyToLayoutIndexMap[i.key()]]->removeWidget(i.value());
m_PropertyToLayoutIndexMap.remove(i.key());
itemlist.append(i.value());
}
// Item list has all the widgets available, now re-add them to the layouts.
for (int i = 0; i < m_verticalLayoutList.size(); i++)
{
ui.horizontalLayout->removeItem(m_verticalLayoutList[i]);
m_verticalLayoutList[i]->deleteLater(); //removeItem de-parents the item.
}
m_verticalLayoutList.clear();
// Create a vertical layout for every intended column
for (int i = 0; i < columncount; i++)
{
QVBoxLayout *layout = new QVBoxLayout();
ui.horizontalLayout->addItem(layout);
m_verticalLayoutList.append(layout);
layout->setMargin(0);
}
//Cycle through all items and add them to the layout
int currcol = 0;
for (int i = 0; i < itemlist.size(); i++)
{
m_verticalLayoutList[currcol]->addWidget(itemlist[i]);
currcol++;
if (currcol >= columncount)
{
currcol = 0;
}
}
m_currentColumn = currcol;
QApplication::processEvents();
recalculateItemTextSizing();
}
void UASQuickView::resizeEvent(QResizeEvent *evt)
{
Q_UNUSED(evt);
recalculateItemTextSizing();
}
void UASQuickView::recalculateItemTextSizing()
{
return;
int minpixelsize = 65535;
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin();i!=uasPropertyToLabelMap.constEnd();i++)
{
int tempmin = i.value()->minValuePixelSize();
if (tempmin < minpixelsize)
{
minpixelsize = tempmin;
}
}
if(minpixelsize < 6)
minpixelsize = 6;
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin();i!=uasPropertyToLabelMap.constEnd();i++)
{
i.value()->setValuePixelSize(minpixelsize);
}
}
void UASQuickView::valueDisabled(QString value)
{
if (uasPropertyToLabelMap.contains(value))
{
UASQuickViewItem *item = uasPropertyToLabelMap[value];
uasPropertyToLabelMap.remove(value);
item->hide();
//ui.verticalLayout->removeWidget(item);
//layout->removeWidget(item);
m_verticalLayoutList[m_PropertyToLayoutIndexMap[value]]->removeWidget(item);
sortItems(m_columnCount);
item->deleteLater();
uasEnabledPropertyList.removeOne(value);
saveSettings();
}
}
void UASQuickView::selectDialogClosed()
{
quickViewSelectDialog = 0;
}
void UASQuickView::updateTimerTick()
{
//uasPropertyValueMap
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin(); i != uasPropertyToLabelMap.constEnd();i++)
{
if (uasPropertyValueMap.contains(i.key()))
{
i.value()->setValue(uasPropertyValueMap[i.key()]);
}
}
}
void UASQuickView::_activeVehicleChanged(Vehicle* vehicle)
{
if (uas || !vehicle) {
return;
}
this->uas = vehicle->uas();
connect(uas, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64)));
}
void UASQuickView::addSource(MAVLinkDecoder *decoder)
{
connect(decoder,SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64)));
}
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant &variant, const quint64 msec)
{
Q_UNUSED(uasId);
Q_UNUSED(unit);
Q_UNUSED(msec);
bool ok;
double value = variant.toDouble(&ok);
QMetaType::Type metaType = static_cast<QMetaType::Type>(variant.type());
if(!ok || metaType == QMetaType::QString || metaType == QMetaType::QByteArray)
return;
if (!uasPropertyValueMap.contains(name))
{
if (quickViewSelectDialog)
{
quickViewSelectDialog->addItem(name);
}
}
uasPropertyValueMap[name] = value;
}
void UASQuickView::actionTriggered(bool checked)
{
QAction *senderlabel = qobject_cast<QAction*>(sender());
if (!senderlabel)
{
return;
}
if (checked)
{
valueEnabled(senderlabel->text());
/*UASQuickViewItem *item = new UASQuickViewTextItem(this);
item->setTitle(senderlabel->text());
layout->addWidget(item);
//ui.verticalLayout->addWidget(item);
m_currentColumn++;
if (m_currentColumn >= m_verticalLayoutList.size())
{
m_currentColumn = 0;
}
uasPropertyToLabelMap[senderlabel->text()] = item;*/
}
else
{
valueDisabled(senderlabel->text());
/*layout->removeWidget(uasPropertyToLabelMap[senderlabel->text()]);
uasPropertyToLabelMap[senderlabel->text()]->deleteLater();
uasPropertyToLabelMap.remove(senderlabel->text());*/
}
}
#ifndef UASQUICKVIEW_H
#define UASQUICKVIEW_H
#include <QWidget>
#include <QTimer>
#include <QLabel>
#include "uas/UASInterface.h"
#include "ui_UASQuickView.h"
#include "UASQuickViewItem.h"
#include "MAVLinkDecoder.h"
#include "UASQuickViewItemSelect.h"
#include "Vehicle.h"
class UASQuickView : public QWidget
{
Q_OBJECT
public:
UASQuickView(QWidget *parent = 0);
~UASQuickView();
void addSource(MAVLinkDecoder *decoder);
private:
UASInterface *uas;
/** List of enabled properties */
QList<QString> uasEnabledPropertyList;
/** Maps from the property name to the current value */
QMap<QString,double> uasPropertyValueMap;
/** Maps from property name to the display item */
QMap<QString,UASQuickViewItem*> uasPropertyToLabelMap;
/** Timer for updating the UI */
QTimer *updateTimer;
/** Selection dialog for selectin/deselecting gauge items */
UASQuickViewItemSelect *quickViewSelectDialog;
/** Saves gauge layout to settings file */
void saveSettings();
/** Loads gauge layout from settings file */
void loadSettings();
void recalculateItemTextSizing();
/** Column Count */
int m_columnCount;
QList<QVBoxLayout*> m_verticalLayoutList;
void sortItems(int columncount);
QList<int> m_verticalLayoutItemCount;
int m_currentColumn;
QMap<QString,int> m_PropertyToLayoutIndexMap;
//FlowLayout *layout;
protected:
Ui::Form ui;
void resizeEvent(QResizeEvent *evt);
signals:
public slots:
void valueChanged(const int uasid, const QString& name, const QString& unit, const QVariant& value,const quint64 msecs);
void actionTriggered(bool checked);
void addActionTriggered();
void updateTimerTick();
void selectDialogClosed();
void valueEnabled(QString value);
void valueDisabled(QString value);
void columnActionTriggered();
private slots:
void _activeVehicleChanged(Vehicle* vehicle);
};
#endif // UASQUICKVIEW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "UASQuickViewGaugeItem.h"
#include <QVBoxLayout>
UASQuickViewGaugeItem::UASQuickViewGaugeItem(QWidget *parent) : UASQuickViewItem(parent)
{
}
void UASQuickViewGaugeItem::setValue(double value)
{
valueLabel->setText(QString::number(value,'f',4));
}
void UASQuickViewGaugeItem::setTitle(QString title)
{
titleLabel->setText(title);
}
void UASQuickViewGaugeItem::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
QFont valuefont = valueLabel->font();
QFont titlefont = titleLabel->font();
valuefont.setPixelSize(this->height() / 2.0);
titlefont.setPixelSize(this->height() / 4.0);
valueLabel->setFont(valuefont);
titleLabel->setFont(titlefont);
update();
}
#ifndef UASQuickViewGaugeItem_H
#define UASQuickViewGaugeItem_H
#include "UASQuickViewItem.h"
#include <QLabel>
class UASQuickViewGaugeItem : public UASQuickViewItem
{
public:
UASQuickViewGaugeItem(QWidget *parent=0);
void setValue(double value);
void setTitle(QString title);
protected:
void resizeEvent(QResizeEvent *event);
private:
QLabel *titleLabel;
QLabel *valueLabel;
};
#endif // UASQuickViewGaugeItem_H
#include "UASQuickViewItem.h"
UASQuickViewItem::UASQuickViewItem(QWidget *parent) :
QWidget(parent)
{
}
#ifndef UASQUICKVIEWITEM_H
#define UASQUICKVIEWITEM_H
#include <QWidget>
class UASQuickViewItem : public QWidget
{
Q_OBJECT
public:
explicit UASQuickViewItem(QWidget *parent = 0);
virtual void setValue(double value)=0;
virtual void setTitle(QString title)=0;
virtual int minValuePixelSize()=0;
virtual void setValuePixelSize(int size)=0;
};
#endif // UASQUICKVIEWITEM_H
#include "UASQuickViewItemSelect.h"
#include <QLabel>
#include <QCheckBox>
UASQuickViewItemSelect::UASQuickViewItemSelect(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
currcol = 0;
currrow = 0;
ui.gridLayout->setSpacing(5);
ui.gridLayout->setMargin(0);
}
void UASQuickViewItemSelect::addItem(QString item,bool enabled)
{
QString category = ".";
QString name = item;
if (item.indexOf(":") != -1 && item.indexOf(".") != -1)
{
//Item has a subcateogry
category = item.mid(item.indexOf(":")+1,item.indexOf(".") - item.indexOf(":")-1);
name = item.mid(item.indexOf(".")+1);
}
int col = -1;
if (m_categoryToIndexMap.contains(category))
{
col = m_categoryToIndexMap[category];
}
else
{
m_categoryToIndexMap[category] = currcol++;
col = m_categoryToIndexMap[category];
//New column.
QLabel *titlelabel = new QLabel(this);
titlelabel->setText(category);
titlelabel->show();
ui.gridLayout->addWidget(titlelabel,0,col);
}
QCheckBox *label = new QCheckBox(this);
m_checkboxToValueMap[label] = item;
m_checkBoxList.append(label);
if (enabled)
{
label->setChecked(true);
}
connect(label,SIGNAL(clicked(bool)),this,SLOT(checkBoxClicked(bool)));
label->setText(name);
label->show();
//ui.gridLayout->addWidget(label,currrow,currcol++);
bool breakout = false;
int row = -1;
while (!breakout)
{
if (!ui.gridLayout->itemAtPosition(++row,col) || row > 100)
{
breakout = true;
}
}
//Row is the next invalid object, and col is the proper column.
ui.gridLayout->addWidget(label,row,col);
}
void UASQuickViewItemSelect::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
/*for (int i=0;i<m_checkBoxList.size();i++)
{
ui.gridLayout->removeWidget(m_checkBoxList[i]);
}
int row = 0;
int col = 0;
for (int i=0;i<m_checkBoxList.size();i++)
{
ui.gridLayout->addWidget(m_checkBoxList[i],row,col);
col++;
ui.gridLayout->widget()->width() > this->width();
//need to reduce column number.
}*/
}
void UASQuickViewItemSelect::checkBoxClicked(bool checked)
{
QCheckBox *check = qobject_cast<QCheckBox*>(sender());
if (!check)
{
return;
}
QString checkval = check->text();
if (m_checkboxToValueMap.contains(check))
{
checkval = m_checkboxToValueMap[check];
}
if (checked)
{
emit valueEnabled(checkval);
}
else
{
emit valueDisabled(checkval);
}
}
UASQuickViewItemSelect::~UASQuickViewItemSelect()
{
}
#ifndef UASQUICKVIEWITEMSELECT_H
#define UASQUICKVIEWITEMSELECT_H
#include <QWidget>
#include <QCheckBox>
#include "ui_UASQuickViewItemSelect.h"
class UASQuickViewItemSelect : public QWidget
{
Q_OBJECT
public:
explicit UASQuickViewItemSelect(QWidget *parent = 0);
~UASQuickViewItemSelect();
void addItem(QString item,bool enabled = false);
int currrow;
int currcol;
protected:
void resizeEvent(QResizeEvent *event);
private:
QMap<QString,int> m_categoryToIndexMap;
QMap<QCheckBox*,QString> m_checkboxToValueMap;
QList<QCheckBox*> m_checkBoxList;
Ui::UASQuickViewItemSelect ui;
private slots:
void checkBoxClicked(bool checked);
signals:
void valueEnabled(QString value);
void valueDisabled(QString value);
};
#endif // UASQUICKVIEWITEMSELECT_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UASQuickViewItemSelect</class>
<widget class="QWidget" name="UASQuickViewItemSelect">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>947</width>
<height>248</height>
</rect>
</property>
<property name="windowTitle">
<string>Select Item</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>927</width>
<height>228</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "UASQuickViewTextItem.h"
#include <QVBoxLayout>
#include <QDebug>
UASQuickViewTextItem::UASQuickViewTextItem(QWidget *parent) : UASQuickViewItem(parent)
{
// Set a standard vertical layout.
QVBoxLayout* layout = new QVBoxLayout();
layout->setMargin(0);
layout->setSizeConstraint(QLayout::SetMinimumSize);
// Create the title label. Scale the font based on available size.
titleLabel = new QLabel(this);
titleLabel->setAlignment(Qt::AlignHCenter);
titleLabel->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Minimum);
titleLabel->setObjectName(QString::fromUtf8("title"));
QFont titlefont = titleLabel->font();
//titlefont.setPixelSize(this->height() / 4.0);
titleLabel->setFont(titlefont);
layout->addWidget(titleLabel);
// Create the value label. Scale the font based on available size.
valueLabel = new QLabel(this);
valueLabel->setAlignment(Qt::AlignHCenter);
valueLabel->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Minimum);
valueLabel->setObjectName(QString::fromUtf8("value"));
valueLabel->setText("0.00");
QFont valuefont = valueLabel->font();
//valuefont.setPixelSize(this->height() / 2.0);
valueLabel->setFont(valuefont);
layout->addWidget(valueLabel);
// And make sure the items are evenly spaced in the UASQuickView.
layout->addSpacerItem(new QSpacerItem(10, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
this->setLayout(layout);
}
void UASQuickViewTextItem::setValue(double value)
{
if (value < 10 && value > -10)
{
valueLabel->setText(QString::number(value,'f',4));
}
else if (value < 100 && value > -100)
{
valueLabel->setText(QString::number(value,'f',3));
}
else if (value < 1000 && value > -1000)
{
valueLabel->setText(QString::number(value,'f',2));
}
else if (value < 10000 && value > -10000)
{
valueLabel->setText(QString::number(value,'f',1));
}
else
{
valueLabel->setText(QString::number(value,'f',0));
}
}
void UASQuickViewTextItem::setTitle(QString title)
{
if (title.indexOf(".") != -1 && title.indexOf(":") != -1)
{
titleLabel->setText(title.mid(title.indexOf(".") + 1));
}
else
{
titleLabel->setText(title);
}
}
int UASQuickViewTextItem::minValuePixelSize()
{
QFont valuefont = valueLabel->font();
QFont titlefont = titleLabel->font();
valuefont.setPixelSize(this->height());
titlefont.setPixelSize(valuefont.pointSize() * 0.75);
//spacerItem->setGeometry(QRect(0,0,20,this->height()/10.0));
QFontMetrics metrics(valuefont);
//valuefont.setPixelSize(this->height() / 2.0);
bool fit = false;
while (!fit)
{
QFontMetrics valfm( valuefont );
QRect valbound = valfm.boundingRect(0,0, valueLabel->width(), valueLabel->height(), Qt::TextWordWrap | Qt::AlignLeft, "12345678.00"/*valueLabel->text()*/);
//QFontMetrics titlefm( titlefont );
//QRect titlebound = titlefm.boundingRect(0,0, titleLabel->width(), titleLabel->height(), Qt::TextWordWrap | Qt::AlignLeft, titleLabel->text());
if ((valbound.width() <= valueLabel->width() && valbound.height() <= valueLabel->height())) // && (titlebound.width() <= titleLabel->width() && titlebound.height() <= titleLabel->height()))
fit = true;
else
{
if (valuefont.pointSize() - 1 <= 6)
{
fit = true;
valuefont.setPixelSize(6);
}
else
{
valuefont.setPixelSize(valuefont.pointSize() - 1);
}
//titlefont.setPixelSize(valuefont.pointSize() / 2.0);
//qDebug() << "Point size:" << valuefont.pointSize() << valueLabel->width() << valueLabel->height();
}
}
return valuefont.pointSize();
}
void UASQuickViewTextItem::setValuePixelSize(int size)
{
QFont valuefont = valueLabel->font();
QFont titlefont = titleLabel->font();
valuefont.setPixelSize(size);
titlefont.setPixelSize(valuefont.pointSize() * 0.75);
valueLabel->setFont(valuefont);
titleLabel->setFont(titlefont);
update();
}
void UASQuickViewTextItem::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
return;
#if 0
// code ifdef'ed out to silence warnings
QFont valuefont = valueLabel->font();
QFont titlefont = titleLabel->font();
valuefont.setPixelSize(this->height());
titlefont.setPixelSize(valuefont.pointSize() / 2.0);
//spacerItem->setGeometry(QRect(0,0,20,this->height()/10.0));
QFontMetrics metrics(valuefont);
//valuefont.setPixelSize(this->height() / 2.0);
bool fit = false;
while (!fit)
{
QFontMetrics valfm( valuefont );
QRect valbound = valfm.boundingRect(0,0, valueLabel->width(), valueLabel->height(), Qt::TextWordWrap | Qt::AlignLeft, valueLabel->text());
//QFontMetrics titlefm( titlefont );
//QRect titlebound = titlefm.boundingRect(0,0, titleLabel->width(), titleLabel->height(), Qt::TextWordWrap | Qt::AlignLeft, titleLabel->text());
if ((valbound.width() <= valueLabel->width() && valbound.height() <= valueLabel->height()))// && (titlebound.width() <= titleLabel->width() && titlebound.height() <= titleLabel->height()))
fit = true;
else
{
if (valuefont.pointSize()-5 <= 0)
{
fit = true;
valuefont.setPixelSize(5);
}
else
{
valuefont.setPixelSize(valuefont.pointSize() - 5);
}
//titlefont.setPixelSize(valuefont.pointSize() / 2.0);
//qDebug() << "Point size:" << valuefont.pointSize() << valueLabel->width() << valueLabel->height();
}
}
titlefont.setPixelSize(valuefont.pointSize() / 2.0);
valueLabel->setFont(valuefont);
titleLabel->setFont(titlefont);
update();
#endif
}
#ifndef UASQUICKVIEWTEXTITEM_H
#define UASQUICKVIEWTEXTITEM_H
#include "UASQuickViewItem.h"
#include <QLabel>
#include <QSpacerItem>
class UASQuickViewTextItem : public UASQuickViewItem
{
public:
UASQuickViewTextItem(QWidget *parent=0);
void setValue(double value);
void setTitle(QString title);
int minValuePixelSize();
void setValuePixelSize(int size);
protected:
void resizeEvent(QResizeEvent *event);
private:
QLabel *titleLabel;
QLabel *valueLabel;
};
#endif // UASQUICKVIEWTEXTITEM_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment