1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

GCS-Added new dialog to let the user choose from a list of available

configurations uppon startup when no valid configuration is found
This commit is contained in:
PT_Dreamer 2012-08-09 22:22:09 +01:00
parent 821f954276
commit e033004656
3 changed files with 170 additions and 0 deletions

View File

@ -0,0 +1,55 @@
#include "importsettings.h"
#include "ui_importsettings.h"
#include <QDir>
#include <QSettings>
#include <utils/xmlconfig.h>
importSettings::importSettings(QWidget *parent) :
QDialog(parent),
ui(new Ui::importSettings)
{
ui->setupUi(this);
connect(ui->cbConfigs,SIGNAL(currentIndexChanged(int)),this,SLOT(updateDetails(int)));
connect(ui->btnLoad,SIGNAL(clicked()),this,SLOT(accept()));
}
void importSettings::loadFiles(QString path)
{
QDir myDir(path);
QStringList filters;
filters << "*.xml";
QStringList list = myDir.entryList(filters,QDir::Files);
int x=0;
foreach(QString fileStr, list)
{
fileInfo * info=new fileInfo;
QSettings settings(path+QDir::separator()+fileStr, XmlConfig::XmlSettingsFormat);
settings.beginGroup("General");
info->description=settings.value("Description","None").toString();
info->details=settings.value("Details","None").toString();
settings.endGroup();
info->file=path+QDir::separator()+fileStr;
configList.insert(x,info);
ui->cbConfigs->addItem(info->description,x);
++x;
}
}
void importSettings::updateDetails(int index)
{
fileInfo * info=configList.value(ui->cbConfigs->itemData(index).toInt());
ui->lblDetails->setText(info->details);
}
QString importSettings::choosenConfig()
{
fileInfo * info=configList.value(ui->cbConfigs->itemData(ui->cbConfigs->currentIndex()).toInt());
return info->file;
}
importSettings::~importSettings()
{
foreach(fileInfo * info,configList.values())
{
delete info;
}
delete ui;
}

View File

@ -0,0 +1,33 @@
#ifndef IMPORTSETTINGS_H
#define IMPORTSETTINGS_H
#include <QDialog>
#include <QMap>
namespace Ui {
class importSettings;
}
class importSettings : public QDialog
{
Q_OBJECT
struct fileInfo
{
QString file;
QString description;
QString details;
};
public:
explicit importSettings(QWidget *parent = 0);
~importSettings();
void loadFiles(QString path);
QString choosenConfig();
private:
Ui::importSettings *ui;
QMap<int,fileInfo*> configList;
private slots:
void updateDetails(int);
};
#endif // IMPORTSETTINGS_H

View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>importSettings</class>
<widget class="QDialog" name="importSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>373</width>
<height>167</height>
</rect>
</property>
<property name="windowTitle">
<string>OpenPilotGCS</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>No configuration file could be found.
Please choose from one of the default configurations</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbConfigs"/>
</item>
<item>
<widget class="QLabel" name="lblDetails">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnLoad">
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>