Browse Source

First draft of AStyle complete. Plugged a logbookwidget leak.

Astyle works however repeatedly changing themes yields inconsisten results. 
Avoid the bb themes they seem to crash the program for some reason.
George 4 years ago
parent
commit
23c7bd0770

+ 3 - 27
main.cpp

@@ -50,42 +50,18 @@ int main(int argc, char *argv[])
 
     ASettings::setup();
 
+    AStyle::setup();
+
     aDB()->connect();
     if (!ASettings::read(ASettings::Setup::SetupComplete).toBool()) {
-        FirstRunDialog dialog;
-        if(dialog.exec() == QDialog::Rejected){
+        if(FirstRunDialog().exec() == QDialog::Rejected){
             DEB "First run not accepted. Exiting.";
             return 1;
         }
         ASettings::write(ASettings::Setup::SetupComplete, true);
         DEB << "Wrote setup_commplete?";
-//        qApp->quit();
-//        QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
     }
 
-    AStyle::setup();
-    //Theming
-//    switch (ASettings::read(ASettings::Main::Theme).toInt()) {
-//    case 1:{
-//        DEB << "main :: Loading light theme";
-//        QFile file(":light.qss");
-//        file.open(QFile::ReadOnly | QFile::Text);
-//        QTextStream stream(&file);
-//        openPilotLog.setStyleSheet(stream.readAll());
-//        break;
-//    }
-//    case 2:{
-//        DEB << "Loading dark theme";
-//        QFile file(":dark.qss");
-//        file.open(QFile::ReadOnly | QFile::Text);
-//        QTextStream stream(&file);
-//        openPilotLog.setStyleSheet(stream.readAll());
-//        break;
-//    }
-//    default:
-//        break;
-//    }
-
     //sqlite does not deal well with multiple connections, ensure only one instance is running
     ARunGuard guard(QStringLiteral("opl_single_key"));
         if ( !guard.tryToRun() ){

+ 18 - 3
src/astyle.cpp

@@ -3,20 +3,35 @@
 #include <QStyleFactory>
 #include <QApplication>
 #include "src/testing/adebug.h"
+#include "src/classes/asettings.h"
+
+const QStringList AStyle::styles = QStyleFactory::keys();
+const QString AStyle::defaultStyle = QStringLiteral("kvantum-dark");
+QString AStyle::currentStyle;
 
 // [G]: Kvantum crashes
 // Are there leaks when style changes?
 void AStyle::setup()
 {
-    QApplication::setStyle(QStyleFactory::create("Windows"));
+    QVariant app_style = ASettings::read(ASettings::Main::Theme);
+    if(!app_style.toBool()){
+        DEB << "Setting style to default:" << defaultStyle;
+        app_style = defaultStyle;
+        ASettings::write(ASettings::Main::Theme, app_style);
+    }
+    DEB << "Style set to:" << app_style;
+    QApplication::setStyle(QStyleFactory::create(app_style.toString()));
+    currentStyle = app_style.toString();
 }
 
 void AStyle::setStyle(const QString& style)
 {
+    DEB << "Setting style to:" << style;
     QApplication::setStyle(QStyleFactory::create(style));
+    ASettings::write(ASettings::Main::Theme, style);
 }
 
-void AStyle::setStyleSheet(const QString &qss_file)
+const QString& AStyle::style()
 {
-
+    return currentStyle;
 }

+ 6 - 1
src/astyle.h

@@ -5,10 +5,15 @@
 
 class AStyle
 {
+private:
+    static QString currentStyle;
 public:
+    static const QStringList styles;
+    static const QString defaultStyle;
+
     static void setup();
     static void setStyle(const QString& style);
-    static void setStyleSheet(const QString& qss_file);
+    static const QString& style();
 };
 
 #endif // ASTYLE_H

+ 10 - 10
src/gui/dialogues/firstrundialog.cpp

@@ -19,13 +19,13 @@ FirstRunDialog::FirstRunDialog(QWidget *parent) :
     ui->previousPushButton->setEnabled(false);
     ui->nightComboBox->setCurrentIndex(1);
 
-    auto *themeGroup = new QButtonGroup;
-    themeGroup->addButton(ui->systemThemeCheckBox, 0);
-    themeGroup->addButton(ui->lightThemeCheckBox, 1);
-    themeGroup->addButton(ui->darkThemeCheckBox, 2);
+//    auto *themeGroup = new QButtonGroup;
+//    themeGroup->addButton(ui->systemThemeCheckBox, 0);
+//    themeGroup->addButton(ui->lightThemeCheckBox, 1);
+//    themeGroup->addButton(ui->darkThemeCheckBox, 2);
 
-    QObject::connect(themeGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
-                     this, &FirstRunDialog::on_themeGroup_toggled);
+//    QObject::connect(themeGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
+//                     this, &FirstRunDialog::on_themeGroup_toggled);
 }
 
 FirstRunDialog::~FirstRunDialog()
@@ -79,10 +79,10 @@ void FirstRunDialog::on_nextPushButton_clicked()
     ui->stackedWidget->setCurrentIndex(current_idx + 1);
 }
 
