Skip to content

Commit a5dda45

Browse files
committed
Merge remote-tracking branch 'origin/dev'
2 parents 399f113 + 2daaf79 commit a5dda45

9 files changed

Lines changed: 124 additions & 12 deletions

File tree

omodsim/cmdlineparser.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "cmdlineparser.h"
2+
3+
///
4+
/// \brief CmdLineParser::CmdLineParser
5+
///
6+
CmdLineParser::CmdLineParser()
7+
{
8+
QCommandLineOption helpOption(QStringList() << _help, tr("Displays this help."));
9+
addOption(helpOption);
10+
11+
QCommandLineOption versionOption(QStringList() << _version, tr("Displays version information."));
12+
addOption(versionOption);
13+
14+
QCommandLineOption configOption(QStringList() << _config, tr("Setup test config file."), tr("file path"));
15+
addOption(configOption);
16+
}

omodsim/cmdlineparser.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef CMDLINEPARSER_H
2+
#define CMDLINEPARSER_H
3+
4+
#include <QCommandLineParser>
5+
6+
class CmdLineParser : public QCommandLineParser
7+
{
8+
public:
9+
explicit CmdLineParser();
10+
11+
public:
12+
static constexpr const char* _help = "help";
13+
static constexpr const char* _version = "version";
14+
static constexpr const char* _config = "config";
15+
};
16+
17+
#endif // CMDLINEPARSER_H

omodsim/dialogs/dialogabout.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
<item>
139139
<widget class="QLabel" name="labelCopyright">
140140
<property name="text">
141-
<string>© Alexandr Ananev, 2024</string>
141+
<string notr="true">© Alexandr Ananev, 2024</string>
142142
</property>
143143
</widget>
144144
</item>

omodsim/formmodsim.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ inline QDataStream& operator <<(QDataStream& out, FormModSim* frm)
246246

247247
const auto wnd = frm->parentWidget();
248248
out << wnd->isMaximized();
249-
out << ((wnd->isMinimized() || wnd->isMaximized()) ?
250-
wnd->sizeHint() : wnd->size());
249+
250+
const auto windowSize = (wnd->isMinimized() || wnd->isMaximized()) ? wnd->sizeHint() : wnd->size();
251+
out << windowSize;
251252

252253
out << frm->displayMode();
253254
out << frm->dataDisplayMode();
@@ -350,6 +351,7 @@ inline QDataStream& operator >>(QDataStream& in, FormModSim* frm)
350351
wnd->resize(windowSize);
351352
wnd->setWindowState(Qt::WindowActive);
352353
if(isMaximized) wnd->setWindowState(Qt::WindowMaximized);
354+
else wnd->resize(windowSize);
353355

354356
frm->setDisplayMode(displayMode);
355357
frm->setDataDisplayMode(dataDisplayMode);

omodsim/main.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
#include <QApplication>
22
#include <QFontDatabase>
33
#include "mainwindow.h"
4+
#include "cmdlineparser.h"
5+
6+
///
7+
/// \brief showVersion
8+
///
9+
static inline void showVersion()
10+
{
11+
const auto version = QString("%1\n").arg(APP_VERSION);
12+
fputs(qPrintable(version), stdout);
13+
}
14+
15+
///
16+
/// \brief showHelp
17+
/// \param helpText
18+
///
19+
static inline void showHelp(const QString& helpText)
20+
{
21+
fputs(qPrintable(helpText), stdout);
22+
}
23+
24+
///
25+
/// \brief showErrorMessage
26+
/// \param message
27+
///
28+
static void showErrorMessage(const QString &message)
29+
{
30+
fputs(qPrintable(message), stderr);
31+
}
432

533
///
634
/// \brief main
@@ -15,7 +43,36 @@ int main(int argc, char *argv[])
1543
a.setApplicationVersion(APP_VERSION);
1644
QFontDatabase::addApplicationFont(":/fonts/firacode.ttf");
1745

