dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
ipconnectionconfiguration.cpp
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 
28 #include <coreplugin/icore.h>
29 
30 IPConnectionConfiguration::IPConnectionConfiguration(QString classId, QSettings *qSettings,
31  QObject *parent)
32  : IUAVGadgetConfiguration(classId, parent)
33 {
34  Q_UNUSED(qSettings);
35 
36  qRegisterMetaType<IPConnectionConfiguration::Protocol>();
37 }
38 
40 {
41 }
42 
43 IUAVGadgetConfiguration *IPConnectionConfiguration::clone()
44 {
46  m->setHosts(m_hosts);
47  return m;
48 }
49 
55 {
56  auto settings = Core::ICore::instance()->settings();
57 
58  settings->beginGroup(QLatin1String("IPConnection"));
59  settings->beginWriteArray("Hosts");
60 
61  for (int i = 0; i < m_hosts.count(); i++) {
62  settings->setArrayIndex(i);
63  settings->setValue("hostname", m_hosts.at(i).hostname);
64  settings->setValue("port", m_hosts.at(i).port);
65  settings->setValue("protocol", m_hosts.at(i).protocol);
66  }
67  settings->endArray();
68  settings->endGroup();
69 }
70 
72 {
73  auto settings = Core::ICore::instance()->settings();
74 
75  m_hosts.clear();
76  settings->beginGroup(QLatin1String("IPConnection"));
77  int elements = qMax<int>(settings->beginReadArray("Hosts"), 1);
78  for (int i = 0; i < elements; i++) {
79  settings->setArrayIndex(i);
80  Host host;
81  host.hostname = settings->value("hostname", "localhost").toString();
82  host.port = settings->value("port", 9000).toInt();
83  host.protocol = static_cast<Protocol>(settings->value("protocol", ProtocolTcp).toInt());
84  m_hosts.append(host);
85  }
86  settings->endArray();
87  settings->endGroup();
88 }
89 
void setHosts(QVector< Host > &hosts)
for i
Definition: OPPlots.m:140
static ICore * instance()
Definition: coreimpl.cpp:46
IPConnectionConfiguration(QString classId, QSettings *qSettings=nullptr, QObject *parent=nullptr)
IUAVGadgetConfiguration * clone()
virtual QSettings * settings(QSettings::Scope scope=QSettings::UserScope) const =0
Returns the application's main settings object.