-void FirstRunDialog::on_themeGroup_toggled(int id)
-{
-    ASettings::write(ASettings::Main::Theme, id);
-}
+//void FirstRunDialog::on_themeGroup_toggled(int id)
+//{
+//    ASettings::write(ASettings::Main::Theme, id);
+//}
 
 bool FirstRunDialog::finish()
 {

+ 1 - 1
src/gui/dialogues/firstrundialog.h

@@ -24,7 +24,7 @@ private slots:
 
     void on_nextPushButton_clicked();
 
-    void on_themeGroup_toggled(int id);
+//    void on_themeGroup_toggled(int id);
 
 private:
     Ui::FirstRunDialog *ui;

+ 0 - 34
src/gui/dialogues/firstrundialog.ui

@@ -394,20 +394,6 @@
      </widget>
      <widget class="QWidget" name="stackedWidgetPage3">
       <layout class="QGridLayout" name="gridLayout_4">
-       <item row="2" column="1">
-        <widget class="QCheckBox" name="lightThemeCheckBox">
-         <property name="text">
-          <string>Light Theme</string>
-         </property>
-        </widget>
-       </item>
-       <item row="3" column="1">
-        <widget class="QCheckBox" name="darkThemeCheckBox">
-         <property name="text">
-          <string>Dark Theme</string>
-         </property>
-        </widget>
-       </item>
        <item row="0" column="0" colspan="2">
         <widget class="QLabel" name="label_4">
          <property name="text">
@@ -421,23 +407,6 @@
          </property>
         </widget>
        </item>
-       <item row="1" column="0">
-        <widget class="QLabel" name="themeLabel">
-         <property name="text">
-          <string>Theme</string>
-         </property>
-        </widget>
-       </item>
-       <item row="1" column="1">
-        <widget class="QCheckBox" name="systemThemeCheckBox">
-         <property name="text">
-          <string>System Theme</string>
-         </property>
-         <property name="checked">
-          <bool>true</bool>
-         </property>
-        </widget>
-       </item>
       </layout>
      </widget>
     </widget>
@@ -458,9 +427,6 @@
   <tabstop>approachComboBox</tabstop>
   <tabstop>nightComboBox</tabstop>
   <tabstop>prefixLineEdit</tabstop>
-  <tabstop>systemThemeCheckBox</tabstop>
-  <tabstop>lightThemeCheckBox</tabstop>
-  <tabstop>darkThemeCheckBox</tabstop>
   <tabstop>stackedWidget</tabstop>
  </tabstops>
  <resources/>

+ 1 - 0
src/gui/widgets/logbookwidget.cpp

@@ -54,6 +54,7 @@ LogbookWidget::LogbookWidget(QWidget *parent) :
 
 LogbookWidget::~LogbookWidget()
 {
+    delete displayModel;  // [G]: previously leaked from logbookwidget.cpp:89
     delete ui;
 }
 

+ 8 - 44
src/gui/widgets/settingswidget.cpp

@@ -53,19 +53,17 @@ SettingsWidget::SettingsWidget(QWidget *parent) :
     ui->setupUi(this);
     ui->tabWidget->setCurrentIndex(0);
 
-    auto *themeGroup = new QButtonGroup;
-    themeGroup->addButton(ui->systemThemeCheckBox, 0);
-    themeGroup->addButton(ui->lightThemeCheckBox, 1);
-    themeGroup->addButton(ui->darkThemeCheckBox, 2);
+    auto styles = AStyle::styles;
+    auto current_style = AStyle::style();
+    ui->styleComboBox->addItem(current_style);
+    styles.removeOne(current_style);
 
-    for(auto & x : QStyleFactory::keys())
-        ui->styleComboBox->addItem(x);
+    ui->styleComboBox->addItems(styles);
+    ui->styleComboBox->model()->sort(0);
+    ui->styleComboBox->setCurrentText(current_style);
 
     readSettings();
     setupValidators();
-
-    QObject::connect(themeGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
-                     this, &SettingsWidget::onThemeGroup_buttonClicked);
 }
 
 void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& text)
