Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+231
@@ -0,0 +1,231 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* LtsColumnsSettingWidget Organise table columns
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Steve Kemayou, ESZS, 2025-03-19
|
||||
*/
|
||||
|
||||
|
||||
#include "lts_columns_setting.h"
|
||||
#include "ui_lts_columns_setting.h"
|
||||
|
||||
#include<QDebug>
|
||||
namespace LtsDataView
|
||||
{
|
||||
LtsColumnsSettingWidget::LtsColumnsSettingWidget(const QVector<ColumnOrganiserInfo> &columnInfoVec, QWidget *parent)
|
||||
: LtsWidgets::LtsFramelessDialog(parent)
|
||||
, m_ui(new Ui::LtsColumnsSetting)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_model = new ColumnOrganiserModel(this);
|
||||
m_model->setModelData(columnInfoVec);
|
||||
m_ui->tableView->setModel(m_model);
|
||||
|
||||
for(const auto &ci : columnInfoVec)
|
||||
{
|
||||
if (ci.debugOnly){
|
||||
qDebug()<<">>>[LtsColumnsSettingWidgets] column to hide: id: "<<ci.logicalIndex;
|
||||
m_ui->tableView->hideRow(ci.logicalIndex);
|
||||
}
|
||||
}
|
||||
connect(m_ui->applyBtn, &QPushButton::clicked, this, &LtsColumnsSettingWidget::onApplyClicked);
|
||||
connect(m_ui->cancelBtn, &QPushButton::clicked, this, &LtsColumnsSettingWidget::onAbortClicked);
|
||||
connect(m_ui->resetBtn, &QPushButton::clicked, this, &LtsColumnsSettingWidget::onResetClicked);
|
||||
}
|
||||
|
||||
LtsColumnsSettingWidget::~LtsColumnsSettingWidget()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void LtsColumnsSettingWidget::onResetClicked()
|
||||
{
|
||||
emit columnsResetted();
|
||||
accept();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief LtsColumnsSettingWidget::onApplyClicked
|
||||
* send columns settings
|
||||
*/
|
||||
void LtsColumnsSettingWidget::onApplyClicked()
|
||||
{
|
||||
QVector<LtsDataView::ColumnOrganiserInfo> colInfoVec;
|
||||
const int rowCount = m_ui->tableView->model()->rowCount();
|
||||
colInfoVec.reserve(rowCount);
|
||||
for(int row = 0; row < rowCount; ++row)
|
||||
{
|
||||
const ColumnOrganiserInfo ci = m_ui->tableView->model()->data(m_model->index(row,0),Qt::UserRole).value<ColumnOrganiserInfo>();
|
||||
colInfoVec.push_back(ci);
|
||||
}
|
||||
emit columnVisibilityChanged(colInfoVec);
|
||||
accept();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief LtsColumnsSettingWidget::onAbortClicked
|
||||
*/
|
||||
void LtsColumnsSettingWidget::onAbortClicked()
|
||||
{
|
||||
reject();
|
||||
}
|
||||
|
||||
/// TABLE MODEL FOR COLUMN SETTINGS
|
||||
|
||||
/*!
|
||||
* \brief ColumnOrganiserModel::ColumnOrganiserModel
|
||||
* \param parent
|
||||
*/
|
||||
ColumnOrganiserModel::ColumnOrganiserModel(QObject *parent)
|
||||
:QAbstractTableModel(parent)
|
||||
{
|
||||
beginResetModel();
|
||||
m_vecData.clear();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ColumnOrganiserModel::setModelData
|
||||
* \param infos
|
||||
*/
|
||||
void ColumnOrganiserModel::setModelData(const QVector<ColumnOrganiserInfo> &infos)
|
||||
{
|
||||
for(const auto &data : infos)
|
||||
insertRow(data);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ColumnOrganiserModel::insertRow
|
||||
* \param info
|
||||
*/
|
||||
void ColumnOrganiserModel::insertRow(const ColumnOrganiserInfo &info)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_vecData.size(), m_vecData.size());
|
||||
m_vecData.append(info);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ColumnOrganiserModel::columnCount
|
||||
* \param parent
|
||||
* \return
|
||||
*/
|
||||
int ColumnOrganiserModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return 1; // list of Column header as rows with on column
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ColumnOrganiserModel::rowCount
|
||||
* \param parent
|
||||
* \return
|
||||
*/
|
||||
int ColumnOrganiserModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return m_vecData.count();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ColumnOrganiserModel::data
|
||||
* \param index
|
||||
* \param role
|
||||
* \return
|
||||
*/
|
||||
QVariant ColumnOrganiserModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if ((role != Qt::DisplayRole &&
|
||||
role != Qt::DecorationRole &&
|
||||
role != Qt::EditRole &&
|
||||
role != Qt::CheckStateRole &&
|
||||
role != Qt::UserRole) || !index.isValid() || index.row() >= m_vecData.size())
|
||||
return QVariant();
|
||||
|
||||
const ColumnOrganiserInfo ci = m_vecData.at(index.row());
|
||||
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
return ci.show;
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
return ci.name;
|
||||
|
||||
if (role == Qt::UserRole)
|
||||
return QVariant::fromValue(ci);
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ColumnOrganiserModel::setData
|
||||
* \param index
|
||||
* \param value
|
||||
* \param role
|
||||
* \return
|
||||
*/
|
||||
bool ColumnOrganiserModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
Q_UNUSED(value)
|
||||
if (role != Qt::EditRole && role != Qt::CheckStateRole)
|
||||
return false;
|
||||
|
||||
ColumnOrganiserInfo &ci = m_vecData[index.row()];
|
||||
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
ci.show = !ci.show;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case 0:
|
||||
return false;
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ColumnOrganiserModel::flags
|
||||
* \param index
|
||||
* \return
|
||||
*/
|
||||
Qt::ItemFlags ColumnOrganiserModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
auto f = QAbstractTableModel::flags(index);
|
||||
if (!index.isValid())
|
||||
return f;
|
||||
|
||||
if (index.column() == 0)
|
||||
{
|
||||
f.setFlag(Qt::ItemIsUserCheckable);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ColumnOrganiserModel::headerData
|
||||
* \param section
|
||||
* \param orientation
|
||||
* \param role
|
||||
* \return
|
||||
*/
|
||||
QVariant ColumnOrganiserModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal
|
||||
&& role == Qt::DisplayRole)
|
||||
{
|
||||
if (section == 0)
|
||||
return tr("Column Visibility");
|
||||
}
|
||||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user