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

Change for user configurable column count in UASQuickView

parent 342634ca
...@@ -4,10 +4,17 @@ ...@@ -4,10 +4,17 @@
#include "UASQuickViewItemSelect.h" #include "UASQuickViewItemSelect.h"
#include "UASQuickViewTextItem.h" #include "UASQuickViewTextItem.h"
#include <QSettings> #include <QSettings>
#include <QInputDialog>
UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent) UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent)
{ {
quickViewSelectDialog=0; quickViewSelectDialog=0;
m_columnCount=2;
m_currentColumn=0;
ui.setupUi(this); 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(activeUASSet(UASInterface*)),this,SLOT(setActiveUAS(UASInterface*)));
connect(UASManager::instance(),SIGNAL(UASCreated(UASInterface*)),this,SLOT(addUAS(UASInterface*))); connect(UASManager::instance(),SIGNAL(UASCreated(UASInterface*)),this,SLOT(addUAS(UASInterface*)));
if (UASManager::instance()->getActiveUAS()) if (UASManager::instance()->getActiveUAS())
...@@ -23,7 +30,7 @@ UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent) ...@@ -23,7 +30,7 @@ UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent)
{ {
valueEnabled("altitude"); valueEnabled("altitude");
valueEnabled("groundSpeed"); valueEnabled("groundSpeed");
valueEnabled("distToWaypoint"); valueEnabled("distToWP");
valueEnabled("yaw"); valueEnabled("yaw");
valueEnabled("roll"); valueEnabled("roll");
} }
...@@ -33,9 +40,15 @@ UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent) ...@@ -33,9 +40,15 @@ UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent)
connect(action,SIGNAL(triggered()),this,SLOT(actionTriggered())); connect(action,SIGNAL(triggered()),this,SLOT(actionTriggered()));
this->addAction(action); 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); updateTimer = new QTimer(this);
connect(updateTimer,SIGNAL(timeout()),this,SLOT(updateTimerTick())); connect(updateTimer,SIGNAL(timeout()),this,SLOT(updateTimerTick()));
updateTimer->start(1000); updateTimer->start(1000);
} }
UASQuickView::~UASQuickView() UASQuickView::~UASQuickView()
{ {
...@@ -44,6 +57,18 @@ UASQuickView::~UASQuickView() ...@@ -44,6 +57,18 @@ UASQuickView::~UASQuickView()
delete quickViewSelectDialog; 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() void UASQuickView::actionTriggered()
{ {
...@@ -75,6 +100,7 @@ void UASQuickView::saveSettings() ...@@ -75,6 +100,7 @@ void UASQuickView::saveSettings()
settings.setValue("type","text"); settings.setValue("type","text");
} }
settings.endArray(); settings.endArray();
settings.setValue("UAS_QUICK_VIEW_COLUMNS",m_columnCount);
settings.sync(); settings.sync();
} }
void UASQuickView::loadSettings() void UASQuickView::loadSettings()
...@@ -91,15 +117,27 @@ void UASQuickView::loadSettings() ...@@ -91,15 +117,27 @@ void UASQuickView::loadSettings()
valueEnabled(nameval); valueEnabled(nameval);
} }
} }
settings.endArray();
m_columnCount = settings.value("UAS_QUICK_VIEW_COLUMNS",1).toInt();
sortItems(m_columnCount);
} }
void UASQuickView::valueEnabled(QString value) void UASQuickView::valueEnabled(QString value)
{ {
UASQuickViewItem *item = new UASQuickViewTextItem(this); UASQuickViewItem *item = new UASQuickViewTextItem(this);
item->setTitle(value); 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; uasPropertyToLabelMap[value] = item;
uasEnabledPropertyList.append(value); uasEnabledPropertyList.append(value);
if (!uasPropertyValueMap.contains(value)) if (!uasPropertyValueMap.contains(value))
{ {
uasPropertyValueMap[value] = 0; uasPropertyValueMap[value] = 0;
...@@ -107,6 +145,44 @@ void UASQuickView::valueEnabled(QString value) ...@@ -107,6 +145,44 @@ void UASQuickView::valueEnabled(QString value)
saveSettings(); 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) void UASQuickView::valueDisabled(QString value)
{ {
...@@ -115,7 +191,10 @@ void UASQuickView::valueDisabled(QString value) ...@@ -115,7 +191,10 @@ void UASQuickView::valueDisabled(QString value)
UASQuickViewItem *item = uasPropertyToLabelMap[value]; UASQuickViewItem *item = uasPropertyToLabelMap[value];
uasPropertyToLabelMap.remove(value); uasPropertyToLabelMap.remove(value);
item->hide(); 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(); item->deleteLater();
uasEnabledPropertyList.removeOne(value); uasEnabledPropertyList.removeOne(value);
saveSettings(); saveSettings();
...@@ -282,16 +361,26 @@ void UASQuickView::actionTriggered(bool checked) ...@@ -282,16 +361,26 @@ void UASQuickView::actionTriggered(bool checked)
} }
if (checked) if (checked)
{ {
UASQuickViewItem *item = new UASQuickViewTextItem(this); valueEnabled(senderlabel->text());
/*UASQuickViewItem *item = new UASQuickViewTextItem(this);
item->setTitle(senderlabel->text()); item->setTitle(senderlabel->text());
ui.verticalLayout->addWidget(item); layout->addWidget(item);
uasPropertyToLabelMap[senderlabel->text()] = item; //ui.verticalLayout->addWidget(item);
m_currentColumn++;
if (m_currentColumn >= m_verticalLayoutList.size())
{
m_currentColumn = 0;
}
uasPropertyToLabelMap[senderlabel->text()] = item;*/
} }
else else
{ {
ui.verticalLayout->removeWidget(uasPropertyToLabelMap[senderlabel->text()]); valueDisabled(senderlabel->text());
/*layout->removeWidget(uasPropertyToLabelMap[senderlabel->text()]);
uasPropertyToLabelMap[senderlabel->text()]->deleteLater(); uasPropertyToLabelMap[senderlabel->text()]->deleteLater();
uasPropertyToLabelMap.remove(senderlabel->text()); uasPropertyToLabelMap.remove(senderlabel->text());*/
} }
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "UASQuickViewItem.h" #include "UASQuickViewItem.h"
#include "MAVLinkDecoder.h" #include "MAVLinkDecoder.h"
#include "UASQuickViewItemSelect.h" #include "UASQuickViewItemSelect.h"
#include "FlowLayout.h"
class UASQuickView : public QWidget class UASQuickView : public QWidget
{ {
Q_OBJECT Q_OBJECT
...@@ -40,6 +41,17 @@ private: ...@@ -40,6 +41,17 @@ private:
/** Loads gauge layout from settings file */ /** Loads gauge layout from settings file */
void loadSettings(); 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: protected:
Ui::Form ui; Ui::Form ui;
signals: signals:
...@@ -65,6 +77,7 @@ public slots: ...@@ -65,6 +77,7 @@ public slots:
void selectDialogClosed(); void selectDialogClosed();
void valueEnabled(QString value); void valueEnabled(QString value);
void valueDisabled(QString value); void valueDisabled(QString value);
void columnActionTriggered();
}; };
#endif // UASQUICKVIEW_H #endif // UASQUICKVIEW_H
...@@ -19,13 +19,9 @@ ...@@ -19,13 +19,9 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QHBoxLayout" name="horizontalLayout"/>
<property name="spacing">
<number>0</number>
</property>
</layout>
</item> </item>
</layout> </layout>
</widget> </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