Addded HorizontalProxyModel which is used to effictively rotate a table 90 degrees.
This commit is contained in:
parent
50cb21b6f9
commit
68a1a8e7c9
3 changed files with 78 additions and 2 deletions
56
pglab/HorizontalProxyModel.cpp
Normal file
56
pglab/HorizontalProxyModel.cpp
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue