]> Some of my projects - localmylist.git/commitdiff
Add Path Mapping tab.
authorAPTX <marek321@gmail.com>
Sun, 30 Aug 2015 10:54:44 +0000 (12:54 +0200)
committerAPTX <marek321@gmail.com>
Sun, 30 Aug 2015 11:01:43 +0000 (13:01 +0200)
This tab lets you manage path mappings. Changes need
to be saved by clicking the "Save Change" button.

localmylist-management/localmylist-management.pro
localmylist-management/registertabs.cpp
localmylist-management/tabs/pathmappingtab.cpp [new file with mode: 0644]
localmylist-management/tabs/pathmappingtab.h [new file with mode: 0644]
localmylist-management/tabs/pathmappingtab.ui [new file with mode: 0644]

index 2dff316d59b732e187bbb3b013b1e0381a82b6a4..2a378e4d7f5b912e51613ec25de2a92a142ed458 100644 (file)
@@ -28,11 +28,12 @@ SOURCES += main.cpp\
        registertabs.cpp \
        tabs/databaselogtab.cpp \
        tabs/clientlogtab.cpp \
+       tabs/dynamicmodeltab.cpp \
+       tabs/pathmappingtab.cpp \
        fonts.cpp \
        aniaddsyntaxhighlighter.cpp \
        settingsdialog.cpp \
        codeeditor.cpp \
-       tabs/dynamicmodeltab.cpp \
        dynamicmodelfiltermodel.cpp \
        dynamicmodelview.cpp \
        dynamicmodelitemdelegate.cpp
@@ -54,11 +55,12 @@ HEADERS += mainwindow.h \
        tabs/pendingrequesttab.h \
        tabs/databaselogtab.h \
        tabs/clientlogtab.h \
+       tabs/dynamicmodeltab.h \
+       tabs/pathmappingtab.h \
        fonts.h \
        aniaddsyntaxhighlighter.h \
        settingsdialog.h \
        codeeditor.h \
-       tabs/dynamicmodeltab.h \
        dynamicmodelfiltermodel.h \
        dynamicmodelview.h \
        dynamicmodelitemdelegate.h
@@ -73,7 +75,8 @@ FORMS += mainwindow.ui \
        tabs/pendingrequesttab.ui \
        tabs/databaselogtab.ui \
        tabs/clientlogtab.ui \
-       tabs/dynamicmodeltab.ui
+       tabs/dynamicmodeltab.ui \
+       tabs/pathmappingtab.ui
 
 include(../localmylist.pri)
 include(qtsingleapplication/qtsingleapplication.pri)
index bf00af856945274dc42a57f6d58c2c15cea3a88a..944be3d420b790ea0a102f4f5f33036cf84910e6 100644 (file)
@@ -7,6 +7,7 @@
 #include "tabs/databaselogtab.h"
 #include "tabs/clientlogtab.h"
 #include "tabs/dynamicmodeltab.h"
+#include "tabs/pathmappingtab.h"
 
 void registerTabs()
 {
@@ -18,4 +19,5 @@ void registerTabs()
        TabWidget::registerTab<DatabaseLogTab>();
        TabWidget::registerTab<ClientLogTab>();
        TabWidget::registerTab<DynamicModelTab>();
+       TabWidget::registerTab<PathMappingTab>();
 }
