From e1c9f64d814247154fc734afdc9b1593d88425bb 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 14:14:49 +0100 Subject: [PATCH] Move ListNode dialog layout code into separate ui file --- Makefile.am | 17 ++- src/lgconfig/NodeListDialog.cpp | 155 ++++++++++++++++++++++ src/lgconfig/NodeListDialog.h | 71 ++++++++++ src/lgconfig/lgconfig.cpp | 135 +------------------ src/lgconfig/lgconfig.h | 21 --- src/lgconfig/ui/dialogs/NodeListDialog.ui | 83 ++++++++++++ 6 files changed, 327 insertions(+), 155 deletions(-) create mode 100644 src/lgconfig/NodeListDialog.cpp create mode 100644 src/lgconfig/NodeListDialog.h create mode 100644 src/lgconfig/ui/dialogs/NodeListDialog.ui diff --git a/Makefile.am b/Makefile.am index bace181..9e6414c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -231,25 +231,36 @@ clean-logedit-extra: bin_lgconfig_SOURCES = \ src/lgconfig/lgconfig.cpp \ src/lgconfig/lgconfig.moc.cpp \ - src/lgconfig/AddNodeDialog.cpp + src/lgconfig/AddNodeDialog.cpp \ + src/lgconfig/NodeListDialog.cpp \ + src/lgconfig/NodeListDialog.moc.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/dialogs/AddNodeDialog.h + src/lgconfig/ui/dialogs/AddNodeDialog.h \ + src/lgconfig/ui/dialogs/NodeListDialog.h src/lgconfig/lgconfig.moc.cpp: \ src/lgconfig/ui/VLPConfigWindow.h \ - src/lgconfig/ui/dialogs/AddNodeDialog.h + src/lgconfig/ui/dialogs/AddNodeDialog.h \ + src/lgconfig/ui/dialogs/NodeListDialog.h $(MOC) src/lgconfig/lgconfig.h -o src/lgconfig/lgconfig.moc.cpp +src/lgconfig/NodeListDialog.moc.cpp: \ + src/lgconfig/ui/dialogs/NodeListDialog.h + $(MOC) src/lgconfig/NodeListDialog.h -o src/lgconfig/NodeListDialog.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 +src/lgconfig/ui/dialogs/NodeListDialog.h: + uic src/lgconfig/ui/dialogs/NodeListDialog.ui -o src/lgconfig/ui/dialogs/NodeListDialog.h + clean-lgconfig-extra: rm -f src/lgconfig/*.moc.cpp rm -f src/lgconfig/ui/*.h diff --git a/src/lgconfig/NodeListDialog.cpp b/src/lgconfig/NodeListDialog.cpp new file mode 100644 index 0000000..44567b0 --- /dev/null +++ b/src/lgconfig/NodeListDialog.cpp @@ -0,0 +1,155 @@ +#include +#include + +#include "lgconfig.h" /* VLPEntry */ +#include "NodeListDialog.h" +#include "AddNodeDialog.h" + +namespace loglan { +namespace vlp { +namespace dialog { + +NodeListDialog::NodeListDialog(QList *nodes, QWidget * parent) + : QDialog(parent) +{ + setupUi(this); + + _nodes = nodes; + + connect(saveButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); +} + +NodeListDialog::~NodeListDialog() +{ +} + +bool NodeListDialog::check_id(int id) +{ + QListIterator nodesIterator(*_nodes); + VLPEntry *node = NULL; + + while (nodesIterator.hasNext()) { + node = nodesIterator.next(); + if (node->ID == id) + return false; + } + return true; +} + +bool NodeListDialog::check_addr(QString addr) +{ + QListIterator nodesIterator(*_nodes); + VLPEntry *node = NULL; + + while (nodesIterator.hasNext()) { + node = nodesIterator.next(); + if (node->addr == addr) + return false; + } + return true; +} + +void NodeListDialog::on_addButton_clicked() +{ + dialog::AddNodeDialog dialog(this); + + if (dialog.exec()) { + int nodeId = dialog.getNodeNumber(); + QString ipAddress = dialog.getIPAddress(); + if (check_id(nodeId)) { + if (check_addr(ipAddress)) { + + VLPEntry *vlpEntry = new VLPEntry; + vlpEntry->ID = nodeId; + if (dialog.getConnectionType() == "Explicit") { + vlpEntry->type = 0; + } + strcpy(vlpEntry->addr, ipAddress.toStdString().c_str()); + strcpy(vlpEntry->progdir, dialog.getProgramsDirectory().toStdString().c_str()); + strcpy(vlpEntry->homedir, dialog.getVLPDirectory().toStdString().c_str()); + + QString info; + info.sprintf("Node: %d\tAddr: %s\tHome dir: %s", + vlpEntry->ID, + vlpEntry->addr, + vlpEntry->homedir + ); + + strcpy(vlpEntry->item, info.toStdString().c_str()); + + QListWidgetItem * listWidgetItem = new QListWidgetItem; + listWidgetItem->setText(info); + nodeList->addItem(listWidgetItem); + _nodes->append(vlpEntry); + } + else { + QMessageBox::warning(this, + "Error!", + "Only one VLP on a single computer!", + QMessageBox::Ok + ); + } + } + else { + QMessageBox::warning(this, + "Error!", + "ID must be unique!", + QMessageBox::Ok + ); + } + } +} + +void NodeListDialog::removeNodes(QList selectedNodes) +{ + QListIterator nodesIterator(*_nodes); + + fprintf(stderr, " > Removing nodes\n"); + for (auto selectedItem : selectedNodes) { + fprintf(stderr, " > Selected item\n"); + VLPEntry *node = NULL; + QString selectedNodeInfo = selectedItem->text(); + + while (nodesIterator.hasNext()) { + node = nodesIterator.next(); + if (selectedNodeInfo == node->item) { + fprintf(stderr, " - found\n"); + break; + } + } + if (node != NULL) { + fprintf(stderr, " - removed\n"); + int row = nodeList->row(selectedItem); + delete nodeList->takeItem(row); + _nodes->removeOne(node); + } + } +} + +void NodeListDialog::on_deleteButton_clicked() +{ + if (nodeList->selectedItems().size() > 0) { + if (QMessageBox::question(this, + "Delete VLP", + "Are you sure?", + QMessageBox::Ok | QMessageBox::Cancel + ) == QMessageBox::Ok) { + removeNodes(nodeList->selectedItems()); + } + } +} + +void NodeListDialog::on_saveButton_clicked() +{ + +} + +void NodeListDialog::on_cancelButton_clicked() +{ +} + + +} +} +} diff --git a/src/lgconfig/NodeListDialog.h b/src/lgconfig/NodeListDialog.h new file mode 100644 index 0000000..65f48b6 --- /dev/null +++ b/src/lgconfig/NodeListDialog.h @@ -0,0 +1,71 @@ +#ifndef _VLP_LGCONFIG_NODELISTDIALOG_H +#define _VLP_LGCONFIG_NODELISTDIALOG_H + +#include +#include +#include + +#include "lgconfig.h" /* VLPEntry */ + +#include "ui/dialogs/NodeListDialog.h" + +namespace loglan { +namespace vlp { +namespace dialog { + +/** + * Program Node List Dialog class + * Displays dialog for configuring nodes + */ +class NodeListDialog : public QDialog, private Ui::NodeListDialog { + Q_OBJECT +private: + QList *_nodes; +public: + /** + * Class constructor + * + * @param nodes actual list of nodes to init dialog with + * @param parent parent widget for this dialog + */ + NodeListDialog(QList *nodes, QWidget * parent = 0); + + /** + * Class destuctor + */ + ~NodeListDialog(); + + /** + * 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(QString addr); + +private: + /** + * Removes list of nodes from the list widget + */ + void removeNodes(QList selectedNodes); + +private slots: + void on_addButton_clicked(); + void on_deleteButton_clicked(); + void on_saveButton_clicked(); + void on_cancelButton_clicked(); +}; + +} +} +} + +#endif /* _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H */ diff --git a/src/lgconfig/lgconfig.cpp b/src/lgconfig/lgconfig.cpp index b8036db..8739358 100644 --- a/src/lgconfig/lgconfig.cpp +++ b/src/lgconfig/lgconfig.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -22,7 +21,7 @@ #include #include "lgconfig.h" -#include "AddNodeDialog.h" +#include "NodeListDialog.h" namespace loglan { namespace vlp { @@ -34,141 +33,15 @@ QInstall::QInstall() Nodes.clear(); } -bool QInstall::check_id(int id) -{ - QListIterator nodesIterator(Nodes); - VLPEntry *node = NULL; - - while (nodesIterator.hasNext()) { - node = nodesIterator.next(); - if (node->ID == id) - return false; - } - return true; -} - -bool QInstall::check_addr(QString addr) -{ - QListIterator nodesIterator(Nodes); - VLPEntry *node = NULL; - - while (nodesIterator.hasNext()) { - node = nodesIterator.next(); - if (node->addr == addr) - return false; - } - return true; -} - -void QInstall::AddNode() -{ - dialog::AddNodeDialog dialog(this); - - if (dialog.exec()) { - int nodeId = dialog.getNodeNumber(); - QString ipAddress = dialog.getIPAddress(); - if (check_id(nodeId)) { - if (check_addr(ipAddress)) { - - VLPEntry *pom = new VLPEntry; - pom->ID = nodeId; - if (dialog.getConnectionType() == "Explicit") { - pom->type = 0; - } - strcpy(pom->addr, ipAddress.toStdString().c_str()); - strcpy(pom->progdir, dialog.getProgramsDirectory().toStdString().c_str()); - strcpy(pom->homedir, dialog.getVLPDirectory().toStdString().c_str()); - - QString info; - info.sprintf("Node: %d\tAddr: %s\tHome dir: %s", - pom->ID, - pom->addr, - pom->homedir - ); - - strcpy(pom->item, info.toStdString().c_str()); - - nodelist->insertItem(info); - Nodes.append(pom); - } - else { - QMessageBox::warning(this, "Error!", "Only one VLP on a single computer!", QMessageBox::Ok); - } - } - else { - QMessageBox::warning(this, "Error!", "ID must be unique!", QMessageBox::Ok); - } - } -} - -void QInstall::DelNode() -{ - if (nodelist->currentItem() >= 0) { - VLPEntry *node = NULL; - QString currentNodeInfo = nodelist->text(nodelist->currentItem()); - - QListIterator nodesIterator(Nodes); - - while (nodesIterator.hasNext()) { - node = nodesIterator.next(); - if (currentNodeInfo == node->item) { - break; - } - } - - if (node != NULL) { - if (QMessageBox::question(this, - "Delete VLP", - "Are you sure?", - QMessageBox::Ok | QMessageBox::Cancel - ) == QMessageBox::Ok) { - nodelist->removeItem(nodelist->currentItem()); - Nodes.removeOne(node); - } - } - } -} - void QInstall::on_actionConfigure_triggered() { - QDialog dlg(this); - QLabel *tmpQLabel; - QPushButton *addbtn, *delbtn, *okbtn, *cancelbtn; + dialog::NodeListDialog dialog(&Nodes, this); + VLPEntry *pom; int i; char pomstr[255]; - //dlg.setStyle(WindowsStyle); - nodelist = new Q3ListBox(&dlg); - nodelist->setGeometry(20, 40, 480, 160); - - tmpQLabel = new QLabel(&dlg); - tmpQLabel->setGeometry(20, 10, 100, 30); - tmpQLabel->setText("Nodes:"); - - addbtn = new QPushButton(&dlg); - addbtn->setGeometry(30, 210, 100, 30); - addbtn->setText("Add VLP"); - connect(addbtn, SIGNAL(clicked()), this, SLOT(AddNode())); - - delbtn = new QPushButton(&dlg); - delbtn->setGeometry(150, 210, 100, 30); - delbtn->setText("Del VLP"); - connect(delbtn, SIGNAL(clicked()), this, SLOT(DelNode())); - - okbtn = new QPushButton(&dlg); - okbtn->setGeometry(270, 210, 100, 30); - okbtn->setText("Save files"); - connect(okbtn, SIGNAL(clicked()), &dlg, SLOT(accept())); - - cancelbtn = new QPushButton(&dlg); - cancelbtn->setGeometry(390, 210, 100, 30); - cancelbtn->setText("Cancel"); - connect(cancelbtn, SIGNAL(clicked()), &dlg, SLOT(reject())); - - dlg.resize(520, 260); - - if (dlg.exec()) { + if (dialog.exec()) { if (!Nodes.isEmpty()) { QListIterator nodesIterator(Nodes); diff --git a/src/lgconfig/lgconfig.h b/src/lgconfig/lgconfig.h index bdd2ae2..67dc3e2 100644 --- a/src/lgconfig/lgconfig.h +++ b/src/lgconfig/lgconfig.h @@ -27,7 +27,6 @@ public: class QInstall: public QMainWindow, private Ui::VLPConfigWindow { Q_OBJECT public: - Q3ListBox *nodelist; QList Nodes; /** @@ -35,26 +34,6 @@ public: */ QInstall(); - /** - * 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(QString addr); - -public slots: - void AddNode(); - void DelNode(); - private slots: void on_actionConfigure_triggered(); void on_actionQuit_triggered(); diff --git a/src/lgconfig/ui/dialogs/NodeListDialog.ui b/src/lgconfig/ui/dialogs/NodeListDialog.ui new file mode 100644 index 0000000..1e2a01a --- /dev/null +++ b/src/lgconfig/ui/dialogs/NodeListDialog.ui @@ -0,0 +1,83 @@ + + + NodeListDialog + + + + 0 + 0 + 508 + 212 + + + + Dialog + + + + + + + + + 400 + 0 + + + + QAbstractItemView::MultiSelection + + + + + + + + + Add + + + + + + + Delete + + + + + + + Save + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Cancel + + + + + + + + + + + + -- 2.30.2