mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-23 16:22:58 +03:00
Merge pull request #452 from DmitryZagorodnev/feature/dataRoles
Feature/data roles
This commit is contained in:
commit
5139ac0ab0
@ -77,10 +77,6 @@ TextItem::TextItem(QObject *owner, QGraphicsItem *parent)
|
|||||||
|
|
||||||
TextItem::~TextItem(){}
|
TextItem::~TextItem(){}
|
||||||
|
|
||||||
int TextItem::fakeMarginSize() const{
|
|
||||||
return marginSize()+5;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextItem::preparePopUpMenu(QMenu &menu)
|
void TextItem::preparePopUpMenu(QMenu &menu)
|
||||||
{
|
{
|
||||||
QAction* editAction = menu.addAction(QIcon(":/report/images/edit_pecil2.png"),tr("Edit"));
|
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;
|
qreal hOffset = 0, vOffset = 0;
|
||||||
switch (m_angle){
|
switch (m_angle){
|
||||||
case Angle0:
|
case Angle0:
|
||||||
hOffset = fakeMarginSize();
|
hOffset = marginSize();
|
||||||
if ((tmpSize.height() > 0) && (m_alignment & Qt::AlignVCenter)){
|
if ((tmpSize.height() > 0) && (m_alignment & Qt::AlignVCenter)){
|
||||||
vOffset = tmpSize.height() / 2;
|
vOffset = tmpSize.height() / 2;
|
||||||
}
|
}
|
||||||
@ -189,8 +185,8 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
|
|||||||
painter->translate(hOffset,vOffset);
|
painter->translate(hOffset,vOffset);
|
||||||
break;
|
break;
|
||||||
case Angle90:
|
case Angle90:
|
||||||
hOffset = width() - fakeMarginSize();
|
hOffset = width() - marginSize();
|
||||||
vOffset = fakeMarginSize();
|
vOffset = marginSize();
|
||||||
if (m_alignment & Qt::AlignVCenter){
|
if (m_alignment & Qt::AlignVCenter){
|
||||||
hOffset = (width() - text->size().height()) / 2 + text->size().height();
|
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);
|
painter->rotate(90);
|
||||||
break;
|
break;
|
||||||
case Angle180:
|
case Angle180:
|
||||||
hOffset = width() - fakeMarginSize();
|
hOffset = width() - marginSize();
|
||||||
vOffset = height() - fakeMarginSize();
|
vOffset = height() - marginSize();
|
||||||
if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){
|
if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){
|
||||||
vOffset = tmpSize.height() / 2+ text->size().height();
|
vOffset = tmpSize.height() / 2+ text->size().height();
|
||||||
}
|
}
|
||||||
@ -214,8 +210,8 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
|
|||||||
painter->rotate(180);
|
painter->rotate(180);
|
||||||
break;
|
break;
|
||||||
case Angle270:
|
case Angle270:
|
||||||
hOffset = fakeMarginSize();
|
hOffset = marginSize();
|
||||||
vOffset = height()-fakeMarginSize();
|
vOffset = height()-marginSize();
|
||||||
if (m_alignment & Qt::AlignVCenter){
|
if (m_alignment & Qt::AlignVCenter){
|
||||||
hOffset = (width() - text->size().height())/2;
|
hOffset = (width() - text->size().height())/2;
|
||||||
}
|
}
|
||||||
@ -321,7 +317,7 @@ void TextItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, i
|
|||||||
initTextSizes();
|
initTextSizes();
|
||||||
|
|
||||||
if (m_textSize.width()>width() && ((m_autoWidth==MaxWordLength)||(m_autoWidth==MaxStringLength))){
|
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()) {
|
if (m_textSize.height()>height()) {
|
||||||
@ -380,9 +376,9 @@ QString TextItem::replaceReturns(QString text) const
|
|||||||
void TextItem::setTextFont(TextPtr text, const QFont& value) const {
|
void TextItem::setTextFont(TextPtr text, const QFont& value) const {
|
||||||
text->setDefaultFont(value);
|
text->setDefaultFont(value);
|
||||||
if ((m_angle==Angle0)||(m_angle==Angle180)){
|
if ((m_angle==Angle0)||(m_angle==Angle180)){
|
||||||
text->setTextWidth(rect().width()-fakeMarginSize()*2);
|
text->setTextWidth(rect().width()-marginSize()*2);
|
||||||
} else {
|
} 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)
|
if (_font.pixelSize()>2)
|
||||||
_font.setPixelSize(_font.pixelSize()-1);
|
_font.setPixelSize(_font.pixelSize()-1);
|
||||||
else break;
|
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
|
int TextItem::underlineLineSize() const
|
||||||
|
@ -192,7 +192,6 @@ protected:
|
|||||||
bool isNeedExpandContent() const;
|
bool isNeedExpandContent() const;
|
||||||
QString replaceBR(QString text) const;
|
QString replaceBR(QString text) const;
|
||||||
QString replaceReturns(QString text) const;
|
QString replaceReturns(QString text) const;
|
||||||
int fakeMarginSize() const;
|
|
||||||
QString getTextPart(int height, int skipHeight);
|
QString getTextPart(int height, int skipHeight);
|
||||||
void restoreLinksEvent();
|
void restoreLinksEvent();
|
||||||
void preparePopUpMenu(QMenu &menu);
|
void preparePopUpMenu(QMenu &menu);
|
||||||
|
@ -272,6 +272,24 @@ QVariant ModelToDataSource::dataByRowIndex(const QString &columnName, int rowInd
|
|||||||
return QVariant();
|
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)
|
QVariant ModelToDataSource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData)
|
||||||
{
|
{
|
||||||
for( int i=0; i < m_model->rowCount(); ++i ){
|
for( int i=0; i < m_model->rowCount(); ++i ){
|
||||||
@ -310,6 +328,13 @@ int ModelToDataSource::columnIndexByName(QString name)
|
|||||||
return -1;
|
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()
|
QString ModelToDataSource::lastError()
|
||||||
{
|
{
|
||||||
return m_lastError;
|
return m_lastError;
|
||||||
@ -722,6 +747,18 @@ QVariant CallbackDatasource::dataByRowIndex(const QString &columnName, int rowIn
|
|||||||
return result;
|
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)
|
QVariant CallbackDatasource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData)
|
||||||
{
|
{
|
||||||
int backupCurrentRow = m_currentRow;
|
int backupCurrentRow = m_currentRow;
|
||||||
@ -816,6 +853,12 @@ int CallbackDatasource::columnIndexByName(QString name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant CallbackDatasource::headerData(const QString &columnName, const QString &roleName)
|
||||||
|
{
|
||||||
|
Q_UNUSED(roleName)
|
||||||
|
return columnName; // STUB
|
||||||
|
}
|
||||||
|
|
||||||
bool CallbackDatasource::checkNextRecord(int recordNum){
|
bool CallbackDatasource::checkNextRecord(int recordNum){
|
||||||
if (bof()) checkIfEmpty();
|
if (bof()) checkIfEmpty();
|
||||||
if (m_rowCount > 0) {
|
if (m_rowCount > 0) {
|
||||||
|
@ -388,10 +388,13 @@ public:
|
|||||||
bool bof();
|
bool bof();
|
||||||
QVariant data(const QString& columnName);
|
QVariant data(const QString& columnName);
|
||||||
QVariant dataByRowIndex(const QString &columnName, int rowIndex);
|
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);
|
QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData);
|
||||||
int columnCount();
|
int columnCount();
|
||||||
QString columnNameByIndex(int columnIndex);
|
QString columnNameByIndex(int columnIndex);
|
||||||
int columnIndexByName(QString name);
|
int columnIndexByName(QString name);
|
||||||
|
QVariant headerData(const QString &columnName, const QString &roleName);
|
||||||
QString lastError();
|
QString lastError();
|
||||||
virtual QAbstractItemModel* model();
|
virtual QAbstractItemModel* model();
|
||||||
int currentRow();
|
int currentRow();
|
||||||
@ -421,6 +424,8 @@ public:
|
|||||||
bool eof(){return m_eof;}
|
bool eof(){return m_eof;}
|
||||||
QVariant data(const QString &columnName);
|
QVariant data(const QString &columnName);
|
||||||
QVariant dataByRowIndex(const QString& columnName, int rowIndex);
|
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);
|
QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData);
|
||||||
int columnCount();
|
int columnCount();
|
||||||
QString columnNameByIndex(int columnIndex);
|
QString columnNameByIndex(int columnIndex);
|
||||||
@ -428,6 +433,7 @@ public:
|
|||||||
bool isInvalid() const{ return false;}
|
bool isInvalid() const{ return false;}
|
||||||
QString lastError(){ return "";}
|
QString lastError(){ return "";}
|
||||||
QAbstractItemModel *model(){return 0;}
|
QAbstractItemModel *model(){return 0;}
|
||||||
|
QVariant headerData(const QString &columnName, const QString &roleName);
|
||||||
private:
|
private:
|
||||||
bool checkNextRecord(int recordNum);
|
bool checkNextRecord(int recordNum);
|
||||||
bool checkIfEmpty();
|
bool checkIfEmpty();
|
||||||
@ -441,6 +447,7 @@ private:
|
|||||||
QHash<QString, QVariant> m_valuesCache;
|
QHash<QString, QVariant> m_valuesCache;
|
||||||
bool m_getDataFromCache;
|
bool m_getDataFromCache;
|
||||||
int m_lastKeyRow;
|
int m_lastKeyRow;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{
|
class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{
|
||||||
|
@ -18,9 +18,12 @@ public:
|
|||||||
virtual bool eof() = 0;
|
virtual bool eof() = 0;
|
||||||
virtual QVariant data(const QString& columnName) = 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) = 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 QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0;
|
||||||
virtual int columnCount() = 0;
|
virtual int columnCount() = 0;
|
||||||
virtual QString columnNameByIndex(int columnIndex) = 0;
|
virtual QString columnNameByIndex(int columnIndex) = 0;
|
||||||
|
virtual QVariant headerData(const QString &columnName, const QString &roleName) = 0;
|
||||||
virtual int columnIndexByName(QString name) = 0;
|
virtual int columnIndexByName(QString name) = 0;
|
||||||
virtual bool isInvalid() const = 0;
|
virtual bool isInvalid() const = 0;
|
||||||
virtual QString lastError() = 0;
|
virtual QString lastError() = 0;
|
||||||
|
@ -1689,6 +1689,28 @@ QVariant DataSourceManager::fieldDataByRowIndex(const QString &fieldName, int ro
|
|||||||
return QVariant();
|
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)
|
QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const QString& valueFieldName, const QString& keyFieldName, QVariant keyValue)
|
||||||
{
|
{
|
||||||
IDataSource* ds = dataSource(datasourceName);
|
IDataSource* ds = dataSource(datasourceName);
|
||||||
@ -1698,6 +1720,36 @@ QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const
|
|||||||
return QVariant();
|
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)
|
void DataSourceManager::reopenDatasource(const QString& datasourceName)
|
||||||
{
|
{
|
||||||
QueryHolder* qh = dynamic_cast<QueryHolder*>(dataSourceHolder(datasourceName));
|
QueryHolder* qh = dynamic_cast<QueryHolder*>(dataSourceHolder(datasourceName));
|
||||||
|
@ -173,12 +173,17 @@ public:
|
|||||||
bool containsField(const QString& fieldName);
|
bool containsField(const QString& fieldName);
|
||||||
QVariant fieldData(const QString& fieldName);
|
QVariant fieldData(const QString& fieldName);
|
||||||
QVariant fieldDataByRowIndex(const QString& fieldName, int rowIndex);
|
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(
|
QVariant fieldDataByKey(
|
||||||
const QString& datasourceName,
|
const QString& datasourceName,
|
||||||
const QString& valueFieldName,
|
const QString& valueFieldName,
|
||||||
const QString& keyFieldName,
|
const QString& keyFieldName,
|
||||||
QVariant keyValue
|
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);
|
void reopenDatasource(const QString& datasourceName);
|
||||||
|
|
||||||
QString extractDataSource(const QString& fieldName);
|
QString extractDataSource(const QString& fieldName);
|
||||||
|
@ -1073,6 +1073,79 @@ bool ScriptEngineManager::createReopenDatasourceFunction()
|
|||||||
return addFunction(fd);
|
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()
|
ScriptEngineManager::ScriptEngineManager()
|
||||||
:m_model(0), m_context(0), m_dataManager(0)
|
:m_model(0), m_context(0), m_dataManager(0)
|
||||||
{
|
{
|
||||||
@ -1114,6 +1187,11 @@ ScriptEngineManager::ScriptEngineManager()
|
|||||||
createAddTableOfContentsItemFunction();
|
createAddTableOfContentsItemFunction();
|
||||||
createClearTableOfContentsFunction();
|
createClearTableOfContentsFunction();
|
||||||
createReopenDatasourceFunction();
|
createReopenDatasourceFunction();
|
||||||
|
createGetFieldByRowIndexEx();
|
||||||
|
createGetFieldByRowIndexEx2();
|
||||||
|
createHeaderData();
|
||||||
|
createHeaderColumnNameByIndex();
|
||||||
|
createColumnCount();
|
||||||
|
|
||||||
m_model = new ScriptEngineModel(this);
|
m_model = new ScriptEngineModel(this);
|
||||||
}
|
}
|
||||||
@ -1866,6 +1944,36 @@ QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool it
|
|||||||
return result;
|
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
|
#ifdef USE_QJSENGINE
|
||||||
|
|
||||||
void ScriptFunctionsManager::addItemsToComboBox(QJSValue object, const QStringList &values)
|
void ScriptFunctionsManager::addItemsToComboBox(QJSValue object, const QStringList &values)
|
||||||
|
@ -378,6 +378,43 @@ public:
|
|||||||
Q_INVOKABLE void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent = 0);
|
Q_INVOKABLE void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent = 0);
|
||||||
Q_INVOKABLE void clearTableOfContents();
|
Q_INVOKABLE void clearTableOfContents();
|
||||||
Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false);
|
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
|
#ifdef USE_QJSENGINE
|
||||||
Q_INVOKABLE void addItemsToComboBox(QJSValue object, const QStringList& values);
|
Q_INVOKABLE void addItemsToComboBox(QJSValue object, const QStringList& values);
|
||||||
Q_INVOKABLE void addItemToComboBox(QJSValue object, const QString& value);
|
Q_INVOKABLE void addItemToComboBox(QJSValue object, const QString& value);
|
||||||
@ -506,6 +543,12 @@ private:
|
|||||||
bool createAddTableOfContentsItemFunction();
|
bool createAddTableOfContentsItemFunction();
|
||||||
bool createClearTableOfContentsFunction();
|
bool createClearTableOfContentsFunction();
|
||||||
bool createReopenDatasourceFunction();
|
bool createReopenDatasourceFunction();
|
||||||
|
bool createGetFieldByRowIndexEx();
|
||||||
|
bool createGetFieldByRowIndexEx2();
|
||||||
|
bool createHeaderData();
|
||||||
|
bool createHeaderColumnNameByIndex();
|
||||||
|
bool createColumnCount();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScriptEngineManager();
|
ScriptEngineManager();
|
||||||
ScriptEngineType* m_scriptEngine;
|
ScriptEngineType* m_scriptEngine;
|
||||||
|
@ -22,16 +22,17 @@ QModelIndex CompleterModel::index(int row, int column, const QModelIndex &parent
|
|||||||
return createIndex(row, column, parentItem->child(row));
|
return createIndex(row, column, parentItem->child(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex CompleterModel::parent(const QModelIndex &child) const
|
QModelIndex CompleterModel::parent(const QModelIndex &child) const {
|
||||||
{
|
if(child.isValid()) {
|
||||||
if (child.isValid()){
|
if(CompleterItem *childItem = static_cast<CompleterItem *>(child.internalPointer());
|
||||||
CompleterItem *childItem = static_cast<CompleterItem*>(child.internalPointer());
|
childItem) {
|
||||||
CompleterItem *parentItem = childItem->parent();
|
CompleterItem *parentItem = childItem->parent();
|
||||||
if (parentItem != &m_root) {
|
if(parentItem != &m_root) {
|
||||||
return indexFromItem(parentItem);
|
return indexFromItem(parentItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QModelIndex();
|
}
|
||||||
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CompleterModel::rowCount(const QModelIndex &parent) const
|
int CompleterModel::rowCount(const QModelIndex &parent) const
|
||||||
|
@ -12,7 +12,9 @@ public:
|
|||||||
CompleterItem(QString text, QIcon icon):m_parent(0), m_text(text), m_icon(icon), m_model(0){}
|
CompleterItem(QString text, QIcon icon):m_parent(0), m_text(text), m_icon(icon), m_model(0){}
|
||||||
~CompleterItem();
|
~CompleterItem();
|
||||||
int rowCount() const {return m_children.count();}
|
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;}
|
CompleterItem* parent() const {return m_parent;}
|
||||||
int row() const{
|
int row() const{
|
||||||
if (m_parent){
|
if (m_parent){
|
||||||
@ -33,7 +35,7 @@ public:
|
|||||||
void appendRow(CompleterItem* child);
|
void appendRow(CompleterItem* child);
|
||||||
void appendRows(const QList<CompleterItem *> &children);
|
void appendRows(const QList<CompleterItem *> &children);
|
||||||
private:
|
private:
|
||||||
CompleterItem* m_parent;
|
CompleterItem* m_parent{nullptr};
|
||||||
QVector<QSharedPointer<CompleterItem> > m_children;
|
QVector<QSharedPointer<CompleterItem> > m_children;
|
||||||
QString m_text;
|
QString m_text;
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
|
Loading…
Reference in New Issue
Block a user