2017-03-05 21:25:37 +01:00
|
|
|
|
#include "BackupFormatModel.h"
|
2019-11-04 18:02:48 +01:00
|
|
|
|
#include "rangechecked_cast.h"
|
2017-03-05 21:25:37 +01:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
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<BackupFormatItem>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t_BackupFormatItemVector g_BackupFormats = {
|
2019-03-27 18:23:00 +01:00
|
|
|
|
BackupFormatItem{ "p", "plain (-Fp)", "Output a plaintext SQL script, restore with psql" },
|
|
|
|
|
|
BackupFormatItem{ "c", "custom (-Fc)", "Postgresql's own format most flexible and compressed, restore with pg_restore" },
|
|
|
|
|
|
BackupFormatItem{ "d", "directory (-Fd)", "Generates a directory with a file for each table or blob" },
|
|
|
|
|
|
BackupFormatItem{ "t", "tar (-Ft)", "Similar to directory if untarred it results in a valid directory backup" }
|
2017-03-05 21:25:37 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end of unnamed namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BackupFormatModel::BackupFormatModel(QObject *parent)
|
|
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
|
|
{
|
2019-03-27 18:23:00 +01:00
|
|
|
|
|
2017-03-05 21:25:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-22 12:45:45 +02:00
|
|
|
|
int BackupFormatModel::rowCount(const QModelIndex &) const
|
2017-03-05 21:25:37 +01:00
|
|
|
|
{
|
2019-11-04 18:02:48 +01:00
|
|
|
|
int size = rangechecked_cast<int>(g_BackupFormats.size());
|
2017-03-05 21:25:37 +01:00
|
|
|
|
return size;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-22 12:45:45 +02:00
|
|
|
|
int BackupFormatModel::columnCount(const QModelIndex &) const
|
2017-03-05 21:25:37 +01:00
|
|
|
|
{
|
|
|
|
|
|
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) {
|
2019-11-04 18:02:48 +01:00
|
|
|
|
const auto &item = g_BackupFormats.at(rangechecked_cast<size_t>(row));
|
2017-03-05 21:25:37 +01:00
|
|
|
|
switch (col) {
|
2017-08-22 12:45:45 +02:00
|
|
|
|
case ColumnShort:
|
2017-03-05 21:25:37 +01:00
|
|
|
|
result = item.shortFlag;
|
|
|
|
|
|
break;
|
2017-08-22 12:45:45 +02:00
|
|
|
|
case ColumnLong:
|
2017-03-05 21:25:37 +01:00
|
|
|
|
result = item.longFlag;
|
|
|
|
|
|
break;
|
2017-08-22 12:45:45 +02:00
|
|
|
|
case ColumnDescription:
|
2017-03-05 21:25:37 +01:00
|
|
|
|
result = item.description;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (role == Qt::ToolTipRole) {
|
2019-11-04 18:02:48 +01:00
|
|
|
|
const auto &item = g_BackupFormats.at(rangechecked_cast<size_t>(row));
|
2017-03-05 21:25:37 +01:00
|
|
|
|
result = item.description;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|