From: APTX Date: Sun, 30 Aug 2015 10:54:44 +0000 (+0200) Subject: Add Path Mapping tab. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=d2daa5fd0b3a5b34cb0de3f7f7f11cc4b6f482f1;p=localmylist.git Add Path Mapping tab. This tab lets you manage path mappings. Changes need to be saved by clicking the "Save Change" button. --- diff --git a/localmylist-management/localmylist-management.pro b/localmylist-management/localmylist-management.pro index 2dff316..2a378e4 100644 --- a/localmylist-management/localmylist-management.pro +++ b/localmylist-management/localmylist-management.pro @@ -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) diff --git a/localmylist-management/registertabs.cpp b/localmylist-management/registertabs.cpp index bf00af8..944be3d 100644 --- a/localmylist-management/registertabs.cpp +++ b/localmylist-management/registertabs.cpp @@ -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(); TabWidget::registerTab(); TabWidget::registerTab(); + TabWidget::registerTab(); } diff --git a/localmylist-management/tabs/pathmappingtab.cpp b/localmylist-management/tabs/pathmappingtab.cpp new file mode 100644 index 0000000..55ece0e --- /dev/null +++ b/localmylist-management/tabs/pathmappingtab.cpp @@ -0,0 +1,104 @@ +#include "pathmappingtab.h" +#include "ui_pathmappingtab.h" + +#include +#include +#include +#include +#include + +#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 index 0000000..957c4e6 --- /dev/null +++ b/localmylist-management/tabs/pathmappingtab.h @@ -0,0 +1,42 @@ +#ifndef PATHMAPPINGTAB_H +#define PATHMAPPINGTAB_H + +#include "abstracttab.h" + +class QSqlRelationalTableModel; + +namespace Ui { +class PathMappingTab; +} + +class PathMappingTab : public AbstractTabBase +{ + 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 index 0000000..80518b8 --- /dev/null +++ b/localmylist-management/tabs/pathmappingtab.ui @@ -0,0 +1,78 @@ + + + PathMappingTab + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + + + + + + + + Save Changes + + + + + + + Discard Changes + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add New + + + + + + + Remove Selected + + + + + + + + + +