mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-01-11 20:31:04 +03:00
addBookmark() && findPageIndexByBookmark() have been added to the script
This commit is contained in:
parent
c475159799
commit
5f56f36a49
@ -1191,6 +1191,7 @@ ReportPages ReportEnginePrivate::renderToPages()
|
|||||||
|
|
||||||
activateLanguage(m_reportLanguage);
|
activateLanguage(m_reportLanguage);
|
||||||
emit renderStarted();
|
emit renderStarted();
|
||||||
|
m_scriptEngineContext->setReportPages(&result);
|
||||||
|
|
||||||
for(int i = 0; i < m_renderingPages.count(); ++i){
|
for(int i = 0; i < m_renderingPages.count(); ++i){
|
||||||
PageItemDesignIntf* page = m_renderingPages.at(i);
|
PageItemDesignIntf* page = m_renderingPages.at(i);
|
||||||
|
@ -545,18 +545,39 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngineManager::addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent)
|
void ScriptEngineManager::addBookMark(const QString& uniqKey, const QString& content){
|
||||||
{
|
|
||||||
Q_ASSERT(m_context != 0);
|
Q_ASSERT(m_context != 0);
|
||||||
if (m_context){
|
if (m_context){
|
||||||
BandDesignIntf* currentBand = m_context->getCurrentBand();
|
BandDesignIntf* currentBand = m_context->getCurrentBand();
|
||||||
m_context->tableOfContents()->setItem(uniqKey, content, 0, indent);
|
|
||||||
if (currentBand)
|
if (currentBand)
|
||||||
currentBand->addBookmark(uniqKey, content);
|
currentBand->addBookmark(uniqKey, content);
|
||||||
else if (m_context->getCurrentPage()) {
|
else if (m_context->getCurrentPage()) {
|
||||||
m_context->getCurrentPage()->addBookmark(uniqKey, content);
|
m_context->getCurrentPage()->addBookmark(uniqKey, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScriptEngineManager::findPageIndexByBookmark(const QString &uniqKey)
|
||||||
|
{
|
||||||
|
for (int i=0; i < m_context->reportPages()->size(); ++i){
|
||||||
|
if (m_context->reportPages()->at(i)->bookmarks().contains(uniqKey))
|
||||||
|
return i+1;
|
||||||
|
foreach(BandDesignIntf* band, m_context->reportPages()->at(i)->bands()){
|
||||||
|
if (band->bookmarks().contains(uniqKey))
|
||||||
|
return i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptEngineManager::addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent)
|
||||||
|
{
|
||||||
|
Q_ASSERT(m_context != 0);
|
||||||
|
if (m_context){
|
||||||
|
m_context->tableOfContents()->setItem(uniqKey, content, 0, indent);
|
||||||
|
addBookMark(uniqKey, content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngineManager::clearTableOfContents(){
|
void ScriptEngineManager::clearTableOfContents(){
|
||||||
@ -835,6 +856,36 @@ bool ScriptEngineManager::createGetFieldByRowIndex()
|
|||||||
return addFunction(fd);
|
return addFunction(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptEngineManager::createAddBookmarkFunction()
|
||||||
|
{
|
||||||
|
JSFunctionDesc fd;
|
||||||
|
fd.setManager(m_functionManager);
|
||||||
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
||||||
|
fd.setCategory(tr("GENERAL"));
|
||||||
|
fd.setName("addBookmark");
|
||||||
|
fd.setDescription("addBookmark(\""+tr("Unique identifier")+" \""+tr("Content")+"\")");
|
||||||
|
fd.setScriptWrapper(QString("function addBookmark(uniqKey, content){"
|
||||||
|
"return %1.addBookmark(uniqKey, content);}"
|
||||||
|
).arg(LimeReport::Const::FUNCTION_MANAGER_NAME)
|
||||||
|
);
|
||||||
|
return addFunction(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScriptEngineManager::createFindPageIndexByBookmark()
|
||||||
|
{
|
||||||
|
JSFunctionDesc fd;
|
||||||
|
fd.setManager(m_functionManager);
|
||||||
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
||||||
|
fd.setCategory(tr("GENERAL"));
|
||||||
|
fd.setName("findPageIndexByBookmark");
|
||||||
|
fd.setDescription("findPageIndexByBookmark(\""+tr("Unique identifier")+"\")");
|
||||||
|
fd.setScriptWrapper(QString("function findPageIndexByBookmark(uniqKey){"
|
||||||
|
"return %1.findPageIndexByBookmark(uniqKey);}"
|
||||||
|
).arg(LimeReport::Const::FUNCTION_MANAGER_NAME)
|
||||||
|
);
|
||||||
|
return addFunction(fd);
|
||||||
|
}
|
||||||
|
|
||||||
bool ScriptEngineManager::createAddTableOfContentsItemFunction()
|
bool ScriptEngineManager::createAddTableOfContentsItemFunction()
|
||||||
{
|
{
|
||||||
JSFunctionDesc fd;
|
JSFunctionDesc fd;
|
||||||
@ -916,6 +967,8 @@ ScriptEngineManager::ScriptEngineManager()
|
|||||||
QScriptValue fontConstructor = m_scriptEngine->newFunction(QFontPrototype::constructorQFont, fontProto);
|
QScriptValue fontConstructor = m_scriptEngine->newFunction(QFontPrototype::constructorQFont, fontProto);
|
||||||
m_scriptEngine->globalObject().setProperty("QFont", fontConstructor);
|
m_scriptEngine->globalObject().setProperty("QFont", fontConstructor);
|
||||||
#endif
|
#endif
|
||||||
|
createAddBookmarkFunction();
|
||||||
|
createFindPageIndexByBookmark();
|
||||||
createAddTableOfContentsItemFunction();
|
createAddTableOfContentsItemFunction();
|
||||||
createClearTableOfContentsFunction();
|
createClearTableOfContentsFunction();
|
||||||
createReopenDatasourceFunction();
|
createReopenDatasourceFunction();
|
||||||
@ -1204,6 +1257,16 @@ void ScriptEngineContext::collectionLoadFinished(const QString& collectionName)
|
|||||||
Q_UNUSED(collectionName);
|
Q_UNUSED(collectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReportPages* ScriptEngineContext::reportPages() const
|
||||||
|
{
|
||||||
|
return m_reportPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptEngineContext::setReportPages(ReportPages *value)
|
||||||
|
{
|
||||||
|
m_reportPages = value;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_UI_LOADER
|
#ifdef HAVE_UI_LOADER
|
||||||
QDialog* ScriptEngineContext::createDialog(DialogDescriber* cont)
|
QDialog* ScriptEngineContext::createDialog(DialogDescriber* cont)
|
||||||
{
|
{
|
||||||
@ -1622,6 +1685,16 @@ void ScriptFunctionsManager::reopenDatasource(const QString& datasourceName)
|
|||||||
return dm->reopenDatasource(datasourceName);
|
return dm->reopenDatasource(datasourceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptFunctionsManager::addBookmark(const QString &uniqKey, const QString &content)
|
||||||
|
{
|
||||||
|
scriptEngineManager()->addBookMark(uniqKey, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScriptFunctionsManager::findPageIndexByBookmark(const QString &uniqKey)
|
||||||
|
{
|
||||||
|
return scriptEngineManager()->findPageIndexByBookmark(uniqKey);
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptFunctionsManager::addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent)
|
void ScriptFunctionsManager::addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent)
|
||||||
{
|
{
|
||||||
scriptEngineManager()->addTableOfContentsItem(uniqKey, content, indent);
|
scriptEngineManager()->addTableOfContentsItem(uniqKey, content, indent);
|
||||||
|
@ -165,6 +165,8 @@ private :
|
|||||||
QByteArray m_description;
|
QByteArray m_description;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef QList< QSharedPointer<PageItemDesignIntf> > ReportPages;
|
||||||
|
|
||||||
class ScriptEngineContext : public QObject, public ICollectionContainer
|
class ScriptEngineContext : public QObject, public ICollectionContainer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -204,6 +206,8 @@ public:
|
|||||||
void setTableOfContents(TableOfContents* tableOfContents);
|
void setTableOfContents(TableOfContents* tableOfContents);
|
||||||
void dropChanges(){ m_hasChanges = false;}
|
void dropChanges(){ m_hasChanges = false;}
|
||||||
bool hasChanges(){ return m_hasChanges;}
|
bool hasChanges(){ return m_hasChanges;}
|
||||||
|
ReportPages* reportPages() const;
|
||||||
|
void setReportPages(ReportPages* value);
|
||||||
#ifdef HAVE_UI_LOADER
|
#ifdef HAVE_UI_LOADER
|
||||||
signals:
|
signals:
|
||||||
void dialogNameChanged(QString dialogName);
|
void dialogNameChanged(QString dialogName);
|
||||||
@ -231,6 +235,7 @@ private:
|
|||||||
PageItemDesignIntf* m_currentPage;
|
PageItemDesignIntf* m_currentPage;
|
||||||
TableOfContents* m_tableOfContents;
|
TableOfContents* m_tableOfContents;
|
||||||
bool m_hasChanges;
|
bool m_hasChanges;
|
||||||
|
ReportPages* m_reportPages;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JSFunctionDesc{
|
class JSFunctionDesc{
|
||||||
@ -366,6 +371,8 @@ public:
|
|||||||
Q_INVOKABLE QVariant getFieldByRowIndex(const QString& fieldName, int rowIndex);
|
Q_INVOKABLE QVariant getFieldByRowIndex(const QString& fieldName, int rowIndex);
|
||||||
Q_INVOKABLE void reopenDatasource(const QString& datasourceName);
|
Q_INVOKABLE void reopenDatasource(const QString& datasourceName);
|
||||||
Q_INVOKABLE QVariant color(const QString& color){ return QColor(color);}
|
Q_INVOKABLE QVariant color(const QString& color){ return QColor(color);}
|
||||||
|
Q_INVOKABLE void addBookmark(const QString& uniqKey, const QString& content);
|
||||||
|
Q_INVOKABLE int findPageIndexByBookmark(const QString &uniqKey);
|
||||||
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);
|
||||||
@ -417,9 +424,12 @@ public:
|
|||||||
QString expandDataFields(QString context, ExpandType expandType, QVariant &varValue, QObject* reportItem);
|
QString expandDataFields(QString context, ExpandType expandType, QVariant &varValue, QObject* reportItem);
|
||||||
QString expandScripts(QString context, QVariant &varValue, QObject* reportItem);
|
QString expandScripts(QString context, QVariant &varValue, QObject* reportItem);
|
||||||
QVariant evaluateScript(const QString &script);
|
QVariant evaluateScript(const QString &script);
|
||||||
|
void addBookMark(const QString &uniqKey, const QString &content);
|
||||||
|
int findPageIndexByBookmark(const QString& uniqKey);
|
||||||
void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent);
|
void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent);
|
||||||
void clearTableOfContents();
|
void clearTableOfContents();
|
||||||
ScriptValueType moveQObjectToScript(QObject* object, const QString objectName);
|
ScriptValueType moveQObjectToScript(QObject* object, const QString objectName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateModel();
|
void updateModel();
|
||||||
bool containsFunction(const QString &functionName);
|
bool containsFunction(const QString &functionName);
|
||||||
@ -440,6 +450,8 @@ private:
|
|||||||
bool createGetFieldFunction();
|
bool createGetFieldFunction();
|
||||||
bool createGetFieldByKeyFunction();
|
bool createGetFieldByKeyFunction();
|
||||||
bool createGetFieldByRowIndex();
|
bool createGetFieldByRowIndex();
|
||||||
|
bool createAddBookmarkFunction();
|
||||||
|
bool createFindPageIndexByBookmark();
|
||||||
bool createAddTableOfContentsItemFunction();
|
bool createAddTableOfContentsItemFunction();
|
||||||
bool createClearTableOfContentsFunction();
|
bool createClearTableOfContentsFunction();
|
||||||
bool createReopenDatasourceFunction();
|
bool createReopenDatasourceFunction();
|
||||||
|
Loading…
Reference in New Issue
Block a user