Move AddNode dialog layout code into separate ui file
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Fri, 29 Jan 2016 23:28:43 +0000 (00:28 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Fri, 29 Jan 2016 23:28:43 +0000 (00:28 +0100)
Makefile.am
src/lgconfig/AddNodeDialog.cpp [new file with mode: 0644]
src/lgconfig/AddNodeDialog.h [new file with mode: 0644]
src/lgconfig/lgconfig.cpp
src/lgconfig/lgconfig.h
src/lgconfig/ui/dialogs/AddNodeDialog.ui [new file with mode: 0644]

index 39e86b7911121d951a6daaf4f0228fe87d95418f..bace181eecb5257c7dbd609acd6ea00135e314fb 100644 (file)
@@ -230,23 +230,30 @@ clean-logedit-extra:
 
 bin_lgconfig_SOURCES = \
        src/lgconfig/lgconfig.cpp \
 
 bin_lgconfig_SOURCES = \
        src/lgconfig/lgconfig.cpp \
-       src/lgconfig/lgconfig.moc.cpp
+       src/lgconfig/lgconfig.moc.cpp \
+       src/lgconfig/AddNodeDialog.cpp
 bin_lgconfig_CPPFLAGS = $(bin_lgconfig_CFLAGS)
 bin_lgconfig_LDADD = $(bin_lgconfig_LIBS) -lconfig++
 bin_logedit_HEADERS = \
        src/lgconfig/lgconfig.h \
 bin_lgconfig_CPPFLAGS = $(bin_lgconfig_CFLAGS)
 bin_lgconfig_LDADD = $(bin_lgconfig_LIBS) -lconfig++
 bin_logedit_HEADERS = \
        src/lgconfig/lgconfig.h \
-       src/lgconfig/ui/VLPConfigWindow.h
+       src/lgconfig/ui/VLPConfigWindow.h \
+       src/lgconfig/ui/dialogs/AddNodeDialog.h
 
 src/lgconfig/lgconfig.moc.cpp: \
 
 src/lgconfig/lgconfig.moc.cpp: \
-               src/lgconfig/ui/VLPConfigWindow.h
+               src/lgconfig/ui/VLPConfigWindow.h \
+               src/lgconfig/ui/dialogs/AddNodeDialog.h
        $(MOC) src/lgconfig/lgconfig.h -o src/lgconfig/lgconfig.moc.cpp
 
 src/lgconfig/ui/VLPConfigWindow.h:
        uic src/lgconfig/ui/VLPConfigWindow.ui -o src/lgconfig/ui/VLPConfigWindow.h
 
        $(MOC) src/lgconfig/lgconfig.h -o src/lgconfig/lgconfig.moc.cpp
 
 src/lgconfig/ui/VLPConfigWindow.h:
        uic src/lgconfig/ui/VLPConfigWindow.ui -o src/lgconfig/ui/VLPConfigWindow.h
 
+src/lgconfig/ui/dialogs/AddNodeDialog.h:
+       uic src/lgconfig/ui/dialogs/AddNodeDialog.ui -o src/lgconfig/ui/dialogs/AddNodeDialog.h
+
 clean-lgconfig-extra:
        rm -f src/lgconfig/*.moc.cpp
        rm -f src/lgconfig/ui/*.h
 clean-lgconfig-extra:
        rm -f src/lgconfig/*.moc.cpp
        rm -f src/lgconfig/ui/*.h
+       rm -f src/lgconfig/ui/dialogs/*.h
        rm -f bin/lgconfig
 
 bin_logcomp_SOURCES = src/preproc/prep.cpp src/preproc/prep.moc.cpp
        rm -f bin/lgconfig
 
 bin_logcomp_SOURCES = src/preproc/prep.cpp src/preproc/prep.moc.cpp
diff --git a/src/lgconfig/AddNodeDialog.cpp b/src/lgconfig/AddNodeDialog.cpp
new file mode 100644 (file)
index 0000000..f8d0058
--- /dev/null
@@ -0,0 +1,50 @@
+#include <QtGui/QListWidgetItem>
+
+#include "AddNodeDialog.h"
+
+namespace loglan {
+namespace vlp {
+namespace dialog {
+
+AddNodeDialog::AddNodeDialog(QWidget * parent)
+       : QDialog(parent)
+{
+       setupUi(this);
+
+       connectionType->addItem("Explicit");
+       connectionType->setCurrentItem(0);
+}
+
+AddNodeDialog::~AddNodeDialog()
+{
+}
+
+int AddNodeDialog::getNodeNumber()
+{
+       return nodeNumber->value();
+}
+
+QString AddNodeDialog::getIPAddress()
+{
+       return ipAddress->text();
+}
+
+QString AddNodeDialog::getConnectionType()
+{
+       return connectionType->currentText();
+}
+
+QString AddNodeDialog::getProgramsDirectory()
+{
+       return programsDirectory->text();
+}
+
+QString AddNodeDialog::getVLPDirectory()
+{
+       return vlpDirectory->text();
+}
+
+
+}
+}
+}
diff --git a/src/lgconfig/AddNodeDialog.h b/src/lgconfig/AddNodeDialog.h
new file mode 100644 (file)
index 0000000..912f28f
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef _VLP_LGCONFIG_ADDNODEDIALOG_H
+#define _VLP_LGCONFIG_ADDNODEDIALOG_H
+
+#include <QtGui/QDialog>
+#include <QtCore/QString>
+
+#include "ui/dialogs/AddNodeDialog.h"
+
+namespace loglan {
+namespace vlp {
+namespace dialog {
+
+/**
+ * Program Unit Dialog class
+ * Displays dialog for generating code template for unit structure
+ */
+class AddNodeDialog : public QDialog, private Ui::AddNodeDialog {
+public:
+       /**
+        * Class constructor
+        */
+       AddNodeDialog(QWidget * parent = 0);
+
+       /**
+        * Class destuctor
+        */
+       ~AddNodeDialog();
+
+       /**
+        * Gets user-passed node number
+        *
+        * @return node number entered in dialog
+        */
+       int getNodeNumber();
+
+       /**
+        * Gets user-passed ip address
+        *
+        * @return ip address entered in dialog
+        */
+       QString getIPAddress();
+
+       /**
+        * Gets user-passed connection type
+        *
+        * @return connection type entered in dialog
+        */
+       QString getConnectionType();
+
+       /**
+        * Gets user-passed programs directory
+        *
+        * @return programs directory entered in dialog
+        */
+       QString getProgramsDirectory();
+
+       /**
+        * Gets user-passed VLP directory
+        *
+        * @return VLP directory entered in dialog
+        */
+       QString getVLPDirectory();
+};
+
+}
+}
+}
+
+#endif /* _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H */
index 91baba33ff75ec40f21a4d0526f59e1f49caffd1..f167848b5af6e8dd61ff1e31d90168b26fbe60d4 100644 (file)
@@ -1,8 +1,6 @@
 #include <QtGui/QApplication>
 #include <QtGui/QMainWindow>
 #include <Qt3Support/q3multilineedit.h>
 #include <QtGui/QApplication>
 #include <QtGui/QMainWindow>
 #include <Qt3Support/q3multilineedit.h>
