Embedded unique pointer for QSettings

main
Isabell Pflug 2 years ago
parent 46dcdfe617
commit 5cea33941b

@ -6,20 +6,25 @@
#include <QSettings> #include <QSettings>
#include <QStandardPaths> #include <QStandardPaths>
// dieser unique Pointer ist absolut genial, weil er mir erlaubt, die User-spezifischen Einstellungen zu Farben und Grid-Größe
// an das Mainwindow weiter zu reichen, noch *bevor* das Mainwindow überhaupt initialisiert ist!
std::unique_ptr<QSettings> settings; std::unique_ptr<QSettings> settings;
void find_config() { // funktioniert komplett plattformunabhängig!
// sogar auf Android, wenn man wahnsinnig sein sollte!
void initialise_settings() {
QString config_string = QStandardPaths::locate( QStandardPaths::ConfigLocation, "ThinkPink.ini"); QString config_string = QStandardPaths::locate( QStandardPaths::ConfigLocation, "ThinkPink.ini");
if (config_string == "") { if (config_string == "") {
config_string = QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).filePath("ThinkPink.ini"); config_string = QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).filePath("ThinkPink.ini");
std::cout << "No config file found. Creating default config at " << config_string.toStdString(); std::cout << "No config file found. Creating default config at " << config_string.toStdString() << std::endl;
} }
settings.reset( new QSettings( ) ); settings.reset( new QSettings( config_string, QSettings::IniFormat ) );
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
initialise_settings();
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
w.show(); w.show();

@ -1,8 +1,8 @@
#include <boost/json.hpp>
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
extern std::unique_ptr<QSettings> settings;
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)

@ -2,6 +2,7 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <QSettings>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }

@ -3,5 +3,5 @@ columns = 9
rows = 9 rows = 9
[colors] [colors]
colors = 0xBD005E, 0xFFC0CB, 0xDB7093, 0xF7A8B8 colors = 0xBD005E, 0xFFC0CB, 0xDB7093, 0xF7A8B8, 0x660033
;, 0xDB7093 ;, 0xDB7093

Loading…
Cancel
Save