Skip to content

Commit

Permalink
WPandaSettings: Remove mainwindow dependence
Browse files Browse the repository at this point in the history
The WPandaSetting is static now.
  • Loading branch information
Carlos Alves committed Feb 15, 2021
1 parent f69e262 commit 9efcc78
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 46 deletions.
13 changes: 6 additions & 7 deletions app/bewaveddolphin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include "ui_bewaveddolphin.h"
#include "WPandaSettings.h"
#include "mainwindow.h"

SignalModel::SignalModel(int rows, int inputs, int columns, QObject *parent)
: QStandardItemModel(rows, columns, parent)
Expand Down Expand Up @@ -79,9 +78,9 @@ BewavedDolphin::BewavedDolphin(Editor *editor, QWidget *parent)
setWindowTitle("Bewaved Dolphin Simulator");
setWindowFlags(Qt::Window);

if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
restoreGeometry(GlobalProperties::settingToByteArray(mainwindow->settings()->bdGeometry()));
}
// TODO: remove geometry from settings save
auto settings = WPandaSettings::self();
restoreGeometry(GlobalProperties::settingToByteArray(settings->bdGeometry()));

m_gv = new GraphicsView(this);
m_ui->verticalLayout->addWidget(m_gv);
Expand All @@ -104,9 +103,9 @@ BewavedDolphin::BewavedDolphin(Editor *editor, QWidget *parent)

BewavedDolphin::~BewavedDolphin()
{
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
mainwindow->settings()->setBdGeometry(GlobalProperties::settingToIntList(saveGeometry()));
}
// TODO: remove geometry from settings save
auto settings = WPandaSettings::self();
settings->setBdGeometry(GlobalProperties::settingToIntList(saveGeometry()));

delete m_ui;
}
Expand Down
8 changes: 4 additions & 4 deletions app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ MainWindow::MainWindow(QWidget *parent, const QString &filename)
, m_dolphinFilename("none")
, m_bd(nullptr)
, m_translator(nullptr)
, m_settings(new WPandaSettings)
, m_settings(WPandaSettings::self())
{
COMMENT("WIRED PANDA Version = " << APP_VERSION << " OR " << GlobalProperties::version, 0);
m_ui->setupUi(this);
Expand Down Expand Up @@ -190,7 +190,7 @@ MainWindow::~MainWindow()
m_settings->save();

delete m_ui;
}
}

void MainWindow::on_actionExit_triggered()
{
Expand Down Expand Up @@ -1030,13 +1030,13 @@ void MainWindow::on_actionSave_Local_Project_triggered()
bool dir_res = QDir().mkpath(path + "/boxes");
if (!dir_res) {
std::cerr << tr("Error creating ICs directory.").toStdString() << std::endl;
}
}
}
if (!QDir(path + "/skins").exists()) {
bool dir_res = QDir().mkpath(path + "/skins");
if (!dir_res) {
std::cerr << tr("Error creating skins directory.").toStdString() << std::endl;
}
}
}
COMMENT("Saving ics and skins to local directories.", 0);
if (!m_editor->saveLocal(path)) {
Expand Down
2 changes: 0 additions & 2 deletions app/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ class MainWindow : public QMainWindow
QString getDolphinFilename();
void setDolphinFilename(const QString &filename);

WPandaSettings *settings();

signals:
void addRecentIcFile(const QString &fname);
void addRecentFile(const QString &fname);
Expand Down
11 changes: 4 additions & 7 deletions app/recentfilescontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@

#include "common.h"
#include "WPandaSettings.h"
#include "mainwindow.h"

RecentFilesController::RecentFilesController(QObject *parent, bool saveSetting)
: QObject(parent)
, m_saveSetting(saveSetting)
{
if (m_saveSetting) {
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
m_files = mainwindow->settings()->recentFileList();
}
auto settings = WPandaSettings::self();
m_files = settings->recentFileList();
}
}