diff --git a/localmylist-management/tabs/pathmappingtab.cpp b/localmylist-management/tabs/pathmappingtab.cpp
new file mode 100644 (file)
index 0000000..55ece0e
--- /dev/null
@@ -0,0 +1,104 @@
+#include "pathmappingtab.h"
+#include "ui_pathmappingtab.h"
+
+#include <QSqlRelationalTableModel>
+#include <QSqlRelation>
+#include <QSqlRelationalDelegate>
+#include <QSqlError>
+#include <QMessageBox>
+
+#include "mylist.h"
+
+PathMappingTab::PathMappingTab(QWidget *parent) :
+       AbstractTabBase(parent),
+       ui(new Ui::PathMappingTab),
+       model(nullptr)
+{
+       ui->setupUi(this);
+       m_label = tr("Path Mapping");
+}
+
+PathMappingTab::~PathMappingTab()
+{
+       delete ui;
+}
+
+QString PathMappingTab::staticId()
+{
+       return "path_mapping";
+}
+
+QString PathMappingTab::name()
+{
+       return tr("Path Mapping");
+}
+
+void PathMappingTab::init()
+{
+       model = new QSqlRelationalTableModel(this,
+                       LocalMyList::instance()->database()->connection());
+
+       model->setTable("path_map");
+       model->setRelation(1, QSqlRelation("host", "host_id", "name"));
+       model->setRelation(2, QSqlRelation("host", "host_id", "name"));
+       model->setEditStrategy(QSqlTableModel::OnManualSubmit);
+
+       model->setHeaderData(0, Qt::Horizontal, "ID");
+       model->setHeaderData(1, Qt::Horizontal, "Source Host");
+       model->setHeaderData(2, Qt::Horizontal, "Destination Host");
+       model->setHeaderData(3, Qt::Horizontal, "Source Prefix");
+       model->setHeaderData(4, Qt::Horizontal, "Destination Prefix");
+
+       ui->pathMappingView->setModel(model);
+       ui->pathMappingView->setItemDelegateForColumn(1, new QSqlRelationalDelegate);
+       ui->pathMappingView->setItemDelegateForColumn(2, new QSqlRelationalDelegate);
+       ui->pathMappingView->setSelectionBehavior(QAbstractItemView::SelectRows);
+       ui->pathMappingView->hideColumn(0);
+
+       reload();
+}
+
+void PathMappingTab::activate()
+{
+}
+
+void PathMappingTab::reload()
+{
+       model->select();
+       ui->pathMappingView->resizeColumnsToContents();
+}
+
+void PathMappingTab::on_addNewButton_clicked()
+{
+       model->insertRecord(-1, QSqlRecord());
+}
+
+
+void PathMappingTab::on_saveButton_clicked()
+{
+       if(!model->isDirty())
+               return;
+
+       if (model->submitAll())
+               return;
+
+       QMessageBox::critical(this, tr("Error while saving changes"),
+                                                 model->lastError().text());
+}
+
+void PathMappingTab::on_discardButton_clicked()
+{
+       model->revertAll();
+}
+
+void PathMappingTab::on_removeSelectedButton_clicked()
+{
+       using namespace LocalMyList;
+
+       QModelIndexList selection = ui->pathMappingView->selectionModel()->selectedRows();
+
+       for (const QModelIndex &idx : selection)
+       {
+               model->removeRow(idx.row());
+       }
+}
diff --git a/localmylist-management/tabs/pathmappingtab.h b/localmylist-management/tabs/pathmappingtab.h
new file mode 100644 (file)
index 0000000..957c4e6
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef PATHMAPPINGTAB_H
+#define PATHMAPPINGTAB_H
+
+#include "abstracttab.h"
+
+class QSqlRelationalTableModel;
+
+namespace Ui {
+class PathMappingTab;
+}
+
+class PathMappingTab : public AbstractTabBase<PathMappingTab>
+{
+       Q_OBJECT
+
+public:
+       explicit PathMappingTab(QWidget *parent = 0);
+       ~PathMappingTab();
+
+       static QString staticId();
+       static QString name();
+
+       void init();
+       void activate();
+
+       void reload();
+
+private slots:
+       void on_addNewButton_clicked();
+
+       void on_saveButton_clicked();
+
+       void on_discardButton_clicked();
+
+       void on_removeSelectedButton_clicked();
+
+private:
+       Ui::PathMappingTab *ui;
+       QSqlRelationalTableModel *model;
+};
+
+#endif // PATHMAPPINGTAB_H
diff --git a/localmylist-management/tabs/pathmappingtab.ui b/localmylist-management/tabs/pathmappingtab.ui
new file mode 100644 (file)
index 0000000..80518b8
--- /dev/null
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PathMappingTab</class>
+ <widget class="QWidget" name="PathMappingTab">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QTableView" name="pathMappingView"/>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QPushButton" name="saveButton">
+       <property name="text">
+        <string>Save Changes</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="discardButton">
+       <property name="text">
+        <string>Discard Changes</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="addNewButton">
+       <property name="text">
+        <string>Add New</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="removeSelectedButton">
+       <property name="text">
+        <string>Remove Selected</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>