2018-08-25 18:14:08 +02:00
|
|
|
|
#include "HorizontalProxyModel.h"
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Code borrowed from: https://stackoverflow.com/questions/21653253/how-to-change-orientation-of-qt-tableview
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HorizontalProxyModel::HorizontalProxyModel(QObject *parent)
|
2018-08-26 07:11:46 +02:00
|
|
|
|
: QIdentityProxyModel(parent)
|
2018-08-25 18:14:08 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|