1 #ifndef DATA_DEDUPLICATION_SERVICE_MYPQXXMODEL_H
2 #define DATA_DEDUPLICATION_SERVICE_MYPQXXMODEL_H
6 #include <unordered_map>
8 #include <QAbstractTableModel>
9 #include <QSortFilterProxyModel>
14 #include <QMouseEvent>
27 using returnType = std::variant <std::type_identity<int64_t>,
28 std::type_identity<double>,
29 std::type_identity<std::string>,
30 std::type_identity<pqxx::binarystring>>;
35 static const std::unordered_map <oid, returnType> oidToTypeMap = {
36 {20, std::type_identity < int64_t > {}},
37 {701, std::type_identity < double > {}},
38 {25, std::type_identity < std::string > {}},
39 {17, std::type_identity < pqxx::binarystring > {}},
40 {1700, std::type_identity < double > {}}
49 template<
typename ReturnType>
57 return {QString::fromStdString(val.str())};
62 return {QString::fromStdString(val.data())};
67 return {QString::fromStdString(val)};
77 return static_cast<qint64
>(val);
120 QVariant convertFromPqxx(
const QModelIndex &index,
int role)
const;
129 template<
typename ResType1,
typename ... Args>
142 template<
typename ResType1,
typename ... Args>
147 void setColumnsTypes();
174 int rowCount(
const QModelIndex &parent)
const override {
179 return res.columns();
189 QVariant headerData(
int section, Qt::Orientation orientation,
190 int role)
const override;
192 QVariant data(
const QModelIndex &index,
int role)
const override;
225 : QSortFilterProxyModel(parent) {
236 QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
239 return (sourceModel()->data(index0).toString().contains(filterRegularExpression()));
250 : QSortFilterProxyModel(parent) {
261 for (
int i = 0; i < sourceModel()->columnCount(); ++i) {
262 if (sourceModel()->data(sourceModel()->index(sourceRow, i, sourceParent)).isNull()) {
282 void mousePressEvent(QMouseEvent *event)
override {
284 QModelIndex item = indexAt(event->pos());
286 if (item.isValid()) {
287 QTableView::mousePressEvent(event);
290 const QModelIndex index;
291 selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
298 template<
typename ResType1,
typename... Args>
302 res = pqxx::result();
307 if (!ss.has_value()) {
308 res = pqxx::result();
312 catch (
const pqxx::sql_error &e) {
313 res = pqxx::result();
316 catch (
const std::exception &e) {
317 res = pqxx::result();
325 template<
typename ResType1,
typename... Args>
329 res = pqxx::result();
334 if (!ss.has_value()) {
335 res = pqxx::result();
339 catch (
const pqxx::sql_error &e) {
340 res = pqxx::result();
343 catch (
const std::exception &e) {
344 res = pqxx::result();
Pqxx model that retrieves database deduplication characteristic.
Definition: myPqxxModel.h:203
void getData() override
Definition: myPqxxModel.h:210
deduplicationCharacteristicsModel(QObject *parent=nullptr)
Definition: myPqxxModel.h:205
Tbale view that can be deselected.
Definition: myPqxxModel.h:271
deselectableTableView(QWidget *parent)
Definition: myPqxxModel.h:273
~deselectableTableView() override=default
Table model for pqxx::result.
Definition: myPqxxModel.h:168
int rowCount(const QModelIndex &parent) const override
Definition: myPqxxModel.h:174
int columnCount(const QModelIndex &parent) const override
Definition: myPqxxModel.h:178
Basic class for database pqxx::result representation.
Definition: myPqxxModel.h:85
bool isEmpty() const
Definition: myPqxxModel.h:106
QList< QString > columnNames
Definition: myPqxxModel.h:159
void executeInTransaction(ResType1(*call)(db_services::trasnactionType &, Args ...), Args &&... args)
QList< oid > columnTypes
Definition: myPqxxModel.h:158
conPtr connection
Definition: myPqxxModel.h:157
resType res
Definition: myPqxxModel.h:156
void executeInTransaction(const std::function< ResType1(db_services::trasnactionType &, Args ...)> &call, Args &&... args)
void reset()
Definition: myPqxxModel.h:151
bool isEmpty_
Definition: myPqxxModel.h:161
bool good
Definition: myPqxxModel.h:160
Sort filter proxy model used for searching entry names.
Definition: myPqxxModel.h:221
mySortFilterProxyModel(QObject *parent=nullptr)
Definition: myPqxxModel.h:224
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Definition: myPqxxModel.h:235
Sort filter model that filters out all rows with NULL values.
Definition: myPqxxModel.h:245
notNullFilterProxyModel(QObject *parent=nullptr)
Definition: myPqxxModel.h:249
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Definition: myPqxxModel.h:260
db_services namespace
Definition: dbCommon.h:17
pqxx::transaction< pqxx::isolation_level::read_committed > trasnactionType
Definition: dbCommon.h:35
pqxx::result resType
Definition: dbCommon.h:38
tl::expected< ResultType, int > executeInTransaction(conPtr &conn, ResultType(*call)(trasnactionType &, Args ...), Args &&... args)
Definition: dbCommon.h:246
resType getDedupCharacteristics(trasnactionType &txn)
Definition: dbCommon.cpp:205
bool checkConnection(const conPtr &conn)
Definition: dbCommon.cpp:309
std::shared_ptr< connectionType > conPtr
Definition: dbCommon.h:37
models namespace
Definition: myPqxxModel.cpp:3
std::variant< std::type_identity< int64_t >, std::type_identity< double >, std::type_identity< std::string >, std::type_identity< pqxx::binarystring > > returnType
Definition: myPqxxModel.h:30
QVariant toQtVariant(const ReturnType &val)
Definition: myPqxxModel.h:51
uint32_t oid
Definition: myPqxxModel.h:22
Structure to store and format connection string.
Definition: myConnString.h:15