46+
CmdLineParser parser;
47+
if(!parser.parse(a.arguments()))
48+
{
49+
showErrorMessage(parser.errorText() + QLatin1Char('\n'));
50+
return EXIT_FAILURE;
51+
}
52+
53+
if(parser.isSet(CmdLineParser::_version))
54+
{
55+
showVersion();
56+
return EXIT_SUCCESS;
57+
}
58+
59+
if(parser.isSet(CmdLineParser::_help))
60+
{
61+
showHelp(parser.helpText());
62+
return EXIT_SUCCESS;
63+
}
64+
65+
QString cfg;
66+
if(parser.isSet(CmdLineParser::_config))
67+
{
68+
cfg = parser.value(CmdLineParser::_config);
69+
}
70+
1871
MainWindow w;
72+
if(!cfg.isEmpty())
73+
{
74+
w.loadConfig(cfg);
75+
}
1976
w.show();
2077

2178
return a.exec();

omodsim/mainwindow.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class MainWindow : public QMainWindow
2323

2424
void setLanguage(const QString& lang);
2525

26+
void loadConfig(const QString& filename);
27+
void saveConfig(const QString& filename);
28+
2629
signals:
2730
void undo();
2831
void redo();
@@ -148,9 +151,6 @@ private slots:
148151
FormModSim* loadMdiChild(const QString& filename);
149152
void saveMdiChild(FormModSim* frm);
150153

151-
void loadConfig(const QString& filename);
152-
void saveConfig(const QString& filename);
153-
154154
void loadSettings();
155155
void saveSettings();
156156

omodsim/omodsim.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CONFIG += c++17
44
CONFIG -= debug_and_release
55
CONFIG -= debug_and_release_target
66

7-
VERSION = 1.5.0
7+
VERSION = 1.5.1
88

99
QMAKE_TARGET_PRODUCT = "Open ModSim"
1010
QMAKE_TARGET_DESCRIPTION = "An Open Source Modbus Slave (Server) Utility"
@@ -25,6 +25,7 @@ INCLUDEPATH += controls \
2525
modbusmessages \
2626

2727
SOURCES += \
28+
cmdlineparser.cpp \
2829
controls/booleancombobox.cpp \
2930
controls/bytelisttextedit.cpp \
3031
controls/clickablelabel.cpp \
@@ -86,6 +87,7 @@ SOURCES += \
8687

8788
HEADERS += \
8889
byteorderutils.h \
90+
cmdlineparser.h \
8991
connectiondetails.h \
9092
controls/booleancombobox.h \
9193
controls/bytelisttextedit.h \

omodsim/translations/omodsim_ru.qm

328 Bytes
Binary file not shown.

omodsim/translations/omodsim_ru.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@
1414
<translation>Вкл</translation>
1515
</message>
1616
</context>
17+
<context>
18+
<name>CmdLineParser</name>
19+
<message>
20+
<location filename="../cmdlineparser.cpp" line="8"/>
21+
<source>Displays this help.</source>
22+
<translation>Пказать эту справку.</translation>
23+
</message>
24+
<message>
25+
<location filename="../cmdlineparser.cpp" line="11"/>
26+
<source>Displays version information.</source>
27+
<translation>Пказать информацию о версии.</translation>
28+
</message>
29+
<message>
30+
<location filename="../cmdlineparser.cpp" line="14"/>
31+
<source>Setup test config file.</source>
32+
<translation>Задать файл конфига.</translation>
33+
</message>
34+
<message>
35+
<location filename="../cmdlineparser.cpp" line="14"/>
36+
<source>file path</source>
37+
<translation>файл</translation>
38+
</message>
39+
</context>
1740
<context>
1841
<name>ConsoleOutput</name>
1942
<message>
@@ -49,11 +72,6 @@
4972
<source>An Open Source Modbus Slave (Server) Utility</source>
5073
<translation>Утилита Modbus Slave (сервер) с открытым исходным кодом</translation>
5174
</message>
52-
<message>
53-
<location filename="../dialogs/dialogabout.ui" line="141"/>
54-
<source>© Alexandr Ananev, 2023</source>
55-
<translation></translation>
56-
</message>
5775
<message>
5876
<location filename="../dialogs/dialogabout.ui" line="177"/>
5977
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;a href=&quot;&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Lecense: The MIT License&lt;span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</source>

0 commit comments

Comments
 (0)