@@ -100,19 +98,6 @@ void SettingsWidget::readSettings()
     ui->nightComboBox->setCurrentIndex(ASettings::read(ASettings::FlightLogging::NightLogging).toInt());
     ui->prefixLineEdit->setText(ASettings::read(ASettings::FlightLogging::FlightNumberPrefix).toString());
 
-    /*
-     * Misc Tab
-     */
-    switch (ASettings::read(ASettings::Main::Theme).toInt()) {
-    case 0:
-        ui->systemThemeCheckBox->setChecked(true);
-        break;
-    case 1:
-        ui->lightThemeCheckBox->setChecked(true);
-        break;
-    case 2:
-        ui->darkThemeCheckBox->setChecked(true);
-    }
     ui->logbookViewComboBox->setCurrentIndex(ASettings::read(ASettings::LogBook::View).toInt());
     /*
      * Aircraft Tab
@@ -276,28 +261,7 @@ void SettingsWidget::on_prefixLineEdit_textChanged(const QString &arg1)
 /*
  * Misc Tab
  */
-void SettingsWidget::onThemeGroup_buttonClicked(int theme_id)
-{
-    ASettings::write(ASettings::Main::Theme, theme_id);
-    switch (ASettings::read(ASettings::Main::Theme).toInt()) {
-    case 1:{
-        DEB << "main :: Loading light theme";
-        QFile file(":light.qss");
-        file.open(QFile::ReadOnly | QFile::Text);
-        QTextStream stream(&file);
-        qApp->setStyleSheet(stream.readAll());
-        break;
-    }
-    case 2:{
-        DEB << "Loading dark theme";
-        QFile file(":dark.qss");
-        file.open(QFile::ReadOnly | QFile::Text);
-        QTextStream stream(&file);
-        qApp->setStyleSheet(stream.readAll());
-        break;
-    }
-    }
-}
+
 void SettingsWidget::on_logbookViewComboBox_currentIndexChanged(int index)
 {
     ASettings::write(ASettings::LogBook::View, index);

+ 1 - 1
src/gui/widgets/settingswidget.h

@@ -39,7 +39,7 @@ public:
 
 private slots:
 
-    void onThemeGroup_buttonClicked(int theme_id);
+//    void onThemeGroup_buttonClicked(int theme_id);
     void on_aboutPushButton_clicked();
     void on_acSortComboBox_currentIndexChanged(int index);
     void on_acAllowIncompleteComboBox_currentIndexChanged(int index);

+ 69 - 115
src/gui/widgets/settingswidget.ui

@@ -468,7 +468,7 @@
        <string>Misc</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_5">
-       <item row="3" column="1">
+       <item row="2" column="1">
         <widget class="QLabel" name="pilotSortLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@@ -487,42 +487,49 @@
          </property>
         </widget>
        </item>
-       <item row="5" column="1">
-        <widget class="QLabel" name="acAllowIncompleteLabel">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
+       <item row="4" column="2">
+        <widget class="QComboBox" name="acAllowIncompleteComboBox">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines whether incomplete database entries are permitted. It is highly recommended to keep this option off.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
-         <property name="text">
-          <string>Allow incomplete Entries </string>
-         </property>
+         <item>
+          <property name="text">
+           <string>No</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Yes</string>
+          </property>
+         </item>
         </widget>
        </item>
-       <item row="6" column="1">
-        <widget class="QLabel" name="logbookViewLabel">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
+       <item row="3" column="2">
+        <widget class="QComboBox" name="acSortComboBox">
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="whatsThis">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="text">
-          <string>Logbook Dispay</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
+         <item>
+          <property name="text">
+           <string>Registration</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Type</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Company</string>
+          </property>
+         </item>
         </widget>
        </item>
-       <item row="4" column="1">
+       <item row="0" column="2">
+        <widget class="QComboBox" name="styleComboBox"/>
+       </item>
+       <item row="3" column="1">
         <widget class="QLabel" name="acSortLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@@ -541,8 +548,25 @@
          </property>
         </widget>
        </item>
-       <item row="0" column="1">
-        <widget class="QLabel" name="themeLabel">
+       <item row="5" column="2">
+        <widget class="QComboBox" name="logbookViewComboBox">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <item>
+          <property name="text">
+           <string>Default</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>EASA Part-FCL</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+       <item row="5" column="1">
+        <widget class="QLabel" name="logbookViewLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
            <horstretch>0</horstretch>
@@ -550,44 +574,17 @@
           </sizepolicy>
          </property>
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Changes the theme of the application.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="text">
-          <string>Theme</string>
-         </property>
-        </widget>
-       </item>
-       <item row="0" column="2">
-        <widget class="QCheckBox" name="systemThemeCheckBox">
-         <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Uses your default system theme.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="text">
-          <string>System</string>
-         </property>
-        </widget>
-       </item>
-       <item row="0" column="3">
-        <widget class="QCheckBox" name="lightThemeCheckBox">
-         <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Uses the Breeze light theme.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="text">
-          <string>Light</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
-        </widget>
-       </item>
-       <item row="0" column="4">
-        <widget class="QCheckBox" name="darkThemeCheckBox">
-         <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Uses the breeze dark theme (night mode)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         <property name="whatsThis">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="text">
-          <string>Dark</string>
+          <string>Logbook Dispay</string>
          </property>
         </widget>
        </item>
-       <item row="1" column="1">
+       <item row="0" column="1">
         <widget class="QLabel" name="styleLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@@ -600,10 +597,7 @@
          </property>
         </widget>
        </item>
-       <item row="1" column="2">
-        <widget class="QComboBox" name="styleComboBox"/>
-       </item>
-       <item row="3" column="2">
+       <item row="2" column="2">
         <widget class="QComboBox" name="pilotSortComboBox">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Pilots in the Pilots Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@@ -625,60 +619,20 @@
          </item>
         </widget>
        </item>
-       <item row="4" column="2">
-        <widget class="QComboBox" name="acSortComboBox">
-         <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+       <item row="4" column="1">
+        <widget class="QLabel" name="acAllowIncompleteLabel">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
          </property>
-         <item>
-          <property name="text">
-           <string>Registration</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>Type</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>Company</string>
-          </property>
-         </item>
-        </widget>
-       </item>
-       <item row="5" column="2">
-        <widget class="QComboBox" name="acAllowIncompleteComboBox">
          <property name="toolTip">
           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines whether incomplete database entries are permitted. It is highly recommended to keep this option off.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
-         <item>
-          <property name="text">
-           <string>No</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>Yes</string>
-          </property>
-         </item>
-        </widget>
-       </item>
-       <item row="6" column="2">
-        <widget class="QComboBox" name="logbookViewComboBox">
-         <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         <property name="text">
+          <string>Allow incomplete Entries </string>
          </property>
-         <item>
-          <property name="text">
-           <string>Default</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>EASA Part-FCL</string>
-          </property>
-         </item>
         </widget>
        </item>
       </layout>