Expand Down Expand Up @@ -60,8 +58,7 @@ QStringList RecentFilesController::getRecentFiles()
void RecentFilesController::saveRecentFiles()
{
if (m_saveSetting) {
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
mainwindow->settings()->setRecentFileList(m_files);
}
auto settings = WPandaSettings::self();
settings->setRecentFileList(m_files);
}
}
1 change: 1 addition & 0 deletions app/settings/WPandaSettings.kcfgc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Mutators=true
DefaultValueGetters=true
MemberVariables=private
GlobalEnums=true
Singleton=true
34 changes: 15 additions & 19 deletions app/simplewaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "input.h"
#include "WPandaSettings.h"
#include "mainwindow.h"

using namespace QtCharts;

Expand All @@ -47,16 +46,17 @@ SimpleWaveform::SimpleWaveform(Editor *editor, QWidget *parent)
setModal(true);
m_sortingMode = SortingMode::INCREASING;

if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
restoreGeometry(GlobalProperties::settingToByteArray(mainwindow->settings()->swGeometry()));
}
// TODO: Remove save geometry
auto settings = WPandaSettings::self();
restoreGeometry(GlobalProperties::settingToByteArray(settings->swGeometry()));
}

SimpleWaveform::~SimpleWaveform()
{
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
mainwindow->settings()->setSwGeometry(GlobalProperties::settingToIntList(saveGeometry()));
}
// TODO: Remove save geometry
auto settings = WPandaSettings::self();
settings->setSwGeometry(GlobalProperties::settingToIntList(saveGeometry()));

delete m_ui;
}

Expand Down Expand Up @@ -200,9 +200,8 @@ bool SimpleWaveform::saveToTxt(QTextStream &outStream, Editor *editor)
// por linha de comando, o resultado poderia ser salvo em arquivo.
void SimpleWaveform::showWaveform()
{
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
m_sortingMode = static_cast<SortingMode>(mainwindow->settings()->sortingType());
}
auto settings = WPandaSettings::self();
m_sortingMode = static_cast<SortingMode>(settings->sortingType());

switch (m_sortingMode) {
case SortingMode::DECREASING:
Expand Down Expand Up @@ -363,27 +362,24 @@ void SimpleWaveform::showWaveform()
void SimpleWaveform::on_radioButton_Position_clicked()
{
m_sortingMode = SortingMode::POSITION;
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
mainwindow->settings()->setSortingType(static_cast<int>(m_sortingMode));
}
auto settings = WPandaSettings::self();
settings->setSortingType(static_cast<int>(m_sortingMode));
showWaveform();
}

void SimpleWaveform::on_radioButton_Increasing_clicked()
{
m_sortingMode = SortingMode::INCREASING;
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
mainwindow->settings()->setSortingType(static_cast<int>(m_sortingMode));
}
auto settings = WPandaSettings::self();
settings->setSortingType(static_cast<int>(m_sortingMode));
showWaveform();
}

void SimpleWaveform::on_radioButton_Decreasing_clicked()
{
m_sortingMode = SortingMode::DECREASING;
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
mainwindow->settings()->setSortingType(static_cast<int>(m_sortingMode));
}
auto settings = WPandaSettings::self();
settings->setSortingType(static_cast<int>(m_sortingMode));
showWaveform();
}

Expand Down
11 changes: 4 additions & 7 deletions app/thememanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "thememanager.h"
#include "WPandaSettings.h"
#include "mainwindow.h"

#include <QApplication>

Expand All @@ -19,9 +18,8 @@ void ThemeManager::setTheme(const Theme &theme)
m_attrs.setTheme(theme);
if (m_theme != theme) {
m_theme = theme;
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
mainwindow->settings()->setTheme(static_cast<int>(theme));
}
auto settings = WPandaSettings::self();
settings->setTheme(static_cast<int>(theme));
emit themeChanged();
}
}
Expand All @@ -40,9 +38,8 @@ ThemeManager::ThemeManager(QObject *parent)
: QObject(parent)
, m_theme(Theme::Panda_Light)
{
if (auto mainwindow = qobject_cast<MainWindow *>(this->parent())) {
m_theme = static_cast<Theme>(mainwindow->settings()->theme());
}
auto settings = WPandaSettings::self();
m_theme = static_cast<Theme>(settings->theme());
setTheme(m_theme);
}

Expand Down

0 comments on commit 9efcc78

Please sign in to comment.