From a2f39692a2461ffdcd6cd30efae55ef0ee4aaf25 Mon Sep 17 00:00:00 2001 From: eelke Date: Sun, 5 Mar 2017 21:25:37 +0100 Subject: [PATCH] Forgot to add untracked files. --- core/BackupFormatModel.cpp | 100 +++++++++++++++++++++++++++++++++++++ core/BackupFormatModel.h | 26 ++++++++++ src/ProcessStdioWidget.cpp | 14 ++++++ src/ProcessStdioWidget.h | 22 ++++++++ src/ProcessStdioWidget.ui | 19 +++++++ 5 files changed, 181 insertions(+) create mode 100644 core/BackupFormatModel.cpp create mode 100644 core/BackupFormatModel.h create mode 100644 src/ProcessStdioWidget.cpp create mode 100644 src/ProcessStdioWidget.h create mode 100644 src/ProcessStdioWidget.ui diff --git a/core/BackupFormatModel.cpp b/core/BackupFormatModel.cpp new file mode 100644 index 0000000..6b6c76b --- /dev/null +++ b/core/BackupFormatModel.cpp @@ -0,0 +1,100 @@ +#include "BackupFormatModel.h" + +#include + +namespace { + + class BackupFormatItem { + public: + const QString shortFlag; + const QString longFlag; + const QString description; + + BackupFormatItem(QString s, QString l, QString d) + : shortFlag(std::move(s)) + , longFlag(std::move(l)) + , description(std::move(d)) + {} + }; + + using t_BackupFormatItemVector = std::vector; + + + t_BackupFormatItemVector g_BackupFormats = { + BackupFormatItem{ "p", "plain", "Output a plaintext SQL script, restore with psql" }, + BackupFormatItem{ "c", "custom", "Postgresql's own format most flexible and compressed, restore with pg_restore" }, + BackupFormatItem{ "d", "directory", "Generates a directory with a file for each table or blob" }, + BackupFormatItem{ "t", "tar", "Similar to directory if untarred it results in a valid directory backup" } + }; + +} // end of unnamed namespace + + + +BackupFormatModel::BackupFormatModel(QObject *parent) + : QAbstractListModel(parent) +{ +} + +//QVariant BackupFormatModel::headerData(int section, Qt::Orientation orientation, int role) const +//{ +// QVariant result; + +// if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { +// switch (section) { +// case Column::Short: +// result = tr("Short"); +// break; +// case Column::Long: +// result = tr("Long"); +// break; +// case Column::Description: +// result = tr("Description"); +// break; +// } +// } + +// return result; +//} + + +int BackupFormatModel::rowCount(const QModelIndex &parent) const +{ + int size = g_BackupFormats.size(); + return size; +} + +int BackupFormatModel::columnCount(const QModelIndex &parent) const +{ + return 3; + +} + +QVariant BackupFormatModel::data(const QModelIndex &index, int role) const +{ + QVariant result; + if (index.isValid()) { + const int row = index.row(); + const int col = index.column(); + + if (role == Qt::DisplayRole) { + const auto &item = g_BackupFormats.at(row); + switch (col) { + case Column::Short: + result = item.shortFlag; + break; + case Column::Long: + result = item.longFlag; + break; + case Column::Description: + result = item.description; + break; + } + } + else if (role == Qt::ToolTipRole) { + const auto &item = g_BackupFormats.at(row); + result = item.description; + } + } + return result; +} diff --git a/core/BackupFormatModel.h b/core/BackupFormatModel.h new file mode 100644 index 0000000..1c0145e --- /dev/null +++ b/core/BackupFormatModel.h @@ -0,0 +1,26 @@ +#ifndef BACKUPFORMATMODEL_H +#define BACKUPFORMATMODEL_H + +#include + +class BackupFormatModel : public QAbstractListModel +{ + Q_OBJECT + +public: + enum class Column { Short=1, Long=0, Description=2 }; + + explicit BackupFormatModel(QObject *parent); + + // Header: +// QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + + // Basic functionality: + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + +private: +}; + +#endif // BACKUPFORMATMODEL_H diff --git a/src/ProcessStdioWidget.cpp b/src/ProcessStdioWidget.cpp new file mode 100644 index 0000000..4d74ad4 --- /dev/null +++ b/src/ProcessStdioWidget.cpp @@ -0,0 +1,14 @@ +#include "ProcessStdioWidget.h" +#include "ui_ProcessStdioWidget.h" + +ProcessStdioWidget::ProcessStdioWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::ProcessStdioWidget) +{ + ui->setupUi(this); +} + +ProcessStdioWidget::~ProcessStdioWidget() +{ + delete ui; +} diff --git a/src/ProcessStdioWidget.h b/src/ProcessStdioWidget.h new file mode 100644 index 0000000..22a6ca0 --- /dev/null +++ b/src/ProcessStdioWidget.h @@ -0,0 +1,22 @@ +#ifndef PROCESSSTDIOWIDGET_H +#define PROCESSSTDIOWIDGET_H + +#include + +namespace Ui { +class ProcessStdioWidget; +} + +class ProcessStdioWidget : public QWidget +{ + Q_OBJECT + +public: + explicit ProcessStdioWidget(QWidget *parent = 0); + ~ProcessStdioWidget(); + +private: + Ui::ProcessStdioWidget *ui; +}; + +#endif // PROCESSSTDIOWIDGET_H diff --git a/src/ProcessStdioWidget.ui b/src/ProcessStdioWidget.ui new file mode 100644 index 0000000..c773832 --- /dev/null +++ b/src/ProcessStdioWidget.ui @@ -0,0 +1,19 @@ + + + ProcessStdioWidget + + + + 0 + 0 + 750 + 556 + + + + Form + + + + +