Commit 84af735e authored by Michael Carpenter's avatar Michael Carpenter

Change for user configurable column count in UASQuickView

parent 342634ca
......@@ -4,10 +4,17 @@
#include "UASQuickViewItemSelect.h"
#include "UASQuickViewTextItem.h"
#include <QSettings>
#include <QInputDialog>
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<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 availble, 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(this);
ui.horizontalLayout->addItem(layout);
m_verticalLayoutList.append(layout);
}
//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;
}
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());*/
}
}
......
......@@ -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<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;
signals:
......@@ -65,6 +77,7 @@ public slots:
void selectDialogClosed();
void valueEnabled(QString value);
void valueDisabled(QString value);
void columnActionTriggered();
};
#endif // UASQUICKVIEW_H
......@@ -19,13 +19,9 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
</layout>
<item>
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
</layout>
</widget>
......
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