|
| 1 | +/* |
| 2 | + Modbus Tools |
| 3 | +
|
| 4 | + Created: 2023 |
| 5 | + Author: Serhii Marchuk, https://github.com/serhmarch |
| 6 | +
|
| 7 | + Copyright (C) 2023 Serhii Marchuk |
| 8 | +
|
| 9 | + This program is free software: you can redistribute it and/or modify |
| 10 | + it under the terms of the GNU General Public License as published by |
| 11 | + the Free Software Foundation, either version 3 of the License, or |
| 12 | + (at your option) any later version. |
| 13 | +
|
| 14 | + This program is distributed in the hope that it will be useful, |
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + GNU General Public License for more details. |
| 18 | +
|
| 19 | + You should have received a copy of the GNU General Public License |
| 20 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | +
|
| 22 | +*/ |
| 23 | +#include "server_dialogscriptmodule.h" |
| 24 | +#include "ui_server_dialogscriptmodule.h" |
| 25 | + |
| 26 | +#include <core.h> |
| 27 | +#include <project/server_scriptmodule.h> |
| 28 | + |
| 29 | +mbServerDialogScriptModule::Strings::Strings() : mbCoreDialogEdit::Strings(), |
| 30 | + title(QStringLiteral("Script Module")), |
| 31 | + cachePrefix(QStringLiteral("Ui.Dialogs.ScriptModule.")) |
| 32 | +{ |
| 33 | +} |
| 34 | + |
| 35 | +const mbServerDialogScriptModule::Strings &mbServerDialogScriptModule::Strings::instance() |
| 36 | +{ |
| 37 | + static const mbServerDialogScriptModule::Strings s; |
| 38 | + return s; |
| 39 | +} |
| 40 | + |
| 41 | +mbServerDialogScriptModule::mbServerDialogScriptModule(QWidget *parent) : |
| 42 | + mbCoreDialogEdit(Strings::instance().cachePrefix, parent), |
| 43 | + ui(new Ui::mbServerDialogScriptModule) |
| 44 | +{ |
| 45 | + ui->setupUi(this); |
| 46 | + |
| 47 | + // ---------------------------------------------------------------------------------- |
| 48 | + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); |
| 49 | + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); |
| 50 | +} |
| 51 | + |
| 52 | +mbServerDialogScriptModule::~mbServerDialogScriptModule() |
| 53 | +{ |
| 54 | + delete ui; |
| 55 | +} |
| 56 | + |
| 57 | +MBSETTINGS mbServerDialogScriptModule::cachedSettings() const |
| 58 | +{ |
| 59 | + const mbServerScriptModule::Strings &vs = mbServerScriptModule::Strings::instance(); |
| 60 | + const Strings &ds = Strings::instance(); |
| 61 | + const QString &prefix = ds.cachePrefix; |
| 62 | + |
| 63 | + MBSETTINGS m = mbCoreDialogEdit::cachedSettings(); |
| 64 | + m[prefix+vs.name ] = ui->lnName ->text(); |
| 65 | + m[prefix+vs.comment ] = ui->txtComment->toPlainText(); |
| 66 | + return m; |
| 67 | +} |
| 68 | + |
| 69 | +void mbServerDialogScriptModule::setCachedSettings(const MBSETTINGS &m) |
| 70 | +{ |
| 71 | + mbCoreDialogEdit::setCachedSettings(m); |
| 72 | + |
| 73 | + const mbServerScriptModule::Strings &vs = mbServerScriptModule::Strings::instance(); |
| 74 | + const Strings &ds = Strings::instance(); |
| 75 | + const QString &prefix = ds.cachePrefix; |
| 76 | + |
| 77 | + MBSETTINGS::const_iterator it; |
| 78 | + MBSETTINGS::const_iterator end = m.end(); |
| 79 | + |
| 80 | + it = m.find(prefix+vs.name ); if (it != end) ui->lnName ->setText (it.value().toString()); |
| 81 | + it = m.find(prefix+vs.comment); if (it != end) ui->txtComment->setPlainText(it.value().toString()); |
| 82 | +} |
| 83 | + |
| 84 | +MBSETTINGS mbServerDialogScriptModule::getSettings(const MBSETTINGS &settings, const QString &title) |
| 85 | +{ |
| 86 | + MBSETTINGS r; |
| 87 | + |
| 88 | + if (title.isEmpty()) |
| 89 | + setWindowTitle(Strings::instance().title); |
| 90 | + else |
| 91 | + setWindowTitle(title); |
| 92 | + if (settings.count()) |
| 93 | + fillForm(settings); |
| 94 | + switch (QDialog::exec()) |
| 95 | + { |
| 96 | + case QDialog::Accepted: |
| 97 | + fillData(r); |
| 98 | + } |
| 99 | + return r; |
| 100 | +} |
| 101 | + |
| 102 | +void mbServerDialogScriptModule::fillForm(const MBSETTINGS &m) |
| 103 | +{ |
| 104 | + const mbServerScriptModule::Strings &vs = mbServerScriptModule::Strings::instance(); |
| 105 | + |
| 106 | + MBSETTINGS::const_iterator it; |
| 107 | + MBSETTINGS::const_iterator end = m.end(); |
| 108 | + |
| 109 | + it = m.find(vs.name ); if (it != end) ui->lnName ->setText (it.value().toString()); |
| 110 | + it = m.find(vs.comment); if (it != end) ui->txtComment->setPlainText(it.value().toString()); |
| 111 | +} |
| 112 | + |
| 113 | +void mbServerDialogScriptModule::fillData(MBSETTINGS &settings) |
| 114 | +{ |
| 115 | + const mbServerScriptModule::Strings &s = mbServerScriptModule::Strings::instance(); |
| 116 | + |
| 117 | + settings[s.name ] = ui->lnName ->text(); |
| 118 | + settings[s.comment] = ui->txtComment->toPlainText(); |
| 119 | +} |
0 commit comments