Code refactoring
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 30 Jan 2016 20:55:26 +0000 (21:55 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 30 Jan 2016 20:55:26 +0000 (21:55 +0100)
src/lgconfig/NodeListDialog.cpp
src/lgconfig/NodeListDialog.h
src/lgconfig/lgconfig.cpp
src/lgconfig/lgconfig.h

index 44567b088931f874731c1d0429ffa07684a42643..fb08ffec53e6c0d97b35066acd53cc527b3f431d 100644 (file)
@@ -9,7 +9,7 @@ namespace loglan {
 namespace vlp {
 namespace dialog {
 
 namespace vlp {
 namespace dialog {
 
-NodeListDialog::NodeListDialog(QList<VLPEntry*> *nodes, QWidget * parent)
+NodeListDialog::NodeListDialog(QList<VLPEntry*> nodes, QWidget * parent)
        : QDialog(parent)
 {
        setupUi(this);
        : QDialog(parent)
 {
        setupUi(this);
@@ -26,7 +26,7 @@ NodeListDialog::~NodeListDialog()
 
 bool NodeListDialog::check_id(int id)
 {
 
 bool NodeListDialog::check_id(int id)
 {
-       QListIterator<VLPEntry *> nodesIterator(*_nodes);
+       QListIterator<VLPEntry *> nodesIterator(_nodes);
        VLPEntry *node = NULL;
 
        while (nodesIterator.hasNext()) {
        VLPEntry *node = NULL;
 
        while (nodesIterator.hasNext()) {
@@ -39,7 +39,7 @@ bool NodeListDialog::check_id(int id)
 
 bool NodeListDialog::check_addr(QString addr)
 {
 
 bool NodeListDialog::check_addr(QString addr)
 {
-       QListIterator<VLPEntry *> nodesIterator(*_nodes);
+       QListIterator<VLPEntry *> nodesIterator(_nodes);
        VLPEntry *node = NULL;
 
        while (nodesIterator.hasNext()) {
        VLPEntry *node = NULL;
 
        while (nodesIterator.hasNext()) {
@@ -50,6 +50,11 @@ bool NodeListDialog::check_addr(QString addr)
        return true;
 }
 
        return true;
 }
 
+QList<VLPEntry*> NodeListDialog::getNodes()
+{
+       return _nodes;
+}
+
 void NodeListDialog::on_addButton_clicked()
 {
        dialog::AddNodeDialog dialog(this);
 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);
                                QListWidgetItem * listWidgetItem = new QListWidgetItem;
                                listWidgetItem->setText(info);
                                nodeList->addItem(listWidgetItem);
-                               _nodes->append(vlpEntry);
+                               _nodes.append(vlpEntry);
                        }
                        else {
                                QMessageBox::warning(this,
                        }
                        else {
                                QMessageBox::warning(this,
@@ -103,7 +108,7 @@ void NodeListDialog::on_addButton_clicked()
 
 void NodeListDialog::removeNodes(QList<QListWidgetItem *> selectedNodes)
 {
 
 void NodeListDialog::removeNodes(QList<QListWidgetItem *> selectedNodes)
 {
-       QListIterator<VLPEntry *> nodesIterator(*_nodes);
+       QListIterator<VLPEntry *> nodesIterator(_nodes);
 
        fprintf(stderr, " > Removing nodes\n");
        for (auto selectedItem : selectedNodes) {
 
        fprintf(stderr, " > Removing nodes\n");
        for (auto selectedItem : selectedNodes) {
@@ -122,7 +127,7 @@ void NodeListDialog::removeNodes(QList<QListWidgetItem *> selectedNodes)
                        fprintf(stderr, "   - removed\n");
                        int row = nodeList->row(selectedItem);
                        delete nodeList->takeItem(row);
                        fprintf(stderr, "   - removed\n");
                        int row = nodeList->row(selectedItem);
                        delete nodeList->takeItem(row);
-                       _nodes->removeOne(node);
+                       _nodes.removeOne(node);
                }
        }
 }
                }
        }
 }
index 65f48b6103b99382de69cb5c337e30696f648fa2..9967ae3f0f32843826b5235bce669b4ec6f7811f 100644 (file)
@@ -20,7 +20,7 @@ namespace dialog {
 class NodeListDialog : public QDialog, private Ui::NodeListDialog {
        Q_OBJECT
 private:
 class NodeListDialog : public QDialog, private Ui::NodeListDialog {
        Q_OBJECT
 private:
-       QList<VLPEntry*> *_nodes;
+       QList<VLPEntry*> _nodes;
 public:
        /**
         * Class constructor
 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
         */
         * @param nodes actual list of nodes to init dialog with
         * @param parent parent widget for this dialog
         */
-       NodeListDialog(QList<VLPEntry*> *nodes, QWidget * parent = 0);
+       NodeListDialog(QList<VLPEntry*> nodes, QWidget * parent = 0);
 
        /**
         * Class destuctor
 
        /**
         * Class destuctor
@@ -51,6 +51,8 @@ public:
         */
        bool check_addr(QString addr);
 
         */
        bool check_addr(QString addr);
 
+       QList<VLPEntry*> getNodes();
+
 private:
        /**
         * Removes list of nodes from the list widget
 private:
        /**
         * Removes list of nodes from the list widget
index f3605f16d91c90c0c0c5531dcaf77ff1358a84f9..7b7fca89d910cf4b12b32a7576cb798e1326bc0b 100644 (file)
@@ -1,19 +1,5 @@
 #include <QtGui/QApplication>
 #include <QtGui/QApplication>
-#include <QtGui/QMainWindow>
-#include <Qt3Support/q3multilineedit.h>
-#include <QtGui/QDialog>
-#include <QtGui/QButtonGroup>
-#include <QtGui/QLabel>
-#include <QtGui/QLineEdit>
-#include <Qt3Support/Q3ListBox>
-#include <QtGui/QPushButton>
-#include <QtGui/QRadioButton>
 #include <QtCore/QList>
 #include <QtCore/QList>
-#include <QtCore/qfile.h>
-#include <QtGui/qcombobox.h>
-#include <QtGui/QToolTip>
-#include <QtGui/QFont>
-#include <QtGui/QPixmap>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -30,26 +16,26 @@ namespace vlp {
 QInstall::QInstall()
 {
        setupUi(this);
 QInstall::QInstall()
 {
        setupUi(this);
-
-       Nodes.clear();
 }
 
 void QInstall::on_actionConfigure_triggered()
 {
 }
 
 void QInstall::on_actionConfigure_triggered()
 {
-       dialog::NodeListDialog dialog(&Nodes, this);
+       dialog::NodeListDialog dialog(nodes, this);
 
        if (dialog.exec()) {
 
        if (dialog.exec()) {
-               if (!Nodes.isEmpty()) {
+               nodes = dialog.getNodes();
+
+               if (!nodes.isEmpty()) {
 
                        VLPEntry *pom;
                        int i;
                        char pomstr[255];
 
 
                        VLPEntry *pom;
                        int i;
                        char pomstr[255];
 
-                       QListIterator<VLPEntry *> nodesIterator(Nodes);
+                       QListIterator<VLPEntry *> nodesIterator(nodes);
 
                        while (nodesIterator.hasNext()) {
                                pom = nodesIterator.next();
 
                        while (nodesIterator.hasNext()) {
                                pom = nodesIterator.next();
-                               i = Nodes.indexOf(pom);
+                               i = nodes.indexOf(pom);
                                sprintf(pomstr, "%s.cfg", pom->addr);
 
                                
                                sprintf(pomstr, "%s.cfg", pom->addr);
 
                                
@@ -62,7 +48,7 @@ void QInstall::on_actionConfigure_triggered()
                                );
 
                                std::vector<std::string> hosts;
                                );
 
                                std::vector<std::string> hosts;
-                               for (auto node : Nodes) {
+                               for (auto node : nodes) {
                                        if (pom != node) {
                                                hosts.push_back(node->addr);
                                        }
                                        if (pom != node) {
                                                hosts.push_back(node->addr);
                                        }
@@ -79,7 +65,7 @@ void QInstall::on_actionConfigure_triggered()
 //                             config_setting_set_string(setting, pom->homedir);
 
 
 //                             config_setting_set_string(setting, pom->homedir);
 
 
-                               pom = Nodes.at(i);
+                               pom = nodes.at(i);
                        }
                }
        }
                        }
                }
        }
index 67dc3e2cc249b9b6a9f2732ae938341002584ee2..c19e0cf66cbc477f2c0f1ea25391f515d4481842 100644 (file)
@@ -2,11 +2,7 @@
 #define _VLP_LGCONFIG_H
 
 #include <QtGui/QMainWindow>
 #define _VLP_LGCONFIG_H
 
 #include <QtGui/QMainWindow>
-#include <QtGui/QPushButton>
 #include <QtCore/QList>
 #include <QtCore/QList>
-#include <QtGui/QMenuBar>
-
-#include <Qt3Support/Q3ListBox>
 
 #include "ui/VLPConfigWindow.h"
 
 
 #include "ui/VLPConfigWindow.h"
 
@@ -27,7 +23,7 @@ public:
 class QInstall: public QMainWindow, private Ui::VLPConfigWindow {
        Q_OBJECT
 public:
 class QInstall: public QMainWindow, private Ui::VLPConfigWindow {
        Q_OBJECT
 public:
-       QList<VLPEntry*> Nodes;
+       QList<VLPEntry*> nodes;
 
        /**
         * Class constructor
 
        /**
         * Class constructor