-#include <QtGui/QMenuBar>
-// #include <qpopmenu.h>
 #include <QtGui/QDialog>
 #include <QtGui/QButtonGroup>
 #include <QtGui/QLabel>
 #include <QtGui/QDialog>
 #include <QtGui/QButtonGroup>
 #include <QtGui/QLabel>
 #include <libconfig.h>
 
 #include "lgconfig.h"
 #include <libconfig.h>
 
 #include "lgconfig.h"
+#include "AddNodeDialog.h"
 
 
-QApplication *app;
+namespace loglan {
+namespace vlp {
 
 QInstall::QInstall()
 {
 
 QInstall::QInstall()
 {
@@ -36,12 +36,12 @@ QInstall::QInstall()
 
 bool QInstall::check_id(int id)
 {
 
 bool QInstall::check_id(int id)
 {
-       VLPEntry *pom;
+       VLPEntry *node;
        QListIterator<VLPEntry *> nodesIterator(Nodes);
 
        while (nodesIterator.hasNext()) {
        QListIterator<VLPEntry *> nodesIterator(Nodes);
 
        while (nodesIterator.hasNext()) {
-               pom = nodesIterator.next();
-               if (pom->ID == id)
+               node = nodesIterator.next();
+               if (node->ID == id)
                        return FALSE;
        }
        return TRUE;
                        return FALSE;
        }
        return TRUE;
@@ -49,12 +49,12 @@ bool QInstall::check_id(int id)
 
 bool QInstall::check_addr(char *addr)
 {
 
 bool QInstall::check_addr(char *addr)
 {
-       VLPEntry *pom;
+       VLPEntry *node;
        QListIterator<VLPEntry *> nodesIterator(Nodes);
 
        while (nodesIterator.hasNext()) {
        QListIterator<VLPEntry *> nodesIterator(Nodes);
 
        while (nodesIterator.hasNext()) {
-               pom = nodesIterator.next();
-               if (strcmp(pom->addr, addr) == 0)
+               node = nodesIterator.next();
+               if (strcmp(node->addr, addr) == 0)
                        return FALSE;
        }
        return TRUE;
                        return FALSE;
        }
        return TRUE;
@@ -62,85 +62,30 @@ bool QInstall::check_addr(char *addr)
 
 void QInstall::AddNode()
 {
 
 void QInstall::AddNode()
 {
-       QDialog dlg(this);
-       QLabel *tmpQLabel;
-       QLineEdit *id, *addr, *progs, *home;
-       QPushButton *okbtn, *cancelbtn;
-       VLPEntry *pom;
-       char pomstr[255];
-
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(110, 10, 180, 30);
-       tmpQLabel->setFrameStyle(49);
-       tmpQLabel->setText("Virtual Processor Properties");
-
-       id = new QLineEdit(&dlg);
-       id->setGeometry(130, 50, 50, 30);
-       id->setText("");
-
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(20, 50, 90, 30);
-       tmpQLabel->setText("Node number");
-
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(20, 90, 80, 30);
-       tmpQLabel->setText("IP Address");
-
-       addr = new QLineEdit(&dlg);
-       addr->setGeometry(130, 90, 120, 30);
-       addr->setText("");
-
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(20, 130, 100, 30);
-       tmpQLabel->setText("Connection type");
-
-       QComboBox* tmpQComboBox;
-       tmpQComboBox = new QComboBox(&dlg);
-       tmpQComboBox->setGeometry(130, 130, 100, 30);
-       tmpQComboBox->insertItem(0, "Explicit");
-
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(20, 170, 110, 30);
-       tmpQLabel->setText("Programs directory");
+       dialog::AddNodeDialog dialog(this);
 
 
-       progs = new QLineEdit(&dlg);
-       progs->setGeometry(130, 170, 230, 30);
-       progs->setText("");
-
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(20, 210, 100, 30);
-       tmpQLabel->setText("VLP directory");
-
-       home = new QLineEdit(&dlg);
-       home->setGeometry(130, 210, 230, 30);
-       home->setText("");
+       VLPEntry *pom;
 
 
-       okbtn = new QPushButton(&dlg);
-       okbtn->setGeometry(80, 250, 100, 30);
-       okbtn->setText("Ok");
-       connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
-       cancelbtn = new QPushButton(&dlg);
-       cancelbtn->setGeometry(210, 250, 100, 30);
-       cancelbtn->setText("Cancel");
-       connect(cancelbtn,SIGNAL(clicked()), &dlg, SLOT(reject()));
-       dlg.resize(380, 300);
-       if (dlg.exec()) {
+       if (dialog.exec()) {
                pom = new VLPEntry;
                pom = new VLPEntry;
-               pom->ID = id->text().toInt();
+               pom->ID = dialog.getNodeNumber();
                if (check_id(pom->ID)) {
                if (check_id(pom->ID)) {
-                       strcpy(pom->addr, addr->text().toStdString().c_str());
+                       strcpy(pom->addr, dialog.getIPAddress().toStdString().c_str());
                        if (check_addr(pom->addr)) {
                        if (check_addr(pom->addr)) {
-                               if (tmpQComboBox->currentText() == "Explicit") {
+                               if (dialog.getConnectionType() == "Explicit") {
                                        pom->type=0;
                                }
                                        pom->type=0;
                                }
-                               strcpy(pom->progdir, progs->text().toStdString().c_str());
-                               strcpy(pom->homedir, home->text().toStdString().c_str());
+                               strcpy(pom->progdir, dialog.getProgramsDirectory().toStdString().c_str());
+                               strcpy(pom->homedir, dialog.getVLPDirectory().toStdString().c_str());
                                Nodes.append(pom);
                                Nodes.append(pom);
-                               sprintf(pomstr, "Node: %d\t"
-                                               "Addr: %s\t"
-                                               "Home dir: %s", pom->ID, pom->addr, pom->homedir);
-                               nodelist->insertItem(pomstr);
-                               strcpy(pom->item, pomstr);
+                               
+                               QString info;
+                               info.sprintf("Node: %d\tAddr: %s\tHome dir: %s",
+                                       pom->ID, pom->addr, pom->homedir
+                               );
+
+                               nodelist->insertItem(info);
+                               strcpy(pom->item, info.toStdString().c_str());
                        } else {
                                QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", "Ok");
                        }
                        } else {
                                QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", "Ok");
                        }
@@ -279,11 +224,14 @@ void QInstall::on_actionQuit_triggered()
        QApplication::instance()->quit();
 }
 
        QApplication::instance()->quit();
 }
 
+}
+}
+
 
 int main(int argc, char **argv)
 {
 
 int main(int argc, char **argv)
 {
-       app = new QApplication(argc,argv);
-       QInstall cfg;
+       QApplication *app = new QApplication(argc,argv);
+       loglan::vlp::QInstall cfg;
        cfg.show();
        return app->exec();
 }
        cfg.show();
        return app->exec();
 }
index 700af05140711aed23d8647060c878b5d57f28fc..4036391e1e7fbcc62828f82a592a2ace619fd0f4 100644 (file)
@@ -10,6 +10,9 @@
 
 #include "ui/VLPConfigWindow.h"
 
 
 #include "ui/VLPConfigWindow.h"
 
+namespace loglan {
+namespace vlp {
+
 class VLPEntry {
 public:
        int ID;
 class VLPEntry {
 public:
        int ID;
@@ -24,14 +27,29 @@ public:
 class QInstall: public QMainWindow, private Ui::VLPConfigWindow {
        Q_OBJECT
 public:
 class QInstall: public QMainWindow, private Ui::VLPConfigWindow {
        Q_OBJECT
 public:
-       QMenuBar *bar;
        Q3ListBox *nodelist;
        Q3ListBox *nodelist;
-       QPushButton *infob;
        QList<VLPEntry*> Nodes;
 
        QList<VLPEntry*> Nodes;
 
+       /**
+        * Class constructor
+        */
        QInstall();
        QInstall();
-       bool check_id(int);
-       bool check_addr(char*);
+
+       /**
+        * Checks if node with specified id already exists
+        *
+        * @param id ID of the node to search for
+        * @return true if node with specified ID has been found, false otherwise
+        */
+       bool check_id(int id);
+
+       /**
+        * Checks if node with specified address already exists
+        *
+        * @param addr address of the node to search for
+        * @return true if node with specified address has been found, false otherwise
+        */
+       bool check_addr(char * addr);
 
 public slots:
        void AddNode();
 
 public slots:
        void AddNode();
@@ -42,4 +60,7 @@ private slots:
        void on_actionQuit_triggered();
 };
 
        void on_actionQuit_triggered();
 };
 
+}
+}
+
 #endif /* _VLP_LGCONFIG_H */
 #endif /* _VLP_LGCONFIG_H */
diff --git a/src/lgconfig/ui/dialogs/AddNodeDialog.ui b/src/lgconfig/ui/dialogs/AddNodeDialog.ui
new file mode 100644 (file)
index 0000000..4d45946
--- /dev/null
@@ -0,0 +1,161 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>AddNodeDialog</class>
+ <widget class="QDialog" name="AddNodeDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>258</width>
+    <height>185</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Virtual Processor Properties</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_3">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <layout class="QVBoxLayout" name="verticalLayout">
+       <item>
+        <widget class="QLabel" name="label">
+         <property name="text">
+          <string>Node number</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="label_2">
+         <property name="text">
+          <string>IP Address</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="label_3">
+         <property name="text">
+          <string>Connection type</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="label_4">
+         <property name="text">
+          <string>Programs directory</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="label_5">
+         <property name="text">
+          <string>VLP directory</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <layout class="QVBoxLayout" name="verticalLayout_2">
+       <item>
+        <widget class="QSpinBox" name="nodeNumber">
+         <property name="minimumSize">
+          <size>
+           <width>300</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="ipAddress">
+         <property name="minimumSize">
+          <size>
+           <width>300</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QComboBox" name="connectionType">
+         <property name="minimumSize">
+          <size>
+           <width>300</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="programsDirectory">
+         <property name="minimumSize">
+          <size>
+           <width>300</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="vlpDirectory">
+         <property name="minimumSize">
+          <size>
+           <width>300</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>AddNodeDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>AddNodeDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>