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
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
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)
#include "tabs/databaselogtab.h"
#include "tabs/clientlogtab.h"
#include "tabs/dynamicmodeltab.h"
+#include "tabs/pathmappingtab.h"
void registerTabs()
{
TabWidget::registerTab<DatabaseLogTab>();
TabWidget::registerTab<ClientLogTab>();
TabWidget::registerTab<DynamicModelTab>();
+ TabWidget::registerTab<PathMappingTab>();
}
--- /dev/null
+#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());
+ }
+}
--- /dev/null
+#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
--- /dev/null
+<?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>