comparison src/main.cpp @ 139:d5d1549e47fb

Change how settings are restored and saved.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 Aug 2017 12:12:21 +0300
parents 5e6bcabfa380
children 783417da6da3
comparison
equal deleted inserted replaced
138:5e6bcabfa380 139:d5d1549e47fb
22 // 22 //
23 // Application settings struct 23 // Application settings struct
24 // 24 //
25 struct 25 struct
26 { 26 {
27 QPoint uiPos;
28 QSize uiSize;
27 double uiScale; // Global UI scale factor 29 double uiScale; // Global UI scale factor
30
28 QString dataPath; // Application data path/directory 31 QString dataPath; // Application data path/directory
32 QString dbBackupURL;
33 QString dbBackupSecret;
29 } settings; 34 } settings;
30 35
31 36
32 37
33 // 38 //
233 238
234 239
235 int main(int argc, char *argv[]) 240 int main(int argc, char *argv[])
236 { 241 {
237 QApplication sapp(argc, argv); 242 QApplication sapp(argc, argv);
243 QSettings tmpst(APP_VENDOR, APP_ID);
244
245 // Read configuration settings
246 settings.uiPos = tmpst.value("pos", QPoint(100, 100)).toPoint();
247 settings.uiSize = tmpst.value("size", QSize(1000, 600)).toSize();
248 settings.uiScale = tmpst.value("scale", 1.0f).toDouble();
249 settings.dbBackupURL = tmpst.value("dbBackupURL", "").toString();
250 settings.dbBackupSecret = tmpst.value("dbBackupSecret", "").toString();
238 251
239 // 252 //
240 // Create logfile and data directory 253 // Create logfile and data directory
241 // 254 //
242 settings.dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); 255 settings.dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
304 QMainWindow(parent), 317 QMainWindow(parent),
305 ui(new Ui::SyntilistaMainWindow) 318 ui(new Ui::SyntilistaMainWindow)
306 { 319 {
307 // Setup UI 320 // Setup UI
308 ui->setupUi(this); 321 ui->setupUi(this);
309 322 backupDialog = NULL;
310 // Read config 323
311 readSettings(); 324 // Restore window size and position
325 move(settings.uiPos);
326 resize(settings.uiSize);
312 327
313 // Setup application icon and window title 328 // Setup application icon and window title
314 setWindowIcon(QIcon(QPixmap(":/img/icon-64.png"))); 329 setWindowIcon(QIcon(QPixmap(":/img/icon-64.png")));
315 setWindowTitle(tr("%1 versio %3"). 330 setWindowTitle(tr("%1 versio %3").
316 arg(tr(APP_NAME)). 331 arg(tr(APP_NAME)).
395 // 410 //
396 // Application main window destructor 411 // Application main window destructor
397 // 412 //
398 SyntilistaMainWindow::~SyntilistaMainWindow() 413 SyntilistaMainWindow::~SyntilistaMainWindow()
399 { 414 {
400 // Save current settings and free resources 415 QSettings tmpst(APP_VENDOR, APP_ID);
401 saveSettings(); 416
402 417 // Save window size and position
418 tmpst.setValue("pos", pos());
419 tmpst.setValue("size", size());
420
421 // Other settings
422 tmpst.setValue("scale", settings.uiScale);
423 tmpst.setValue("dbBackupURL", settings.dbBackupURL);
424 tmpst.setValue("dbBackupSecret", settings.dbBackupSecret);
425
426 // Free resources
403 delete ui; 427 delete ui;
404 delete model_People; 428 delete model_People;
405 delete model_Latest; 429 delete model_Latest;
406 430
407 // Commit and close database 431 // Commit and close database
415 // 439 //
416 void SyntilistaMainWindow::statusMsg(const QString &msg) 440 void SyntilistaMainWindow::statusMsg(const QString &msg)
417 { 441 {
418 slLog("STATUS", msg); 442 slLog("STATUS", msg);
419 ui->statusbar->showMessage(msg); 443 ui->statusbar->showMessage(msg);
420 }
421
422
423 //
424 // Restoring and saving of current settings
425 //
426 void SyntilistaMainWindow::readSettings()
427 {
428 QSettings tmpst(APP_VENDOR, APP_ID);
429
430 // Restore window size and position
431 move(tmpst.value("pos", QPoint(100, 100)).toPoint());
432 resize(tmpst.value("size", QSize(1000, 600)).toSize());
433
434 // Other settings
435 settings.uiScale = tmpst.value("scale", 1.0f).toDouble();
436 }
437
438
439 void SyntilistaMainWindow::saveSettings()
440 {
441 QSettings tmpst(APP_VENDOR, APP_ID);
442
443 // Save window size and position
444 tmpst.setValue("pos", pos());
445 tmpst.setValue("size", size());
446
447 // Other settings
448 tmpst.setValue("scale", settings.uiScale);
449 } 444 }
450 445
451 446
452 // 447 //
453 // Window scale / zoom changing 448 // Window scale / zoom changing