From: Rafał Długołęcki Date: Fri, 29 Jan 2016 23:28:43 +0000 (+0100) Subject: Move AddNode dialog layout code into separate ui file X-Git-Tag: 3.4-b1~16 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=8758a2ce8b1ecd7f588d3fc9c985ea46b3ad1776;hp=b75f396432fe4070829b3229b45b5e89f8654c8e;p=vlp.git Move AddNode dialog layout code into separate ui file --- diff --git a/Makefile.am b/Makefile.am index 39e86b7..bace181 100644 --- a/Makefile.am +++ b/Makefile.am @@ -230,23 +230,30 @@ clean-logedit-extra: 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 \ - src/lgconfig/ui/VLPConfigWindow.h + src/lgconfig/ui/VLPConfigWindow.h \ + src/lgconfig/ui/dialogs/AddNodeDialog.h 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 +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 + rm -f src/lgconfig/ui/dialogs/*.h 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 index 0000000..f8d0058 --- /dev/null +++ b/src/lgconfig/AddNodeDialog.cpp @@ -0,0 +1,50 @@ +#include + +#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 index 0000000..912f28f --- /dev/null +++ b/src/lgconfig/AddNodeDialog.h @@ -0,0 +1,69 @@ +#ifndef _VLP_LGCONFIG_ADDNODEDIALOG_H +#define _VLP_LGCONFIG_ADDNODEDIALOG_H + +#include +#include + +#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 */ diff --git a/src/lgconfig/lgconfig.cpp b/src/lgconfig/lgconfig.cpp index 91baba3..f167848 100644 --- a/src/lgconfig/lgconfig.cpp +++ b/src/lgconfig/lgconfig.cpp @@ -1,8 +1,6 @@ #include #include #include -#include -// #include #include #include #include @@ -24,8 +22,10 @@ #include #include "lgconfig.h" +#include "AddNodeDialog.h" -QApplication *app; +namespace loglan { +namespace vlp { QInstall::QInstall() { @@ -36,12 +36,12 @@ QInstall::QInstall() bool QInstall::check_id(int id) { - VLPEntry *pom; + VLPEntry *node; QListIterator nodesIterator(Nodes); while (nodesIterator.hasNext()) { - pom = nodesIterator.next(); - if (pom->ID == id) + node = nodesIterator.next(); + if (node->ID == id) return FALSE; } return TRUE; @@ -49,12 +49,12 @@ bool QInstall::check_id(int id) bool QInstall::check_addr(char *addr) { - VLPEntry *pom; + VLPEntry *node; QListIterator 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; @@ -62,85 +62,30 @@ bool QInstall::check_addr(char *addr) 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->ID = id->text().toInt(); + pom->ID = dialog.getNodeNumber(); 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 (tmpQComboBox->currentText() == "Explicit") { + if (dialog.getConnectionType() == "Explicit") { 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); - 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"); } @@ -279,11 +224,14 @@ void QInstall::on_actionQuit_triggered() QApplication::instance()->quit(); } +} +} + 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(); } diff --git a/src/lgconfig/lgconfig.h b/src/lgconfig/lgconfig.h index 700af05..4036391 100644 --- a/src/lgconfig/lgconfig.h +++ b/src/lgconfig/lgconfig.h @@ -10,6 +10,9 @@ #include "ui/VLPConfigWindow.h" +namespace loglan { +namespace vlp { + class VLPEntry { public: int ID; @@ -24,14 +27,29 @@ public: class QInstall: public QMainWindow, private Ui::VLPConfigWindow { Q_OBJECT public: - QMenuBar *bar; Q3ListBox *nodelist; - QPushButton *infob; QList Nodes; + /** + * Class constructor + */ 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(); @@ -42,4 +60,7 @@ private slots: void on_actionQuit_triggered(); }; +} +} + #endif /* _VLP_LGCONFIG_H */ diff --git a/src/lgconfig/ui/dialogs/AddNodeDialog.ui b/src/lgconfig/ui/dialogs/AddNodeDialog.ui new file mode 100644 index 0000000..4d45946 --- /dev/null +++ b/src/lgconfig/ui/dialogs/AddNodeDialog.ui @@ -0,0 +1,161 @@ + + + AddNodeDialog + + + + 0 + 0 + 258 + 185 + + + + Virtual Processor Properties + + + + + + + + + + Node number + + + + + + + IP Address + + + + + + + Connection type + + + + + + + Programs directory + + + + + + + VLP directory + + + + + + + + + + + + 300 + 0 + + + + + + + + + 300 + 0 + + + + + + + + + 300 + 0 + + + + + + + + + 300 + 0 + + + + + + + + + 300 + 0 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AddNodeDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AddNodeDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +