diff --git a/pglab/HorizontalProxyModel.cpp b/pglab/HorizontalProxyModel.cpp new file mode 100644 index 0000000..e11c41b --- /dev/null +++ b/pglab/HorizontalProxyModel.cpp @@ -0,0 +1,56 @@ +#include "HorizontalProxyModel.h" +/* + * Code borrowed from: https://stackoverflow.com/questions/21653253/how-to-change-orientation-of-qt-tableview + */ + + +HorizontalProxyModel::HorizontalProxyModel(QObject *parent) + : QAbstractProxyModel(parent) +{ +} + +QModelIndex HorizontalProxyModel::mapToSource(const QModelIndex &proxyIndex) const +{ + if (sourceModel()) { + return sourceModel()->index(proxyIndex.column(), proxyIndex.row()); + } + else { + return QModelIndex(); + } +} + +QModelIndex HorizontalProxyModel::mapFromSource(const QModelIndex &sourceIndex) const +{ + return index(sourceIndex.column(), sourceIndex.row()); +} + +QModelIndex HorizontalProxyModel::index(int row, int column, const QModelIndex &) const +{ + return createIndex(row, column, nullptr); +} + +QModelIndex HorizontalProxyModel::parent(const QModelIndex &) const +{ + return QModelIndex(); +} + +int HorizontalProxyModel::rowCount(const QModelIndex &) const +{ + return sourceModel() ? sourceModel()->columnCount() : 0; +} + +int HorizontalProxyModel::columnCount(const QModelIndex &) const +{ + return sourceModel() ? sourceModel()->rowCount() : 0; +} + +QVariant HorizontalProxyModel::headerData( + int section, Qt::Orientation orientation, int role) const +{ + if (!sourceModel()) { + return QVariant(); + } + Qt::Orientation new_orientation = orientation == Qt::Horizontal ? + Qt::Vertical : Qt::Horizontal; + return sourceModel()->headerData(section, new_orientation, role); +} diff --git a/pglab/HorizontalProxyModel.h b/pglab/HorizontalProxyModel.h new file mode 100644 index 0000000..2e073c9 --- /dev/null +++ b/pglab/HorizontalProxyModel.h @@ -0,0 +1,18 @@ +#ifndef HORIZONTALPROXYMODEL_H +#define HORIZONTALPROXYMODEL_H + +#include + +class HorizontalProxyModel : public QAbstractProxyModel { +public: + HorizontalProxyModel(QObject * parent = nullptr); + QModelIndex mapToSource(const QModelIndex &proxyIndex) const; + QModelIndex mapFromSource(const QModelIndex &sourceIndex) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &child) const; + int rowCount(const QModelIndex &parent) const; + int columnCount(const QModelIndex &parent) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; +}; + +#endif // HORIZONTALPROXYMODEL_H diff --git a/pglab/pglab.pro b/pglab/pglab.pro index 3058c10..52a6b07 100644 --- a/pglab/pglab.pro +++ b/pglab/pglab.pro @@ -73,7 +73,8 @@ SOURCES += main.cpp\ Module.cpp \ EditorGutter.cpp \ CodeEditor.cpp \ - PlgPage.cpp + PlgPage.cpp \ + HorizontalProxyModel.cpp HEADERS += \ QueryResultModel.h \ @@ -119,7 +120,8 @@ HEADERS += \ EditorGutter.h \ CodeEditor.h \ PlgPage.h \ - AbstractCommand.h + AbstractCommand.h \ + HorizontalProxyModel.h FORMS += mainwindow.ui \ ConnectionManagerWindow.ui \