Skip to content

Commit

Permalink
save left panel state (#36)
Browse files Browse the repository at this point in the history
Close #35
  • Loading branch information
RPG-18 authored Jan 2, 2022
1 parent abd8c9d commit 46ce326
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ add_library(components
ErrorWrap.cpp ErrorWrap.h
Producer.cpp Producer.h
ProtoOption.cpp ProtoOption.h
Helpers.cpp Helpers.h)
Helpers.cpp Helpers.h
Settings.cpp Settings.h)

target_compile_definitions(components
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
Expand Down
2 changes: 2 additions & 0 deletions src/components/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "KafkaConnectivityTester.h"
#include "Producer.h"
#include "ProtoOption.h"
#include "Settings.h"
#include "TopicCreator.h"

void registerTypes()
Expand All @@ -23,6 +24,7 @@ void registerTypes()
qmlRegisterType<ConsumerFilterSelector>("plumber", 1, 0, "ConsumerFilterSelector");
qmlRegisterType<ConsumerBeginningSelector>("plumber", 1, 0, "ConsumerBeginningSelector");
qmlRegisterType<TopicCreator>("plumber", 1, 0, "TopicCreator");
qmlRegisterType<Settings>("plumber", 1, 0, "Settings");

qmlRegisterType<Producer>("plumber", 1, 0, "Producer");
qmlRegisterType<ProducerOptions>("plumber", 1, 0, "ProducerOptions");
Expand Down
29 changes: 29 additions & 0 deletions src/components/Settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <QtCore/QSettings>

#include "Settings.h"

Settings::Settings(QObject *parent)
: QObject(parent)
, m_settings(new QSettings(QSettings::UserScope, this))
{}

Settings::~Settings()
{
m_settings->sync();
}

QString Settings::leftPanelState()
{
m_settings->beginGroup("left_panel");
const auto state = m_settings->value("state", "default");
m_settings->endGroup();
return state.toString();
}

void Settings::setLeftPanelState(const QString &value)
{
m_settings->beginGroup("left_panel");
m_settings->setValue("state", value);
m_settings->endGroup();
emit leftPanelStateChanged();
}
26 changes: 26 additions & 0 deletions src/components/Settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <QtCore/QObject>

class QSettings;

class Settings : public QObject
{
Q_OBJECT

public:
Q_PROPERTY(QString leftPanelState READ leftPanelState WRITE setLeftPanelState NOTIFY
leftPanelStateChanged)
Settings(QObject *parent = nullptr);
~Settings();

QString leftPanelState();
void setLeftPanelState(const QString &value);

signals:

void leftPanelStateChanged();

private:
QSettings *m_settings;
};
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int main(int argc, char *argv[])

kafka::clients::KafkaClient::setGlobalLogger(KafkaSpdLogger);
QCoreApplication::setApplicationName("plumber");
QCoreApplication::setOrganizationName("plumber");

QApplication app(argc, argv);
init();
Expand Down
4 changes: 2 additions & 2 deletions src/plumber_ru_RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,12 @@
<context>
<name>Panel</name>
<message>
<location filename="qml/LeftPanel/Panel.qml" line="125"/>
<location filename="qml/LeftPanel/Panel.qml" line="126"/>
<source>&lt;&lt; Collapse</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="qml/LeftPanel/Panel.qml" line="147"/>
<location filename="qml/LeftPanel/Panel.qml" line="148"/>
<source>« Collapse</source>
<translation type="unfinished"></translation>
</message>
Expand Down
7 changes: 4 additions & 3 deletions src/qml/LeftPanel/Panel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Rectangle {
id: menu

property var broker
property var settings

signal activatedItem(int indx)

Expand All @@ -17,7 +18,7 @@ Rectangle {
height: 200
radius: 10
border.color: Style.BorderColor
state: "default"
state: settings.leftPanelState

Rectangle {
id: header
Expand Down Expand Up @@ -130,9 +131,9 @@ Rectangle {
anchors.fill: parent
onClicked: {
if (menu.state === "default")
menu.state = "small";
settings.leftPanelState = "small";
else
menu.state = "default";
settings.leftPanelState = "default";
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/qml/MainScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Rectangle {
broker: mainScreen.broker
}

Settings {
id: mainSettings
}

ColumnLayout {
anchors.fill: parent
anchors.margins: 4
Expand Down Expand Up @@ -49,6 +53,7 @@ Rectangle {
id: menu

broker: mainScreen.broker
settings: mainSettings
Layout.fillHeight: true
onActivatedItem: (indx) => {
stackLayout.currentIndex = indx;
Expand Down
1 change: 0 additions & 1 deletion src/services/ConfigurationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ bool ConfigurationService::save()
const auto path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
const QDir dir(path);
return m_cfg.saveToFile(dir.filePath(ConfigName));
;
}

void ConfigurationService::createDirs()
Expand Down

0 comments on commit 46ce326

Please sign in to comment.