From 56e145ecd8fe7c3b0e3e52853d4e89ea9aeefe7e Mon Sep 17 00:00:00 2001 From: Dmitry Zagorodnev Date: Mon, 20 Feb 2023 14:24:25 +0300 Subject: [PATCH 1/6] Fix: lrcompletermodel.h out of range --- limereport/scripteditor/lrcompletermodel.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/limereport/scripteditor/lrcompletermodel.h b/limereport/scripteditor/lrcompletermodel.h index 862437a..eeab147 100644 --- a/limereport/scripteditor/lrcompletermodel.h +++ b/limereport/scripteditor/lrcompletermodel.h @@ -12,7 +12,9 @@ public: CompleterItem(QString text, QIcon icon):m_parent(0), m_text(text), m_icon(icon), m_model(0){} ~CompleterItem(); int rowCount() const {return m_children.count();} - CompleterItem* child(int row) const {return m_children.at(row).data();} + CompleterItem *child(int row) const { + return m_children.count() < row ? m_children.at(row).data() : nullptr; + } CompleterItem* parent() const {return m_parent;} int row() const{ if (m_parent){ From de850125aaffeebb6530214047bacd97feed32f9 Mon Sep 17 00:00:00 2001 From: Dmitry Zagorodnev Date: Mon, 20 Feb 2023 14:29:32 +0300 Subject: [PATCH 2/6] Fix: lrcompletermodel access to null ptr --- limereport/scripteditor/lrcompletermodel.cpp | 19 ++++++++++--------- limereport/scripteditor/lrcompletermodel.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/limereport/scripteditor/lrcompletermodel.cpp b/limereport/scripteditor/lrcompletermodel.cpp index 29c7116..70299f6 100644 --- a/limereport/scripteditor/lrcompletermodel.cpp +++ b/limereport/scripteditor/lrcompletermodel.cpp @@ -22,16 +22,17 @@ QModelIndex CompleterModel::index(int row, int column, const QModelIndex &parent return createIndex(row, column, parentItem->child(row)); } -QModelIndex CompleterModel::parent(const QModelIndex &child) const -{ - if (child.isValid()){ - CompleterItem *childItem = static_cast(child.internalPointer()); - CompleterItem *parentItem = childItem->parent(); - if (parentItem != &m_root) { - return indexFromItem(parentItem); - } +QModelIndex CompleterModel::parent(const QModelIndex &child) const { + if(child.isValid()) { + if(CompleterItem *childItem = static_cast(child.internalPointer()); + childItem) { + CompleterItem *parentItem = childItem->parent(); + if(parentItem != &m_root) { + return indexFromItem(parentItem); + } } - return QModelIndex(); + } + return QModelIndex(); } int CompleterModel::rowCount(const QModelIndex &parent) const diff --git a/limereport/scripteditor/lrcompletermodel.h b/limereport/scripteditor/lrcompletermodel.h index eeab147..9611e5d 100644 --- a/limereport/scripteditor/lrcompletermodel.h +++ b/limereport/scripteditor/lrcompletermodel.h @@ -35,7 +35,7 @@ public: void appendRow(CompleterItem* child); void appendRows(const QList &children); private: - CompleterItem* m_parent; + CompleterItem* m_parent{nullptr}; QVector > m_children; QString m_text; QIcon m_icon; From fede9963bed91dda8c90d6a7d04144cb7805fbb3 Mon Sep 17 00:00:00 2001 From: Dmitry Zagorodnev Date: Thu, 9 Mar 2023 15:32:48 +0300 Subject: [PATCH 3/6] Fix: lrcompletermodel.h -> child(int row) --- limereport/scripteditor/lrcompletermodel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/limereport/scripteditor/lrcompletermodel.h b/limereport/scripteditor/lrcompletermodel.h index 9611e5d..8f218e8 100644 --- a/limereport/scripteditor/lrcompletermodel.h +++ b/limereport/scripteditor/lrcompletermodel.h @@ -13,7 +13,7 @@ public: ~CompleterItem(); int rowCount() const {return m_children.count();} CompleterItem *child(int row) const { - return m_children.count() < row ? m_children.at(row).data() : nullptr; + return m_children.count() > row ? m_children.at(row).data() : nullptr; } CompleterItem* parent() const {return m_parent;} int row() const{ From fbfe26aa53a64903803bfef74d898206b4af81b0 Mon Sep 17 00:00:00 2001 From: Dmitry Zagorodnev Date: Tue, 14 Mar 2023 17:49:38 +0300 Subject: [PATCH 4/6] Fix: lrtextitem.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fakeMarginSize - убрал +5px постоянный размер прогала --- limereport/items/lrtextitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/limereport/items/lrtextitem.cpp b/limereport/items/lrtextitem.cpp index 4677892..4cec5f9 100644 --- a/limereport/items/lrtextitem.cpp +++ b/limereport/items/lrtextitem.cpp @@ -78,7 +78,7 @@ TextItem::TextItem(QObject *owner, QGraphicsItem *parent) TextItem::~TextItem(){} int TextItem::fakeMarginSize() const{ - return marginSize()+5; + return marginSize()/*+5*/; } void TextItem::preparePopUpMenu(QMenu &menu) From 87eae706e5c188ef4a011937848dedd3fedee1d3 Mon Sep 17 00:00:00 2001 From: Dmitry Zagorodnev Date: Wed, 15 Mar 2023 09:35:59 +0300 Subject: [PATCH 5/6] Fix: replace fakeMarginSize() -> marginSize() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * В алгоритмах расчета размеров объекта использовалась функция fakeMarginSize() увеличивающая отступы на 5px. --- limereport/items/lrtextitem.cpp | 26 +++++++++++--------------- limereport/items/lrtextitem.h | 1 - 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/limereport/items/lrtextitem.cpp b/limereport/items/lrtextitem.cpp index 4cec5f9..b293495 100644 --- a/limereport/items/lrtextitem.cpp +++ b/limereport/items/lrtextitem.cpp @@ -77,10 +77,6 @@ TextItem::TextItem(QObject *owner, QGraphicsItem *parent) TextItem::~TextItem(){} -int TextItem::fakeMarginSize() const{ - return marginSize()/*+5*/; -} - void TextItem::preparePopUpMenu(QMenu &menu) { QAction* editAction = menu.addAction(QIcon(":/report/images/edit_pecil2.png"),tr("Edit")); @@ -180,7 +176,7 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q qreal hOffset = 0, vOffset = 0; switch (m_angle){ case Angle0: - hOffset = fakeMarginSize(); + hOffset = marginSize(); if ((tmpSize.height() > 0) && (m_alignment & Qt::AlignVCenter)){ vOffset = tmpSize.height() / 2; } @@ -189,8 +185,8 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q painter->translate(hOffset,vOffset); break; case Angle90: - hOffset = width() - fakeMarginSize(); - vOffset = fakeMarginSize(); + hOffset = width() - marginSize(); + vOffset = marginSize(); if (m_alignment & Qt::AlignVCenter){ hOffset = (width() - text->size().height()) / 2 + text->size().height(); } @@ -202,8 +198,8 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q painter->rotate(90); break; case Angle180: - hOffset = width() - fakeMarginSize(); - vOffset = height() - fakeMarginSize(); + hOffset = width() - marginSize(); + vOffset = height() - marginSize(); if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){ vOffset = tmpSize.height() / 2+ text->size().height(); } @@ -214,8 +210,8 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q painter->rotate(180); break; case Angle270: - hOffset = fakeMarginSize(); - vOffset = height()-fakeMarginSize(); + hOffset = marginSize(); + vOffset = height()-marginSize(); if (m_alignment & Qt::AlignVCenter){ hOffset = (width() - text->size().height())/2; } @@ -321,7 +317,7 @@ void TextItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, i initTextSizes(); if (m_textSize.width()>width() && ((m_autoWidth==MaxWordLength)||(m_autoWidth==MaxStringLength))){ - setWidth(m_textSize.width() + fakeMarginSize()*2); + setWidth(m_textSize.width() + marginSize()*2); } if (m_textSize.height()>height()) { @@ -380,9 +376,9 @@ QString TextItem::replaceReturns(QString text) const void TextItem::setTextFont(TextPtr text, const QFont& value) const { text->setDefaultFont(value); if ((m_angle==Angle0)||(m_angle==Angle180)){ - text->setTextWidth(rect().width()-fakeMarginSize()*2); + text->setTextWidth(rect().width()-marginSize()*2); } else { - text->setTextWidth(rect().height()-fakeMarginSize()*2); + text->setTextWidth(rect().height()-marginSize()*2); } } @@ -394,7 +390,7 @@ void TextItem::adaptFontSize(TextPtr text) const{ if (_font.pixelSize()>2) _font.setPixelSize(_font.pixelSize()-1); else break; - } while(text->size().height()>this->height() || text->size().width()>(this->width()) - fakeMarginSize() * 2); + } while(text->size().height()>this->height() || text->size().width()>(this->width()) - marginSize() * 2); } int TextItem::underlineLineSize() const diff --git a/limereport/items/lrtextitem.h b/limereport/items/lrtextitem.h index 0d63415..a64142e 100644 --- a/limereport/items/lrtextitem.h +++ b/limereport/items/lrtextitem.h @@ -192,7 +192,6 @@ protected: bool isNeedExpandContent() const; QString replaceBR(QString text) const; QString replaceReturns(QString text) const; - int fakeMarginSize() const; QString getTextPart(int height, int skipHeight); void restoreLinksEvent(); void preparePopUpMenu(QMenu &menu); From 4c1c0c49e682cdecfc210b675ac72d893374ee3f Mon Sep 17 00:00:00 2001 From: Dmitry Zagorodnev Date: Tue, 26 Mar 2024 11:43:58 +0300 Subject: [PATCH 6/6] 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 --- limereport/lrdatadesignintf.cpp | 43 +++++++++++ limereport/lrdatadesignintf.h | 7 ++ limereport/lrdatasourceintf.h | 3 + limereport/lrdatasourcemanager.cpp | 52 +++++++++++++ limereport/lrdatasourcemanager.h | 5 ++ limereport/lrscriptenginemanager.cpp | 108 +++++++++++++++++++++++++++ limereport/lrscriptenginemanager.h | 43 +++++++++++ 7 files changed, 261 insertions(+) diff --git a/limereport/lrdatadesignintf.cpp b/limereport/lrdatadesignintf.cpp index 0315c27..f7b3aa2 100644 --- a/limereport/lrdatadesignintf.cpp +++ b/limereport/lrdatadesignintf.cpp @@ -272,6 +272,24 @@ QVariant ModelToDataSource::dataByRowIndex(const QString &columnName, int rowInd return QVariant(); } +QVariant ModelToDataSource::dataByRowIndex(const QString &columnName, int rowIndex, int roleName) +{ + if(m_model->rowCount() > rowIndex) + return m_model->data(m_model->index(rowIndex, columnIndexByName(columnName))); + return QVariant(); +} + +QVariant ModelToDataSource::dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName) +{ + if(m_model->rowCount() > rowIndex) { + int roleCode{roleName.isEmpty() ? Qt::DisplayRole + : m_model->roleNames().key(roleName.toUtf8(), Qt::DisplayRole)}; + return m_model->data(m_model->index(rowIndex, columnIndexByName(columnName)), roleCode); + } + + return QVariant(); +} + QVariant ModelToDataSource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) { for( int i=0; i < m_model->rowCount(); ++i ){ @@ -310,6 +328,13 @@ int ModelToDataSource::columnIndexByName(QString name) return -1; } +QVariant ModelToDataSource::headerData(const QString &columnName, const QString &roleName) +{ + int roleCode{roleName.isEmpty() ? Qt::DisplayRole + : m_model->roleNames().key(roleName.toUtf8(), Qt::DisplayRole)}; + return m_model->headerData(columnIndexByName(columnName), Qt::Horizontal, roleCode); +} + QString ModelToDataSource::lastError() { return m_lastError; @@ -722,6 +747,18 @@ QVariant CallbackDatasource::dataByRowIndex(const QString &columnName, int rowIn return result; } +QVariant CallbackDatasource::dataByRowIndex(const QString &columnName, int rowIndex, int roleName) +{ + Q_UNUSED(roleName) + return dataByRowIndex(columnName, rowIndex); +} + +QVariant CallbackDatasource::dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName) +{ + Q_UNUSED(roleName) + return dataByRowIndex(columnName, rowIndex); +} + QVariant CallbackDatasource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) { int backupCurrentRow = m_currentRow; @@ -816,6 +853,12 @@ int CallbackDatasource::columnIndexByName(QString name) return -1; } +QVariant CallbackDatasource::headerData(const QString &columnName, const QString &roleName) +{ + Q_UNUSED(roleName) + return columnName; // STUB +} + bool CallbackDatasource::checkNextRecord(int recordNum){ if (bof()) checkIfEmpty(); if (m_rowCount > 0) { diff --git a/limereport/lrdatadesignintf.h b/limereport/lrdatadesignintf.h index f76de85..f070f7a 100644 --- a/limereport/lrdatadesignintf.h +++ b/limereport/lrdatadesignintf.h @@ -388,10 +388,13 @@ public: bool bof(); QVariant data(const QString& columnName); QVariant dataByRowIndex(const QString &columnName, int rowIndex); + QVariant dataByRowIndex(const QString &columnName, int rowIndex, int roleName); + QVariant dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName); QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData); int columnCount(); QString columnNameByIndex(int columnIndex); int columnIndexByName(QString name); + QVariant headerData(const QString &columnName, const QString &roleName); QString lastError(); virtual QAbstractItemModel* model(); int currentRow(); @@ -421,6 +424,8 @@ public: bool eof(){return m_eof;} QVariant data(const QString &columnName); QVariant dataByRowIndex(const QString& columnName, int rowIndex); + QVariant dataByRowIndex(const QString &columnName, int rowIndex, int roleName); + QVariant dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName); QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData); int columnCount(); QString columnNameByIndex(int columnIndex); @@ -428,6 +433,7 @@ public: bool isInvalid() const{ return false;} QString lastError(){ return "";} QAbstractItemModel *model(){return 0;} + QVariant headerData(const QString &columnName, const QString &roleName); private: bool checkNextRecord(int recordNum); bool checkIfEmpty(); @@ -441,6 +447,7 @@ private: QHash m_valuesCache; bool m_getDataFromCache; int m_lastKeyRow; + }; class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{ diff --git a/limereport/lrdatasourceintf.h b/limereport/lrdatasourceintf.h index 26f7a65..481787c 100644 --- a/limereport/lrdatasourceintf.h +++ b/limereport/lrdatasourceintf.h @@ -18,9 +18,12 @@ public: virtual bool eof() = 0; virtual QVariant data(const QString& columnName) = 0; virtual QVariant dataByRowIndex(const QString& columnName, int rowIndex) = 0; + virtual QVariant dataByRowIndex(const QString &columnName, int rowIndex, int roleName) = 0; + virtual QVariant dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName) = 0; virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0; virtual int columnCount() = 0; virtual QString columnNameByIndex(int columnIndex) = 0; + virtual QVariant headerData(const QString &columnName, const QString &roleName) = 0; virtual int columnIndexByName(QString name) = 0; virtual bool isInvalid() const = 0; virtual QString lastError() = 0; diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 91f1189..a532c1e 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -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(dataSourceHolder(datasourceName)); diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index f870b77..7e94be9 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -173,12 +173,17 @@ public: bool containsField(const QString& fieldName); QVariant fieldData(const QString& fieldName); QVariant fieldDataByRowIndex(const QString& fieldName, int rowIndex); + QVariant fieldDataByRowIndex(const QString &fieldName, int rowIndex, int role); + QVariant fieldDataByRowIndex(const QString &fieldName, int rowIndex, const QString &roleName); QVariant fieldDataByKey( const QString& datasourceName, const QString& valueFieldName, const QString& keyFieldName, QVariant keyValue ); + QVariant headerData(const QString &fieldName, const QString &roleName); + QString columnName(const QString &datasourceName, int index); + int columnCount(const QString &datasourceName); void reopenDatasource(const QString& datasourceName); QString extractDataSource(const QString& fieldName); diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index 31220d3..c940f8b 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -1073,6 +1073,79 @@ bool ScriptEngineManager::createReopenDatasourceFunction() return addFunction(fd); } +bool ScriptEngineManager::createGetFieldByRowIndexEx() +{ + JSFunctionDesc fd; + fd.setManager(m_functionManager); + fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME); + fd.setCategory(tr("GENERAL")); + fd.setName("getFieldByRowIndexEx"); + fd.setDescription("getFieldByRowIndexEx(\"" + tr("FieldName") + "\", \"" + tr("RowIndex") + + "\", \"" + tr("RoleIndex") + "\")"); + fd.setScriptWrapper(QString("function getFieldByRowIndexEx(fieldName, rowIndex, role){" + "return %1.getFieldByRowIndexEx(fieldName, rowIndex, role);}") + .arg(LimeReport::Const::FUNCTION_MANAGER_NAME)); + return addFunction(fd); +} + +bool ScriptEngineManager::createGetFieldByRowIndexEx2() +{ + JSFunctionDesc fd; + fd.setManager(m_functionManager); + fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME); + fd.setCategory(tr("GENERAL")); + fd.setName("getFieldByRowIndexEx2"); + fd.setDescription("getFieldByRowIndexEx2(\"" + tr("FieldName") + "\", \"" + tr("RowIndex") + + "\", \"" + tr("RoleName") + "\")"); + fd.setScriptWrapper(QString("function getFieldByRowIndexEx2(fieldName, rowIndex, role){" + "return %1.getFieldByRowIndexEx2(fieldName, rowIndex, role);}") + .arg(LimeReport::Const::FUNCTION_MANAGER_NAME)); + return addFunction(fd); +} + +bool ScriptEngineManager::createHeaderData() +{ + JSFunctionDesc fd; + fd.setManager(m_functionManager); + fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME); + fd.setCategory(tr("GENERAL")); + fd.setName("getHeaderData"); + fd.setDescription("getHeaderData(\"" + tr("FieldName") + "\", \"" + tr("RoleName") + "\")"); + fd.setScriptWrapper(QString("function getHeaderData(fieldName, role){" + "return %1.getHeaderData(fieldName, role);}") + .arg(LimeReport::Const::FUNCTION_MANAGER_NAME)); + return addFunction(fd); +} + +bool ScriptEngineManager::createHeaderColumnNameByIndex() +{ + JSFunctionDesc fd; + fd.setManager(m_functionManager); + fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME); + fd.setCategory(tr("GENERAL")); + fd.setName("getHeaderColumnNameByIndex"); + fd.setDescription("getHeaderColumnNameByIndex(\"" + tr("datasourceName") + "\", \"" + + tr("columnIndex") + "\")"); + fd.setScriptWrapper(QString("function getHeaderColumnNameByIndex(datasourceName, columnIndex){" + "return %1.getHeaderColumnNameByIndex(datasourceName, columnIndex);}") + .arg(LimeReport::Const::FUNCTION_MANAGER_NAME)); + return addFunction(fd); +} + +bool ScriptEngineManager::createColumnCount() +{ + JSFunctionDesc fd; + fd.setManager(m_functionManager); + fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME); + fd.setCategory(tr("GENERAL")); + fd.setName("getColumnCount"); + fd.setDescription("getColumnCount(\"" + tr("datasourceName") + "\")"); + fd.setScriptWrapper(QString("function getColumnCount(datasourceName){" + "return %1.getColumnCount(datasourceName);}") + .arg(LimeReport::Const::FUNCTION_MANAGER_NAME)); + return addFunction(fd); +} + ScriptEngineManager::ScriptEngineManager() :m_model(0), m_context(0), m_dataManager(0) { @@ -1114,6 +1187,11 @@ ScriptEngineManager::ScriptEngineManager() createAddTableOfContentsItemFunction(); createClearTableOfContentsFunction(); createReopenDatasourceFunction(); + createGetFieldByRowIndexEx(); + createGetFieldByRowIndexEx2(); + createHeaderData(); + createHeaderColumnNameByIndex(); + createColumnCount(); m_model = new ScriptEngineModel(this); } @@ -1866,6 +1944,36 @@ QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool it return result; } +QVariant ScriptFunctionsManager::getFieldByRowIndexEx(const QString &fieldName, int rowIndex, const int role) +{ + DataSourceManager *dm = scriptEngineManager()->dataManager(); + return dm->fieldDataByRowIndex(fieldName, rowIndex, role); +} + +QVariant ScriptFunctionsManager::getFieldByRowIndexEx2(const QString &fieldName, int rowIndex, const QString &roleName) +{ + DataSourceManager *dm = scriptEngineManager()->dataManager(); + return dm->fieldDataByRowIndex(fieldName, rowIndex, roleName); +} + +QVariant ScriptFunctionsManager::getHeaderData(const QString &fieldName, const QString &roleName) +{ + DataSourceManager *dm = scriptEngineManager()->dataManager(); + return dm->headerData(fieldName, roleName); +} + +QVariant ScriptFunctionsManager::getHeaderColumnNameByIndex(const QString &datasourceName, const int columnIndex) +{ + DataSourceManager *dm = scriptEngineManager()->dataManager(); + return dm->columnName(datasourceName, columnIndex); +} + +int ScriptFunctionsManager::getColumnCount(const QString &datasourceName) +{ + DataSourceManager *dm = scriptEngineManager()->dataManager(); + return dm->columnCount(datasourceName); +} + #ifdef USE_QJSENGINE void ScriptFunctionsManager::addItemsToComboBox(QJSValue object, const QStringList &values) diff --git a/limereport/lrscriptenginemanager.h b/limereport/lrscriptenginemanager.h index d027a1a..1763190 100644 --- a/limereport/lrscriptenginemanager.h +++ b/limereport/lrscriptenginemanager.h @@ -378,6 +378,43 @@ public: Q_INVOKABLE void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent = 0); Q_INVOKABLE void clearTableOfContents(); Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false); + /*! + * \brief getFieldByRowIndexEx Выдает для поля значение заданной роли + * \param fieldName имя источника данных + имя поля + * \param rowIndex индекс строки + * \param role код роли + * \return + */ + Q_INVOKABLE QVariant getFieldByRowIndexEx(const QString &fieldName, int rowIndex, const int role); + /*! + * \brief getFieldByRowIndexEx2 Выдает для поля значение заданной роли + * \param fieldName имя источника данных + имя поля + * \param rowIndex индекс строки + * \param roleName имя роли из roleNames() + * \return + */ + Q_INVOKABLE QVariant getFieldByRowIndexEx2(const QString &fieldName, int rowIndex, const QString &roleName); + /*! + * \brief getHeaderData Выдает для поля заголовка значение заданной роли + * \param fieldName имя источника данных + имя поля + * \param role имя роли из roleNames() + * \return + */ + Q_INVOKABLE QVariant getHeaderData(const QString &fieldName, const QString &roleName); + /*! + * \brief getHeaderColumnNameByIndex Выдает имя колонки по ее индексу (имя используемое LR) + * \param datasourceName имя источника данных + * \param columnIndex индекс колонки + * \return + */ + Q_INVOKABLE QVariant getHeaderColumnNameByIndex(const QString &datasourceName, const int columnIndex); + /*! + * \brief getColumnCount Выдает число столбцов в источнике данных + * \param datasourceName имя источника данных + * \return возможно -1 при ошибке + */ + Q_INVOKABLE int getColumnCount(const QString &datasourceName); + #ifdef USE_QJSENGINE Q_INVOKABLE void addItemsToComboBox(QJSValue object, const QStringList& values); Q_INVOKABLE void addItemToComboBox(QJSValue object, const QString& value); @@ -506,6 +543,12 @@ private: bool createAddTableOfContentsItemFunction(); bool createClearTableOfContentsFunction(); bool createReopenDatasourceFunction(); + bool createGetFieldByRowIndexEx(); + bool createGetFieldByRowIndexEx2(); + bool createHeaderData(); + bool createHeaderColumnNameByIndex(); + bool createColumnCount(); + private: ScriptEngineManager(); ScriptEngineType* m_scriptEngine;