Refactoring to use new entryprovider and settingsprovider classes
This commit is contained in:
rodzic
2824f84f9f
commit
45d7b930f8
@ -18,7 +18,7 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include "config.h"
|
||||
#include "entryprovider.h"
|
||||
class EntryPushButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -44,8 +44,8 @@ public:
|
||||
void setRow(int row);
|
||||
void setCol(int col);
|
||||
void setShortcutKey(QString key);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // ENTRYPUSHBUTTON_H
|
||||
|
12
main.cpp
12
main.cpp
@ -19,13 +19,12 @@
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
#include <QSettings>
|
||||
#include <QLocalSocket>
|
||||
#include "configprovider.h"
|
||||
#include <QDir>
|
||||
#include "settingsprovider.h"
|
||||
#include "entryprovider.h"
|
||||
#include "window.h"
|
||||
#include "singleinstanceserver.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
@ -58,7 +57,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
QSettings settings(configDirectoryPath + "qsrun.config", QSettings::NativeFormat);
|
||||
|
||||
ConfigProvider configProvider(configDirectoryPath, settings);
|
||||
SettingsProvider settingsProvider { settings };
|
||||
EntryProvider entryProvider(settingsProvider.userEntriesPaths(), settingsProvider.systemApplicationsEntriesPaths());
|
||||
//TODO if setting single instance mode
|
||||
QLocalSocket localSocket;
|
||||
localSocket.connectToServer("/tmp/qsrun.socket");
|
||||
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
qDebug() << "Failed to listen on socket!";
|
||||
}
|
||||
Window *w = new Window { configProvider };
|
||||
Window *w = new Window { entryProvider, settingsProvider };
|
||||
QObject::connect(&server, &SingleInstanceServer::receivedMaximizationRequest, [&w]{
|
||||
if(w != nullptr)
|
||||
{
|
||||
|
24
qsrun.pro
24
qsrun.pro
@ -7,19 +7,21 @@ TARGET = qsrun
|
||||
INCLUDEPATH += .
|
||||
|
||||
# Input
|
||||
HEADERS += config.h window.h \
|
||||
entrypushbutton.h \
|
||||
calculationengine.h \
|
||||
singleinstanceserver.h \
|
||||
configprovider.h
|
||||
SOURCES += config.cpp main.cpp window.cpp \
|
||||
entrypushbutton.cpp \
|
||||
calculationengine.cpp \
|
||||
singleinstanceserver.cpp \
|
||||
configprovider.cpp
|
||||
HEADERS += calculationengine.h \
|
||||
entryprovider.h \
|
||||
entrypushbutton.h \
|
||||
settingsprovider.h \
|
||||
singleinstanceserver.h \
|
||||
window.h
|
||||
SOURCES += calculationengine.cpp \
|
||||
entryprovider.cpp \
|
||||
entrypushbutton.cpp \
|
||||
main.cpp \
|
||||
settingsprovider.cpp \
|
||||
singleinstanceserver.cpp \
|
||||
window.cpp
|
||||
QT += widgets sql network
|
||||
QT_CONFIG -= no-pkg-config
|
||||
LIBS += -lcln
|
||||
CONFIG += link_pkgconfig
|
||||
PKGCONFIG += libqalculate
|
||||
|
||||
|
13
window.cpp
13
window.cpp
@ -28,10 +28,11 @@
|
||||
#include <QClipboard>
|
||||
#include <QScrollArea>
|
||||
#include "window.h"
|
||||
#include "configprovider.h"
|
||||
Window::Window(ConfigProvider &configProvider)
|
||||
#include "entryprovider.h"
|
||||
Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
|
||||
{
|
||||
this->configProvider = &configProvider;
|
||||
this->entryProvider = &entryProvider;
|
||||
this->settingsProvider = &configProvider;
|
||||
createGui();
|
||||
initFromConfig();
|
||||
this->lineEdit->installEventFilter(this);
|
||||
@ -55,8 +56,8 @@ void Window::initFromConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
this->userEntryButtons = generateEntryButtons(configProvider->getUserEntries());
|
||||
this->systemEntryButtons = generateEntryButtons(configProvider->getSystemEntries());
|
||||
this->userEntryButtons = generateEntryButtons(entryProvider->getUserEntries());
|
||||
this->systemEntryButtons = generateEntryButtons(entryProvider->getSystemEntries());
|
||||
}
|
||||
catch(const ConfigFormatException &e)
|
||||
{
|
||||
@ -124,7 +125,7 @@ void Window::buttonClick(const EntryPushButton &config)
|
||||
|
||||
void Window::closeWindow()
|
||||
{
|
||||
if(configProvider->singleInstanceMode())
|
||||
if(settingsProvider->singleInstanceMode())
|
||||
{
|
||||
this->lineEdit->setText("");
|
||||
hide();
|
||||
|
8
window.h
8
window.h
@ -30,16 +30,16 @@
|
||||
#include <QThread>
|
||||
#include <QTreeWidget>
|
||||
#include <QLabel>
|
||||
#include "config.h"
|
||||
#include "entrypushbutton.h"
|
||||
#include "calculationengine.h"
|
||||
#include "configprovider.h"
|
||||
#include "settingsprovider.h"
|
||||
|
||||
class Window : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
ConfigProvider *configProvider;
|
||||
EntryProvider *entryProvider;
|
||||
SettingsProvider *settingsProvider;
|
||||
CalculationEngine calcEngine;
|
||||
QString calculationresult;
|
||||
QVector<EntryPushButton*> userEntryButtons;
|
||||
@ -71,7 +71,7 @@ private slots:
|
||||
void lineEditReturnPressed();
|
||||
void showCalculationResultContextMenu(const QPoint &point);
|
||||
public:
|
||||
Window(ConfigProvider &configProvider);
|
||||
Window(EntryProvider &entryProvider, SettingsProvider &settingsProvider);
|
||||
void setSystemConfig(const QVector<EntryConfig> &config);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
void focusInput();
|
||||
|
Ładowanie…
Reference in New Issue
Block a user