Move dialogs layout code into separate ui file
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Thu, 28 Jan 2016 19:38:09 +0000 (20:38 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Thu, 28 Jan 2016 19:38:09 +0000 (20:38 +0100)
Makefile.am
src/edit/ProgramStructureDialog.cpp [new file with mode: 0644]
src/edit/ProgramStructureDialog.h [new file with mode: 0644]
src/edit/UnitStructureDialog.cpp [new file with mode: 0644]
src/edit/UnitStructureDialog.h [new file with mode: 0644]
src/edit/editor.cpp
src/edit/ui/dialogs/ProgramStructureDialog.ui [new file with mode: 0644]
src/edit/ui/dialogs/UnitStructureDialog.ui [new file with mode: 0644]

index 819b8844b2faffb01ae4a0243994bc0b0136e726..13dddd85a78ec8c1e2a04fd64220527f99ea03f3 100644 (file)
@@ -163,25 +163,42 @@ bin_logint_HEADERS = \
 clean-logint-extra:
        rm -f bin/logint
 
-bin_logedit_SOURCES = src/edit/editor.cpp src/edit/editor.moc.cpp 
-bin_logedit_CPPFLAGS = $(bin_logedit_CFLAGS) 
+bin_logedit_SOURCES = \
+       src/edit/editor.cpp \
+       src/edit/editor.moc.cpp \
+       src/edit/ProgramStructureDialog.cpp \
+       src/edit/UnitStructureDialog.cpp
+bin_logedit_CPPFLAGS = $(bin_logedit_CFLAGS)
 bin_logedit_LDADD = $(bin_logedit_LIBS)
 bin_logeditdir = src/edit
 bin_logedit_HEADERS =\
        src/edit/editor.h \
-       src/edit/ui/editor.h
+       src/edit/ui/editor.h \
+       src/edit/ProgramStructureDialog.h \
+       src/edit/ui/dialogs/ProgramStructureDialog.h \
+       src/edit/UnitStructureDialog.h \
+       src/edit/ui/dialogs/UnitStructureDialog.h
 
 src/edit/editor.moc.cpp: \
                src/edit/editor.h \
-               src/edit/ui/editor.h
+               src/edit/ui/editor.h \
+               src/edit/ui/dialogs/ProgramStructureDialog.h \
+               src/edit/ui/dialogs/UnitStructureDialog.h
        moc-qt4 src/edit/editor.h -o src/edit/editor.moc.cpp
 #      $(MOC) src/edit/editor.h -o src/edit/editor.moc.cpp
 
 src/edit/ui/editor.h:
        uic src/edit/ui/editor.ui -o src/edit/ui/editor.h
 
+src/edit/ui/dialogs/ProgramStructureDialog.h:
+       uic src/edit/ui/dialogs/ProgramStructureDialog.ui -o src/edit/ui/dialogs/ProgramStructureDialog.h
+
+src/edit/ui/dialogs/UnitStructureDialog.h:
+       uic src/edit/ui/dialogs/UnitStructureDialog.ui -o src/edit/ui/dialogs/UnitStructureDialog.h
+
 
 clean-logedit-extra:
+       rm -f src/edit/ui/dialogs/*.h
        rm -f src/edit/ui/editor.h
        rm -f src/edit/*.moc.cpp
        rm -f bin/modules/logedit
diff --git a/src/edit/ProgramStructureDialog.cpp b/src/edit/ProgramStructureDialog.cpp
new file mode 100644 (file)
index 0000000..25750c8
--- /dev/null
@@ -0,0 +1,27 @@
+#include "ProgramStructureDialog.h"
+
+
+ProgramStructureDialog::ProgramStructureDialog(QWidget * parent)
+       : QDialog(parent)
+{
+       setupUi(this);
+       
+       connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+       connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+}
+
+ProgramStructureDialog::~ProgramStructureDialog()
+{
+}
+
+QString ProgramStructureDialog::getProgramName()
+{
+       return lineEdit->text();
+}
+
+QString ProgramStructureDialog::getCode()
+{
+       QString code;
+       code.sprintf("PROGRAM %s\n\nBEGIN\n\nEND", getProgramName().toStdString().c_str());
+       return code;
+}
diff --git a/src/edit/ProgramStructureDialog.h b/src/edit/ProgramStructureDialog.h
new file mode 100644 (file)
index 0000000..35fbe04
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H
+#define _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H
+
+#include <QtGui/QDialog>
+#include <QtCore/QString>
+
+
+#include "ui/dialogs/ProgramStructureDialog.h"
+
+/**
+ * Program Structure Dialog class
+ * Displays dialog for generating code template for program structure
+ */
+class ProgramStructureDialog : public QDialog, private Ui::ProgramStructureDialog {
+public:
+       /**
+        * Class constructor
+        */
+       ProgramStructureDialog(QWidget * parent = 0);
+
+       /**
+        * Class destuctor
+        */
+       ~ProgramStructureDialog();
+
+       /**
+        * Gets user-passed program name
+        * 
+        * @return program name entered in dialog
+        */
+       QString getProgramName();
+
+       /**
+        * Gets program code template
+        * 
+        * @return program code template with program name
+        */
+       QString getCode();
+};
+
+#endif /* _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H */
diff --git a/src/edit/UnitStructureDialog.cpp b/src/edit/UnitStructureDialog.cpp
new file mode 100644 (file)
index 0000000..a947a12
--- /dev/null
@@ -0,0 +1,47 @@
+#include "UnitStructureDialog.h"
+
+#define TYPENUM        5
+
+const char *UnitTypes[TYPENUM] = {
+       "CLASS",
+       "PROCEDURE",
+       "FUNCTION",
+       "PROCESS",
+       "COROUTINE"
+};
+
+UnitStructureDialog::UnitStructureDialog(QWidget * parent)
+       : QDialog(parent)
+{
+       setupUi(this);
+
+       for (int i = 0; i < TYPENUM; i++) {
+               QListWidgetItem *newItem = new QListWidgetItem;
+               newItem->setText(UnitTypes[i]);
+               listWidget->insertItem(i, newItem);
+       }
+       listWidget->setCurrentItem(0);
+
+       connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+       connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+}
+
+UnitStructureDialog::~UnitStructureDialog()
+{
+}
+
+QString UnitStructureDialog::getUnitName()
+{
+       return lineEdit->text();
+}
+
+QString UnitStructureDialog::getCode()
+{
+       QString code;
+       code.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
+               getUnitName().toStdString().c_str(),
+               listWidget->currentItem()->text().toStdString().c_str(),
+               getUnitName().toStdString().c_str()
+       );
+       return code;
+}
diff --git a/src/edit/UnitStructureDialog.h b/src/edit/UnitStructureDialog.h
new file mode 100644 (file)
index 0000000..32fd7df
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef _VLP_EDITOR_UNITSTRUCTUREDIALOG_H
+#define _VLP_EDITOR_UNITSTRUCTUREDIALOG_H
+
+#include <QtGui/QDialog>
+#include <QtCore/QString>
+
+#include "ui/dialogs/UnitStructureDialog.h"
+
+/**
+ * Program Unit Dialog class
+ * Displays dialog for generating code template for unit structure
+ */
+class UnitStructureDialog : public QDialog, private Ui::UnitStructureDialog {
+public:
+       /**
+        * Class constructor
+        */
+       UnitStructureDialog(QWidget * parent = 0);
+
+       /**
+        * Class destuctor
+        */
+       ~UnitStructureDialog();
+
+       /**
+        * Gets user-passed unit name
+        *
+        * @return unit name entered in dialog
+        */
+       QString getUnitName();
+
+       /**
+        * Gets unit code template
+        * 
+        * @return unit code template with unit name
+        */
+       QString getCode();
+};
+
+#endif /* _VLP_EDITOR_PROGRAMSTRUCTUREDIALOG_H */
index c832f3e88b37c10d9a82c2e4db6194a8e002c804..59e7f9e53d0eae1885a5bcbb8343e959d60b7907 100644 (file)
 #include <QtGui/QListWidget>
 #include <QtGui/QListWidgetItem>
 
