Skip to content
Browse files

Panel and gauges used to use different ini files.

I've combined them into one, and changed the format
from system default to an ini file called 
"extpanel_guages.ini" in the same path as the 
executable. This will be to allow import and 
export of ini files, so that several cockpits may
be saved on disk.
  • Loading branch information...
1 parent 1578c82 commit 04b116dd9a486cf9cfecdf5d134218285fcfe4b9 bobgates committed Jul 19, 2011
Showing with 91 additions and 21 deletions.
  1. +33 −13 dialogs/settingsdialog.cpp
  2. +4 −2 dialogs/settingsdialog.h
  3. +53 −6 menubutton.cpp
  4. +1 −0 menubutton.h
View
46 dialogs/settingsdialog.cpp
@@ -1,9 +1,22 @@
+/* This file manages the getting and setting of application settings:
+ - panel rotation
+ - panel fullscreen
+ - IP address
+*/
+
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
-SettingsDialog::SettingsDialog(QWidget *parent) :
+SettingsDialog::SettingsDialog(QWidget *parent, QSettings *settings) :
QDialog(parent),
- ui(new Ui::SettingsDialog), settings("org.vranki", "extplane-gauges-settings", this) {
+ ui(new Ui::SettingsDialog){
+
+/* _rotation=0;
+ _fullscreen=false;
+ _serverAddress=QString("127.0.0.1:51000");
+*/
+ _settings = settings;
+
ui->setupUi(this);
connect(ui->panelRotationDial, SIGNAL(valueChanged(int)), this, SIGNAL(rotationChanged(int)));
connect(ui->fullscreenCheckbox, SIGNAL(clicked(bool)), this, SIGNAL(fullscreenChanged(bool)));
@@ -25,21 +38,28 @@ void SettingsDialog::changeEvent(QEvent *e) {
}
}
+
void SettingsDialog::loadSettings() {
- settings.beginGroup("settings");
- qDebug() << Q_FUNC_INFO << settings.value("panelrotation").toInt();
- ui->panelRotationDial->setValue(settings.value("panelrotation").toInt());
- ui->fullscreenCheckbox->setChecked(settings.value("fullscreen", false).toBool());
+ /* Load settings for panel rotation, fullscreen, and address from .ini file */
+
+ _settings->beginGroup("settings");
+ qDebug() << Q_FUNC_INFO << _settings->value("panelrotation").toInt();
+ ui->panelRotationDial->setValue(_settings->value("panelrotation").toInt());
+ ui->fullscreenCheckbox->setChecked(_settings->value("fullscreen", false).toBool());
emit fullscreenChanged(ui->fullscreenCheckbox->isChecked());
- ui->serverAddressEdit->setText(settings.value("serveraddress", "127.0.0.1:51000").toString());
+ ui->serverAddressEdit->setText(_settings->value("serveraddress", "127.0.0.1:51000").toString());
emit setServerAddress(ui->serverAddressEdit->text());
- settings.endGroup();
+ _settings->endGroup();
+
}
void SettingsDialog::saveSettings() {
- settings.beginGroup("settings");
- settings.setValue("panelrotation", ui->panelRotationDial->value());
- settings.setValue("fullscreen", ui->fullscreenCheckbox->isChecked());
- settings.setValue("serveraddress", ui->serverAddressEdit->text());
- settings.endGroup();
+ /* Load settings for panel rotation, fullscreen, and address from .ini file */
+
+ _settings->beginGroup("settings");
+ _settings->setValue("panelrotation", ui->panelRotationDial->value());
+ _settings->setValue("fullscreen", ui->fullscreenCheckbox->isChecked());
+ _settings->setValue("serveraddress", ui->serverAddressEdit->text());
+ _settings->endGroup();
+
}
View
6 dialogs/settingsdialog.h
@@ -13,19 +13,21 @@ class SettingsDialog : public QDialog {
Q_OBJECT
public:
- explicit SettingsDialog(QWidget *parent);
+ explicit SettingsDialog(QWidget *parent, QSettings *settings);
~SettingsDialog();
void loadSettings();
void saveSettings();
+
protected:
void changeEvent(QEvent *e);
signals:
void rotationChanged(int r);
void fullscreenChanged(bool fs);
void setServerAddress(QString host);
+
private:
Ui::SettingsDialog *ui;
- QSettings settings;
+ QSettings * _settings;
};
#endif // SETTINGSDIALOG_H
View
59 menubutton.cpp
@@ -1,13 +1,15 @@
#include "menubutton.h"
MenuButton::MenuButton(QWidget *parent, QList<PanelItem*> &gaugelist, PanelItemFactory *gf) :
- QObject(parent), panelItems(gaugelist), itemFactory(gf), settings("org.vranki", "extplane-gauges-panels", this)
+ QObject(parent), panelItems(gaugelist), itemFactory(gf),
+ settings(QString("extpanel_gauges.ini"), QSettings::IniFormat, this)
+/*settings("org.vranki", "extplane-gauges-panels", this)*/
{
parentWidget = parent;
side = 20;
msg = 0;
editMode = false;
- settingsDialog = new SettingsDialog(parentWidget);
+ settingsDialog = new SettingsDialog(parentWidget, &settings);
connect(settingsDialog, SIGNAL(rotationChanged(int)), this, SIGNAL(panelRotationChanged(int)));
connect(settingsDialog, SIGNAL(fullscreenChanged(bool)), this, SIGNAL(fullscreenChanged(bool)));
connect(settingsDialog, SIGNAL(setServerAddress(QString)), this, SIGNAL(setServerAddress(QString)));
@@ -62,15 +64,23 @@ void MenuButton::mousePressEvent ( QGraphicsSceneMouseEvent * event ) {
QPushButton *saveButton = new QPushButton("Save panel", msg);
connect(saveButton, SIGNAL(clicked()), this, SLOT(savePanel()));
layout->addWidget(saveButton);
+
QPushButton *loadButton = new QPushButton("Load panel", msg);
connect(loadButton, SIGNAL(clicked()), this, SLOT(loadPanel()));
layout->addWidget(loadButton);
+
+ QPushButton *exportButton = new QPushButton("Export panel", msg);
+ connect(exportButton, SIGNAL(clicked()), this, SLOT(exportPanel()));
+ layout->addWidget(exportButton);
+
QPushButton *settingsButton = new QPushButton("App Settings", msg);
connect(settingsButton, SIGNAL(clicked()), this, SLOT(showSettings()));
layout->addWidget(settingsButton);
+
QPushButton *closeButton = new QPushButton("Close", msg);
connect(closeButton, SIGNAL(clicked()), this, SLOT(closeDialog()));
layout->addWidget(closeButton);
+
QPushButton *quitButton = new QPushButton("Quit", msg);
connect(quitButton, SIGNAL(clicked()), this, SLOT(quit()));
layout->addWidget(quitButton);
@@ -112,10 +122,11 @@ void MenuButton::deleteItems() {
}
void MenuButton::savePanel() {
- settingsDialog->saveSettings();
- int panelNumber = 0;
- QString panelName = "Panel";
+
settings.clear();
+ settingsDialog->saveSettings(); // First save panel settings
+ int panelNumber = 0; // Now save gauge settings
+ QString panelName = "Panel";
settings.beginGroup("panel-" + QString::number(panelNumber));
settings.setValue("number", panelNumber);
settings.setValue("name", panelName);
@@ -137,8 +148,9 @@ void MenuButton::closeDialog() {
}
void MenuButton::loadPanel() {
- settingsDialog->loadSettings();
+ settingsDialog->loadSettings(); // Fetches global panel settings and loads them
+ // Now go to gauge settings and load those:
foreach(PanelItem *g, panelItems) {
g->deleteLater();
}
@@ -169,6 +181,41 @@ void MenuButton::loadPanel() {
closeDialog();
}
+void MenuButton::exportPanel(void) {
+ // To be replaced with code to export current panel ini file to external file.
+
+/* settingsDialog->loadSettings();
+
+ foreach(PanelItem *g, panelItems) {
+ g->deleteLater();
+ }
+ int panelNumber = 0;
+ while(panelNumber >= 0) {
+ settings.beginGroup("panel-" + QString::number(panelNumber));
+ if(settings.contains("name")) {
+ int gc = settings.value("gaugecount", 0).toInt();
+ QString name = settings.value("name").toString();
+ for(int gn=0;gn<gc;gn++) {
+ settings.beginGroup("gauge-" + QString::number(gn));
+ PanelItem *g = itemFactory->itemForName(settings.value("type").toString(), parentWidget);
+ if(g) {
+ emit itemAdded(g);
+ g->loadSettings(settings);
+ } else {
+ qDebug() << Q_FUNC_INFO << "Can't load item of type " << settings.value("type").toString();
+ }
+ settings.endGroup();
+ }
+ panelNumber++;
+ } else {
+ panelNumber = -1;
+ }
+ settings.endGroup();
+ }
+
+ closeDialog(); */
+}
+
void MenuButton::showSettings() {
closeDialog();
View
1 menubutton.h
@@ -37,6 +37,7 @@ public slots:
void closeDialog();
void savePanel();
void loadPanel();
+ void exportPanel(void);
void showSettings();
void quit();
void itemProperties();

0 comments on commit 04b116d

Please sign in to comment.
Something went wrong with that request. Please try again.