diff --git a/src/ui/uas/UASQuickView.cc b/src/ui/uas/UASQuickView.cc index 9bb52255d44e773dd3f3e915380d2731a7f68b1e..23e3fcc2d4ce4b4b83feb9d7ed456b4c200f3279 100644 --- a/src/ui/uas/UASQuickView.cc +++ b/src/ui/uas/UASQuickView.cc @@ -4,10 +4,17 @@ #include "UASQuickViewItemSelect.h" #include "UASQuickViewTextItem.h" #include +#include UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent) { quickViewSelectDialog=0; + m_columnCount=2; + m_currentColumn=0; ui.setupUi(this); + + m_verticalLayoutList.append(new QVBoxLayout()); + ui.horizontalLayout->addItem(m_verticalLayoutList[0]); + connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(setActiveUAS(UASInterface*))); connect(UASManager::instance(),SIGNAL(UASCreated(UASInterface*)),this,SLOT(addUAS(UASInterface*))); if (UASManager::instance()->getActiveUAS()) @@ -23,7 +30,7 @@ UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent) { valueEnabled("altitude"); valueEnabled("groundSpeed"); - valueEnabled("distToWaypoint"); + valueEnabled("distToWP"); valueEnabled("yaw"); valueEnabled("roll"); } @@ -33,9 +40,15 @@ UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent) connect(action,SIGNAL(triggered()),this,SLOT(actionTriggered())); this->addAction(action); + QAction *columnaction = new QAction("Set Column Count",this); + columnaction->setCheckable(false); + connect(columnaction,SIGNAL(triggered()),this,SLOT(columnActionTriggered())); + this->addAction(columnaction); + updateTimer = new QTimer(this); connect(updateTimer,SIGNAL(timeout()),this,SLOT(updateTimerTick())); updateTimer->start(1000); + } UASQuickView::~UASQuickView() { @@ -44,6 +57,18 @@ UASQuickView::~UASQuickView() delete quickViewSelectDialog; } } +void UASQuickView::columnActionTriggered() +{ + bool ok = false; + int newcolumns = QInputDialog::getInt(this,"Columns","Enter number of columns",1,0,100,1,&ok); + if (!ok) + { + return; + } + m_columnCount = newcolumns; + sortItems(newcolumns); + saveSettings(); +} void UASQuickView::actionTriggered() { @@ -75,6 +100,7 @@ void UASQuickView::saveSettings() settings.setValue("type","text"); } settings.endArray(); + settings.setValue("UAS_QUICK_VIEW_COLUMNS",m_columnCount); settings.sync(); } void UASQuickView::loadSettings() @@ -91,15 +117,27 @@ void UASQuickView::loadSettings() valueEnabled(nameval); } } + settings.endArray(); + m_columnCount = settings.value("UAS_QUICK_VIEW_COLUMNS",1).toInt(); + sortItems(m_columnCount); } void UASQuickView::valueEnabled(QString value) { UASQuickViewItem *item = new UASQuickViewTextItem(this); item->setTitle(value); - ui.verticalLayout->addWidget(item); + //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; @@ -107,6 +145,44 @@ void UASQuickView::valueEnabled(QString value) saveSettings(); } +void UASQuickView::sortItems(int columncount) +{ + QList itemlist; + for (QMap::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 availble, now re-add them to the layouts. + for (int i=0;iremoveItem(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;iaddItem(layout); + m_verticalLayoutList.append(layout); + } + + //Cycle through all items and add them to the layout + int currcol = 0; + for (int i=0;iaddWidget(itemlist[i]); + currcol++; + if (currcol >= columncount) + { + currcol = 0; + } + } + m_currentColumn = currcol; +} void UASQuickView::valueDisabled(QString value) { @@ -115,7 +191,10 @@ void UASQuickView::valueDisabled(QString value) UASQuickViewItem *item = uasPropertyToLabelMap[value]; uasPropertyToLabelMap.remove(value); item->hide(); - ui.verticalLayout->removeWidget(item); + //ui.verticalLayout->removeWidget(item); + //layout->removeWidget(item); + m_verticalLayoutList[m_PropertyToLayoutIndexMap[value]]->removeWidget(item); + sortItems(m_columnCount); item->deleteLater(); uasEnabledPropertyList.removeOne(value); saveSettings(); @@ -282,16 +361,26 @@ void UASQuickView::actionTriggered(bool checked) } if (checked) { - UASQuickViewItem *item = new UASQuickViewTextItem(this); + valueEnabled(senderlabel->text()); + /*UASQuickViewItem *item = new UASQuickViewTextItem(this); item->setTitle(senderlabel->text()); - ui.verticalLayout->addWidget(item); - uasPropertyToLabelMap[senderlabel->text()] = item; + layout->addWidget(item); + //ui.verticalLayout->addWidget(item); + m_currentColumn++; + if (m_currentColumn >= m_verticalLayoutList.size()) + { + m_currentColumn = 0; + } + uasPropertyToLabelMap[senderlabel->text()] = item;*/ + + } else { - ui.verticalLayout->removeWidget(uasPropertyToLabelMap[senderlabel->text()]); + valueDisabled(senderlabel->text()); + /*layout->removeWidget(uasPropertyToLabelMap[senderlabel->text()]); uasPropertyToLabelMap[senderlabel->text()]->deleteLater(); - uasPropertyToLabelMap.remove(senderlabel->text()); + uasPropertyToLabelMap.remove(senderlabel->text());*/ } } diff --git a/src/ui/uas/UASQuickView.h b/src/ui/uas/UASQuickView.h index 4a0dc9b7b240bfa3670b07ff4e1ac30acd343bd1..16109e4a1a5ea969e1f64701fdca845bf8da7b0f 100644 --- a/src/ui/uas/UASQuickView.h +++ b/src/ui/uas/UASQuickView.h @@ -10,6 +10,7 @@ #include "UASQuickViewItem.h" #include "MAVLinkDecoder.h" #include "UASQuickViewItemSelect.h" +#include "FlowLayout.h" class UASQuickView : public QWidget { Q_OBJECT @@ -40,6 +41,17 @@ private: /** Loads gauge layout from settings file */ void loadSettings(); + + /** Column Count */ + int m_columnCount; + + QList m_verticalLayoutList; + void sortItems(int columncount); + QList m_verticalLayoutItemCount; + int m_currentColumn; + QMap m_PropertyToLayoutIndexMap; + + //FlowLayout *layout; protected: Ui::Form ui; signals: @@ -65,6 +77,7 @@ public slots: void selectDialogClosed(); void valueEnabled(QString value); void valueDisabled(QString value); + void columnActionTriggered(); }; #endif // UASQUICKVIEW_H diff --git a/src/ui/uas/UASQuickView.ui b/src/ui/uas/UASQuickView.ui index 067c3afc6f489a4914bcb40aebc2e1307a1fa1af..f11c734b7cc8ae1a57fdf65b9497f9eb55f5d8c0 100644 --- a/src/ui/uas/UASQuickView.ui +++ b/src/ui/uas/UASQuickView.ui @@ -19,13 +19,9 @@ Form - + - - - 0 - - +