0
0
mirror of https://github.com/fralx/LimeReport.git synced 2025-10-22 02:17:28 +03:00

Add: added a function to get an arbitrary role of a model item

Example:
$D{appdata.Column_1}
$S{
var vRow = line('DataBand1') - 1;
// 8 - Qt::BackgroundRole
var vColor = getFieldByRowIndexEx('appdata.Column_1', vRow, 8);

THIS.backgroundColor = LimeReport.color('lightgray');
if(vColor > '')
{
	THIS.backgroundColor = vColor;
}
''
}

Added several functions to get extended information from the model

- getFieldByRowIndexEx2(fieldName, rowIndex, roleName), default:
Qt::DisplayRole

- getHeaderData(fieldName, roleName), default: Qt::DisplayRole

- getHeaderColumnNameByIndex(datasourceName, columnIndex), default:
Qt::UserRole or Qt::DisplayRole

- getColumnCount(datasourceName), default: -1
This commit is contained in:
Dmitry Zagorodnev
2024-03-26 11:43:58 +03:00
parent 2b388b02fe
commit 4c1c0c49e6
7 changed files with 261 additions and 0 deletions

View File

@@ -1689,6 +1689,28 @@ QVariant DataSourceManager::fieldDataByRowIndex(const QString &fieldName, int ro
return QVariant();
}
QVariant DataSourceManager::fieldDataByRowIndex(const QString &fieldName, int rowIndex, int role)
{
if(containsField(fieldName)) {
IDataSource *ds = dataSource(extractDataSource(fieldName));
if(ds) {
return ds->dataByRowIndex(extractFieldName(fieldName), rowIndex, role);
}
}
return QVariant();
}
QVariant DataSourceManager::fieldDataByRowIndex(const QString &fieldName, int rowIndex, const QString &roleName)
{
if(containsField(fieldName)) {
IDataSource *ds = dataSource(extractDataSource(fieldName));
if(ds) {
return ds->dataByRowIndex(extractFieldName(fieldName), rowIndex, roleName);
}
}
return QVariant();
}
QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const QString& valueFieldName, const QString& keyFieldName, QVariant keyValue)
{
IDataSource* ds = dataSource(datasourceName);
@@ -1698,6 +1720,36 @@ QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const
return QVariant();
}
QVariant DataSourceManager::headerData(const QString &fieldName, const QString &roleName)
{
if(containsField(fieldName)) {
IDataSource *ds = dataSource(extractDataSource(fieldName));
if(ds) {
return ds->headerData(extractFieldName(fieldName), roleName);
}
}
return QVariant();
}
QString DataSourceManager::columnName(const QString &datasourceName, int index)
{
IDataSource *ds = dataSource(datasourceName);
if(ds && !ds->isInvalid() && ds->columnCount() > index) {
return ds->columnNameByIndex(index);
}
return QString("unknown");
}
int DataSourceManager::columnCount(const QString &datasourceName)
{
IDataSource *ds = dataSource(datasourceName);
if(ds && !ds->isInvalid()) {
return ds->columnCount();
}
return -1;
}
void DataSourceManager::reopenDatasource(const QString& datasourceName)
{
QueryHolder* qh = dynamic_cast<QueryHolder*>(dataSourceHolder(datasourceName));