From fdd7cc36378cfdd1692885c39f0e8ccd3ea09c1d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Sat, 30 Jan 2016 21:55:26 +0100 Subject: [PATCH] Code refactoring --- src/lgconfig/NodeListDialog.cpp | 17 +++++++++++------ src/lgconfig/NodeListDialog.h | 6 ++++-- src/lgconfig/lgconfig.cpp | 30 ++++++++---------------------- src/lgconfig/lgconfig.h | 6 +----- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/lgconfig/NodeListDialog.cpp b/src/lgconfig/NodeListDialog.cpp index 44567b0..fb08ffe 100644 --- a/src/lgconfig/NodeListDialog.cpp +++ b/src/lgconfig/NodeListDialog.cpp @@ -9,7 +9,7 @@ namespace loglan { namespace vlp { namespace dialog { -NodeListDialog::NodeListDialog(QList *nodes, QWidget * parent) +NodeListDialog::NodeListDialog(QList nodes, QWidget * parent) : QDialog(parent) { setupUi(this); @@ -26,7 +26,7 @@ NodeListDialog::~NodeListDialog() bool NodeListDialog::check_id(int id) { - QListIterator nodesIterator(*_nodes); + QListIterator nodesIterator(_nodes); VLPEntry *node = NULL; while (nodesIterator.hasNext()) { @@ -39,7 +39,7 @@ bool NodeListDialog::check_id(int id) bool NodeListDialog::check_addr(QString addr) { - QListIterator nodesIterator(*_nodes); + QListIterator nodesIterator(_nodes); VLPEntry *node = NULL; while (nodesIterator.hasNext()) { @@ -50,6 +50,11 @@ bool NodeListDialog::check_addr(QString addr) return true; } +QList NodeListDialog::getNodes() +{ + return _nodes; +} + void NodeListDialog::on_addButton_clicked() { dialog::AddNodeDialog dialog(this); @@ -81,7 +86,7 @@ void NodeListDialog::on_addButton_clicked() QListWidgetItem * listWidgetItem = new QListWidgetItem; listWidgetItem->setText(info); nodeList->addItem(listWidgetItem); - _nodes->append(vlpEntry); + _nodes.append(vlpEntry); } else { QMessageBox::warning(this, @@ -103,7 +108,7 @@ void NodeListDialog::on_addButton_clicked() void NodeListDialog::removeNodes(QList selectedNodes) { - QListIterator nodesIterator(*_nodes); + QListIterator nodesIterator(_nodes); fprintf(stderr, " > Removing nodes\n"); for (auto selectedItem : selectedNodes) { @@ -122,7 +127,7 @@ void NodeListDialog::removeNodes(QList selectedNodes) fprintf(stderr, " - removed\n"); int row = nodeList->row(selectedItem); delete nodeList->takeItem(row); - _nodes->removeOne(node); + _nodes.removeOne(node); } } } diff --git a/src/lgconfig/NodeListDialog.h b/src/lgconfig/NodeListDialog.h index 65f48b6..9967ae3 100644 --- a/src/lgconfig/NodeListDialog.h +++ b/src/lgconfig/NodeListDialog.h @@ -20,7 +20,7 @@ namespace dialog { class NodeListDialog : public QDialog, private Ui::NodeListDialog { Q_OBJECT private: - QList *_nodes; + QList _nodes; public: /** * Class constructor @@ -28,7 +28,7 @@ public: * @param nodes actual list of nodes to init dialog with * @param parent parent widget for this dialog */ - NodeListDialog(QList *nodes, QWidget * parent = 0); + NodeListDialog(QList nodes, QWidget * parent = 0); /** * Class destuctor @@ -51,6 +51,8 @@ public: */ bool check_addr(QString addr); + QList getNodes(); + private: /** * Removes list of nodes from the list widget diff --git a/src/lgconfig/lgconfig.cpp b/src/lgconfig/lgconfig.cpp index f3605f1..7b7fca8 100644 --- a/src/lgconfig/lgconfig.cpp +++ b/src/lgconfig/lgconfig.cpp @@ -1,19 +1,5 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include #include #include #include @@ -30,26 +16,26 @@ namespace vlp { QInstall::QInstall() { setupUi(this); - - Nodes.clear(); } void QInstall::on_actionConfigure_triggered() { - dialog::NodeListDialog dialog(&Nodes, this); + dialog::NodeListDialog dialog(nodes, this); if (dialog.exec()) { - if (!Nodes.isEmpty()) { + nodes = dialog.getNodes(); + + if (!nodes.isEmpty()) { VLPEntry *pom; int i; char pomstr[255]; - QListIterator nodesIterator(Nodes); + QListIterator nodesIterator(nodes); while (nodesIterator.hasNext()) { pom = nodesIterator.next(); - i = Nodes.indexOf(pom); + i = nodes.indexOf(pom); sprintf(pomstr, "%s.cfg", pom->addr); @@ -62,7 +48,7 @@ void QInstall::on_actionConfigure_triggered() ); std::vector hosts; - for (auto node : Nodes) { + for (auto node : nodes) { if (pom != node) { hosts.push_back(node->addr); } @@ -79,7 +65,7 @@ void QInstall::on_actionConfigure_triggered() // config_setting_set_string(setting, pom->homedir); - pom = Nodes.at(i); + pom = nodes.at(i); } } } diff --git a/src/lgconfig/lgconfig.h b/src/lgconfig/lgconfig.h index 67dc3e2..c19e0cf 100644 --- a/src/lgconfig/lgconfig.h +++ b/src/lgconfig/lgconfig.h @@ -2,11 +2,7 @@ #define _VLP_LGCONFIG_H #include -#include #include -#include - -#include #include "ui/VLPConfigWindow.h" @@ -27,7 +23,7 @@ public: class QInstall: public QMainWindow, private Ui::VLPConfigWindow { Q_OBJECT public: - QList Nodes; + QList nodes; /** * Class constructor -- 2.30.2