-#include "editor.h"
-
-#define TYPENUM        5
+#include "ProgramStructureDialog.h"
+#include "UnitStructureDialog.h"
 
-/**
- * @attention Currently not in use
- */
-const char *UnitTypes[TYPENUM] = {
-       "CLASS",
-       "PROCEDURE",
-       "FUNCTION",
-       "PROCESS",
-       "COROUTINE"
-};
+#include "editor.h"
 
 /**
  * Editor constructor. Initializes and sets variables of Loglan Editor.
@@ -412,102 +402,19 @@ void Editor::on_actionCompile_Gen_triggered()
 
 void Editor::on_actionProgram_structure_triggered()
 {
-       QDialog dlg(this, "unit", TRUE);
-       char uname[255];
-
-       QLineEdit *files;
-       files = new QLineEdit(&dlg, "f_path");
-       files->setGeometry(130, 20, 250, 30);
-       files->setText("");
-       files->setMaxLength(32767);
-       files->setEchoMode(QLineEdit::Normal);
-       files->setFrame(TRUE);
-
-       QLabel *tmpQLabel;
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(10, 20, 100, 30);
-       tmpQLabel->setText("Program name:");
-
-       QPushButton* tmpQPushButton;
-       tmpQPushButton = new QPushButton(&dlg);
-       tmpQPushButton->setGeometry(40, 70, 70, 30);
-       tmpQPushButton->setText("Ok");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       tmpQPushButton = new QPushButton(&dlg);
-       tmpQPushButton->setGeometry(130, 70, 100, 30);
-       tmpQPushButton->setText("Cancel");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-
-       if (dlg.exec()) {
-               strcpy(uname, files->text());
-
-               QString txt;
-               txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND", uname);
+       ProgramStructureDialog dialog(this);
 
-               editor->textCursor().insertText(txt);
+       if (dialog.exec()) {
+               editor->textCursor().insertText(dialog.getCode());
        }
 }
 
 void Editor::on_actionUnit_structure_triggered()
 {
-       QDialog dlg(this, Qt::Dialog);
-       int i;
-       char uname[255];
-
-       QLineEdit* files;
-       files = new QLineEdit(&dlg, "f_path");
-       files->setGeometry(130, 20, 250, 30);
-       files->setText("");
-       files->setMaxLength(32767);
-       files->setEchoMode(QLineEdit::Normal);
-       files->setFrame(TRUE);
-
-       QLabel* tmpQLabel;
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(10, 20, 100, 30);
-       tmpQLabel->setText("Unit name:");
-       tmpQLabel->setAlignment(289);
-       tmpQLabel->setMargin(-1);
-
-       QPushButton* tmpQPushButton;
-       tmpQPushButton = new QPushButton(&dlg);
-       tmpQPushButton->setGeometry(40, 170, 70, 30);
-       tmpQPushButton->setText("Ok");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
-
-       tmpQPushButton = new QPushButton(&dlg);
-       tmpQPushButton->setGeometry(130, 170, 100, 30);
-       tmpQPushButton->setText("Cancel");
-       tmpQPushButton->setAutoRepeat(FALSE);
-       connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
-
-       tmpQLabel = new QLabel(&dlg);
-       tmpQLabel->setGeometry(10, 50, 100, 60);
-       tmpQLabel->setText("Unit type:");
-
-       QListWidget *listWidget = new QListWidget(&dlg);
-       for(i = 0; i < TYPENUM; i++) {
-               QListWidgetItem *newItem = new QListWidgetItem;
-               newItem->setText(UnitTypes[i]);
-               listWidget->insertItem(i, newItem);
-       }
-       listWidget->setCurrentItem(0);
-
-       if (dlg.exec()) {
-               strcpy(uname, files->text());
-
-               QString txt;
-               txt.sprintf("UNIT %s : %s( <params> );\nBEGIN\n\nEND %s;",
-                       uname,
-                       listWidget->currentItem()->text().toStdString().c_str(),
-                       uname
-               );
+       UnitStructureDialog dialog(this);
 
-               editor->textCursor().insertText(txt);
+       if (dialog.exec()) {
+               editor->textCursor().insertText(dialog.getCode());
        }
 }
 
diff --git a/src/edit/ui/dialogs/ProgramStructureDialog.ui b/src/edit/ui/dialogs/ProgramStructureDialog.ui
new file mode 100644 (file)
index 0000000..b4dfa31
--- /dev/null
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ProgramStructureDialog</class>
+ <widget class="QDialog" name="ProgramStructureDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>318</width>
+    <height>108</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Program Structure</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <property name="spacing">
+      <number>6</number>
+     </property>
+     <property name="topMargin">
+      <number>20</number>
+     </property>
+     <property name="bottomMargin">
+      <number>20</number>
+     </property>
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Program name</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLineEdit" name="lineEdit">
+       <property name="minimumSize">
+        <size>
+         <width>200</width>
+         <height>0</height>
+        </size>
+       </property>
+      </widget>
+     </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>ProgramStructureDialog</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>ProgramStructureDialog</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>
diff --git a/src/edit/ui/dialogs/UnitStructureDialog.ui b/src/edit/ui/dialogs/UnitStructureDialog.ui
new file mode 100644 (file)
index 0000000..74f1a5b
--- /dev/null
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UnitStructureDialog</class>
+ <widget class="QDialog" name="UnitStructureDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>486</width>
+    <height>262</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</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_2">
+         <property name="text">
+          <string>Unit type</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QListWidget" name="listWidget">
+         <property name="minimumSize">
+          <size>
+           <width>200</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <layout class="QVBoxLayout" name="verticalLayout_2">
+       <item>
+        <widget class="QLabel" name="label">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="text">
+          <string>Unit name</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="lineEdit">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="minimumSize">
+          <size>
+           <width>200</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="verticalSpacer">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </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>UnitStructureDialog</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>UnitStructureDialog</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>