From caa8a50b5c30d9c82e4e5db2d5e24ad5e55aab6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikko=20Syrj=C3=A4?= Date: Fri, 8 Mar 2019 22:33:56 +0200 Subject: Command line parameter improvements. --- help/eng/usage.rst | 16 ++++ help/fin/usage.rst | 16 ++++ locale/symedit.en_GB.ts | 198 ++++++++++++++++++++++++++++-------------------- locale/symedit.fi_FI.ts | 198 ++++++++++++++++++++++++++++-------------------- locale/symedit.ts | 42 ++++++++-- main.cpp | 45 +++++++++-- main.qml | 5 +- symedit.cpp | 33 +++++--- symedit.h | 10 ++- symedit.pro | 3 +- 10 files changed, 372 insertions(+), 194 deletions(-) diff --git a/help/eng/usage.rst b/help/eng/usage.rst index 20fe242..a20add5 100644 --- a/help/eng/usage.rst +++ b/help/eng/usage.rst @@ -8,6 +8,22 @@ Installation xxx +Command line +------------ + +Command line parameters:: + + Usage: ./symedit [options] file + + Options: + -t, --transfer Symbol file is transfer file. + -s, --symbol Read symbol data from parameter . + -l, --language Application language abbreviation . + -h, --help Displays this help. + + Arguments: + file Symbol file name. + Usage ----- diff --git a/help/fin/usage.rst b/help/fin/usage.rst index 68b42de..b323c25 100644 --- a/help/fin/usage.rst +++ b/help/fin/usage.rst @@ -8,6 +8,22 @@ Asennus xxx +Komentorivi +----------- + +Komentoriviparametrit:: + + Usage: ./symedit [options] file + + Options: + -t, --transfer Symbolitiedosto on siirtotiedosto. + -s, --symbol Lue symbolin data parametrista . + -l, --language Sovelluksen kielen lyhenne . + -h, --help Displays this help. + + Arguments: + file Symbolitiedoston nimi. + Käyttö ------ diff --git a/locale/symedit.en_GB.ts b/locale/symedit.en_GB.ts index eaa7a7d..b77be70 100644 --- a/locale/symedit.en_GB.ts +++ b/locale/symedit.en_GB.ts @@ -5,319 +5,351 @@ - Symbol Editor + Symbol Editor - File + File - Open... + Open... - Save... + Save... - Exit + Exit - Edit + Edit - Undo + Undo - Redo + Redo - Cut + Cut - Copy + Copy - Paste + Paste - Rotate Right + Rotate Right - Rotate Left + Rotate Left - Raise Item + Raise Item - Lower Item + Lower Item - Delete Item + Delete Item - View + View - Zoom In + Zoom In - Zoom Out + Zoom Out - Maximum + Maximum - Show Grid + Show Grid - Preview + Preview - Tool + Tool - Select + Select - Line + Line - Rectangle Corner + Rectangle Corner - Rectangle Center + Rectangle Center - Circle Corner + Circle Corner - Circle Radius + Circle Radius - Circle Center + Circle Center - Semicircle + Semicircle - Quarter Circle + Quarter Circle - Text + Text - Help + Help - Contents + Contents - About + About - Undo edit + Undo edit - Redo edit + Redo edit - Cut symbol + Cut symbol - Copy symbol + Copy symbol - Paste symbol + Paste symbol - Rotate right + Rotate right - Rotate left + Rotate left - Raise item + Raise item - Lower item + Lower item - Delete item + Delete item - - - Maximum zoom - - + - Preview symbol + Maximum zoom + + + + Preview symbol - Select item + Select item - Draw line + Draw line - Rectangle corner + Rectangle corner - Rectangle center + Rectangle center - Circle corner + Circle corner - Circle radius + Circle radius - Circle center + Circle center - Draw text + Draw text - Snap Grid + Snap Grid - Fill Item + Fill Item - 0 No fill + 0 No fill - 1 Background + 1 Background - 2 Fill area + 2 Fill area - Line Width + Line Width - Text Size + Text Size - Alignment + Alignment - 1 Top right + 1 Top right - 2 Top center + 2 Top center - 3 Top left + 3 Top left - 4 Base right + 4 Base right - 5 Base center + 5 Base center - 6 Base left + 6 Base left - 7 Bottom right + 7 Bottom right - 8 Bottom center + 8 Bottom center - 9 Bottom left + 9 Bottom left - 10 Middle right + 10 Middle right - 11 Middle center + 11 Middle center - 12 Middle left + 12 Middle left - Text + Text - About Program + About Program - Symbol editor for 3D-Win + Symbol editor for 3D-Win + + + + + + + + + + + + symbol + + + + Read symbol from parameter <symbol>. + + + + language + + + + Application language abbreviation <language>. + + + + Symbol file is transfer file. + + + + Symbol file name. diff --git a/locale/symedit.fi_FI.ts b/locale/symedit.fi_FI.ts index 23cd14d..6fc8a18 100644 --- a/locale/symedit.fi_FI.ts +++ b/locale/symedit.fi_FI.ts @@ -5,319 +5,351 @@ - Symbolieditori + Symbolieditori - Tiedosto + Tiedosto - Avaa... + Avaa... - Tallenna... + Tallenna... - Lopeta + Lopeta - Muokkaa + Muokkaa - Kumoa + Kumoa - Tee uudelleen + Tee uudelleen - Leikkaa + Leikkaa - Kopioi + Kopioi - Liitä + Liitä - Käännä oikealle + Käännä oikealle - Käännä vasemmalle + Käännä vasemmalle - Nosta kohdetta + Nosta kohdetta - Alenna kohdetta + Alenna kohdetta - Poista kohde + Poista kohde - Näytä + Näytä - Lähennä + Lähennä - Loitonna + Loitonna - Maksimi + Maksimi - Ruudukko + Ruudukko - Esikatselu + Esikatselu - Työkalut + Työkalut - Valitse + Valitse - Viiva + Viiva - Suorakulmio kulmista + Suorakulmio kulmista - Suorakulmio keskeltä + Suorakulmio keskeltä - Ympyrä kulmista + Ympyrä kulmista - Ympyrä halkaisija + Ympyrä halkaisija - Ympyrä keskeltä + Ympyrä keskeltä - Puoliympyrä + Puoliympyrä - Neljännesympyrä + Neljännesympyrä - Teksti + Teksti - Ohje + Ohje - Sisältö + Sisältö - Tietoja + Tietoja - Kumoa toiminto + Kumoa toiminto - Tee toiminto uudelleen + Tee toiminto uudelleen - Leikkaa symboli + Leikkaa symboli - Kopioi symboli + Kopioi symboli - Liitä symboli + Liitä symboli - Käännä oikealle + Käännä oikealle - Käännä vasemmalle + Käännä vasemmalle - Nosta kohdetta + Nosta kohdetta - Alenna kohdetta + Alenna kohdetta - Poista kohde + Poista kohde - - - Maksimizoomaus - - + - Symbolin esikatselu + Maksimizoomaus + + + + Symbolin esikatselu - Valitse kohde + Valitse kohde - Piirrä viiva + Piirrä viiva - Suorakulmio kulmista + Suorakulmio kulmista - Suorakulmio keskeltä + Suorakulmio keskeltä - Ympyrä kulmista + Ympyrä kulmista - Ympyrä halkasija + Ympyrä halkasija - Ympyrä keskeltä + Ympyrä keskeltä - Piirrä teksti + Piirrä teksti - Tartunta + Tartunta - Täyttö + Täyttö - 0 Ei täyttöä + 0 Ei täyttöä - 1 Taustaväri + 1 Taustaväri - 2 Alueen täyttö + 2 Alueen täyttö - Viivan leveys + Viivan leveys - Tekstin koko + Tekstin koko - Asemointi + Asemointi - 1 Ylhäällä oikealla + 1 Ylhäällä oikealla - 2 Ylhäällä keskellä + 2 Ylhäällä keskellä - 3 Ylhäällä vasemmalla + 3 Ylhäällä vasemmalla - 4 Alareunassa oikealla + 4 Alareunassa oikealla - 5 Alareunassa keskellä + 5 Alareunassa keskellä - 6 Alareunassa vasemmalla + 6 Alareunassa vasemmalla - 7 Alhaalla oikealla + 7 Alhaalla oikealla - 8 Alhaalla keskellä + 8 Alhaalla keskellä - 9 Alhaalla vasemmalla + 9 Alhaalla vasemmalla - 10 Puolivälissä oikealla + 10 Puolivälissä oikealla - 11 Puolivälissä keskellä + 11 Puolivälissä keskellä - 12 Puolivälissä vasemmalla + 12 Puolivälissä vasemmalla - Teksti + Teksti - Tietoja ohjelmasta + Tietoja ohjelmasta - 3D-Win symbolieditori + 3D-Win symbolieditori + + + + + + + + + + + + symboli + + + + Lue symboli parametrista <symboli>. + + + + kieli + + + + Sovelluksen kielen lyhenne <kieli>. + + + + Symbolitiedosto on siirtotiedosto. + + + + Symbolitiedoston nimi. diff --git a/locale/symedit.ts b/locale/symedit.ts index 0b9c513..bf67612 100644 --- a/locale/symedit.ts +++ b/locale/symedit.ts @@ -175,11 +175,11 @@ - - - - - + + + + + @@ -319,5 +319,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main.cpp b/main.cpp index 168bb98..b202026 100644 --- a/main.cpp +++ b/main.cpp @@ -17,29 +17,60 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); - // register enumerations - qmlRegisterUncreatableMetaObject(Operation::staticMetaObject, - "Org.Syrja.Symbol.Operation", 1, 0, "Operation", "Error: only enums" ); + // set base language translators + QLocale locale; + QTranslator backuptranslator, localetranslator, currenttranslator; + if ( backuptranslator.load(":/locale/symedit.en_GB.qm") ) + QCoreApplication::installTranslator(&backuptranslator); + if ( localetranslator.load(locale, ":/locale/symedit.") ) + QCoreApplication::installTranslator(&localetranslator); + // register command line arguments QCommandLineParser parser; + parser.addPositionalArgument("file", qtTrId("id_cli_symbol_file_name")); + QCommandLineOption transferoption(QStringList() << "t" << "transfer", qtTrId("id_cli_transfer_file")); + parser.addOption(transferoption); + QCommandLineOption symboloption(QStringList() << "s" << "symbol", + qtTrId("id_cli_symbol_description"), qtTrId("id_cli_symbol")); + parser.addOption(symboloption); + QCommandLineOption languageoption(QStringList() << "l" << "language", + qtTrId("id_cli_language_description"), qtTrId("id_cli_language")); + parser.addOption(languageoption); + parser.addHelpOption(); parser.process(app); - QString symbol; + // read command line arguments + QString filename; const QStringList arguments = parser.positionalArguments(); if ( arguments.size() ) - symbol = arguments.at(0); + filename = arguments.at(0); + bool transfer = parser.isSet(transferoption); + QString symbol = parser.value(symboloption); + QString language = parser.value(languageoption); + + // set current translator + if ( currenttranslator.load(language == "fin" ? ":/locale/symedit.fi_FI.qm" : "") ) + QCoreApplication::installTranslator(¤ttranslator); + + // register enumerations + qmlRegisterUncreatableMetaObject(Operation::staticMetaObject, + "Org.Syrja.Symbol.Operation", 1, 0, "Operation", "Error: only enums" ); // register manager - SymEditManager manager(symbol); QQmlApplicationEngine engine; + SymEditManager manager(filename, symbol); engine.rootContext()->setContextProperty("manager", &manager); + // start application engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if ( engine.rootObjects().isEmpty() ) return -1; - int result = app.exec(); + if ( transfer ) + { + //## save file + } manager.SaveSettings(); return result; diff --git a/main.qml b/main.qml index 69a4ab9..d702a70 100644 --- a/main.qml +++ b/main.qml @@ -327,12 +327,13 @@ ApplicationWindow function open() { - + manager.open(); + editor.update() } function save() { - + manager.save(); } function zoom(dir) diff --git a/symedit.cpp b/symedit.cpp index 7e636f4..da2d9ec 100644 --- a/symedit.cpp +++ b/symedit.cpp @@ -73,22 +73,23 @@ void SymEditSettings::Save() const SymEditManager::SymEditManager(QObject* parent) : QObject(parent) { Settings.Load(); - - QLocale locale; -// if ( BackupTranslator.load(":/locale/symedit.en_GB.qm") ) - if ( BackupTranslator.load(":/locale/symedit.fi_FI.qm") ) - QGuiApplication::installTranslator(&BackupTranslator); - if ( LocaleTranslator.load(locale, ":/locale/symedit.") ) - QGuiApplication::installTranslator(&LocaleTranslator); } //! Constructor. /*! + \param filename Symbol file name from command line. \param symbol Symbol string from command line. */ -SymEditManager::SymEditManager(const QString& symbol) : SymEditManager(nullptr) +SymEditManager::SymEditManager(const QString& filename, const QString& symbol) + : SymEditManager(nullptr) { - Symbol.Load(symbol); + if ( !filename.isEmpty() ) + { + //## load file + } + + if ( !symbol.isEmpty() ) + Symbol.Load(symbol); } //! Set window initialized. @@ -431,6 +432,20 @@ bool SymEditManager::raiseItem(int dir) return false; } +//! Open symbol file. +bool SymEditManager::open() +{ + //## + return false; +} + +//! Save symbol file. +bool SymEditManager::save() +{ + //## + return false; +} + //! Undo edit operation. /*! \param undo True undoes, false redoes. diff --git a/symedit.h b/symedit.h index acb5a5f..92cd16a 100644 --- a/symedit.h +++ b/symedit.h @@ -37,7 +37,7 @@ class SymEditManager : public QObject public: explicit SymEditManager(QObject* parent = nullptr); - explicit SymEditManager(const QString& symbol); + explicit SymEditManager(const QString& filename, const QString& symbol); //! Save settings. void SaveSettings() const { Settings.Save(); } @@ -80,6 +80,9 @@ public: Q_INVOKABLE void rotateSymbol(int dir); Q_INVOKABLE bool raiseItem(int dir); + Q_INVOKABLE bool open(); + Q_INVOKABLE bool save(); + Q_INVOKABLE bool undo(bool undo); Q_INVOKABLE void help(QString topic) const; @@ -87,13 +90,12 @@ private: void undosave(); bool Initialized = false; //!< Initialization mutex. + QString SymbolFile; //!< Symbol file name. + SymEditSymbol Symbol; //!< Current symbol. SymEditSettings Settings; //!< Editor settings. std::deque UndoStack; //!< Undo stack. std::deque RedoStack; //!< Redo stack. - - QTranslator BackupTranslator; //!< UI backup translator. - QTranslator LocaleTranslator; //!< UI locale translator. }; #endif diff --git a/symedit.pro b/symedit.pro index 4586988..68e2b75 100644 --- a/symedit.pro +++ b/symedit.pro @@ -66,4 +66,5 @@ DISTFILES += \ help/eng/tools.rst \ help/eng/usage.rst \ help/eng/Makefile \ - help/eng/conf.py + help/eng/conf.py \ + LICENSE -- cgit v1.2.3