addBookmark() && findPageIndexByBookmark() have been added to the script

This commit is contained in:
Arin Alexander 2019-03-06 22:16:30 +03:00
parent c475159799
commit 5f56f36a49
3 changed files with 90 additions and 4 deletions

View File

@ -1191,6 +1191,7 @@ ReportPages ReportEnginePrivate::renderToPages()
activateLanguage(m_reportLanguage);
emit renderStarted();
m_scriptEngineContext->setReportPages(&result);
for(int i = 0; i < m_renderingPages.count(); ++i){
PageItemDesignIntf* page = m_renderingPages.at(i);

View File

@ -545,18 +545,39 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){
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);
if (m_context){
BandDesignIntf* currentBand = m_context->getCurrentBand();
m_context->tableOfContents()->setItem(uniqKey, content, 0, indent);
if (currentBand)
currentBand->addBookmark(uniqKey, content);
else if (m_context->getCurrentPage()) {
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(){
@ -835,6 +856,36 @@ bool ScriptEngineManager::createGetFieldByRowIndex()
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()
{
JSFunctionDesc fd;
@ -916,6 +967,8 @@ ScriptEngineManager::ScriptEngineManager()
QScriptValue fontConstructor = m_scriptEngine->newFunction(QFontPrototype::constructorQFont, fontProto);
m_scriptEngine->globalObject().setProperty("QFont", fontConstructor);
#endif
createAddBookmarkFunction();
createFindPageIndexByBookmark();
createAddTableOfContentsItemFunction();
createClearTableOfContentsFunction();
createReopenDatasourceFunction();
@ -1204,6 +1257,16 @@ void ScriptEngineContext::collectionLoadFinished(const QString& collectionName)
Q_UNUSED(collectionName);
}
ReportPages* ScriptEngineContext::reportPages() const
{
return m_reportPages;
}
void ScriptEngineContext::setReportPages(ReportPages *value)
{
m_reportPages = value;
}
#ifdef HAVE_UI_LOADER
QDialog* ScriptEngineContext::createDialog(DialogDescriber* cont)
{
@ -1622,6 +1685,16 @@ void ScriptFunctionsManager::reopenDatasource(const QString& 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)
{
scriptEngineManager()->addTableOfContentsItem(uniqKey, content, indent);

View File

@ -165,6 +165,8 @@ private :
QByteArray m_description;
};
typedef QList< QSharedPointer<PageItemDesignIntf> > ReportPages;
class ScriptEngineContext : public QObject, public ICollectionContainer
{
Q_OBJECT
@ -204,7 +206,9 @@ public:
void setTableOfContents(TableOfContents* tableOfContents);
void dropChanges(){ m_hasChanges = false;}
bool hasChanges(){ return m_hasChanges;}
#ifdef HAVE_UI_LOADER
ReportPages* reportPages() const;
void setReportPages(ReportPages* value);
#ifdef HAVE_UI_LOADER
signals:
void dialogNameChanged(QString dialogName);
void dialogDeleted(QString dialogName);
@ -231,6 +235,7 @@ private:
PageItemDesignIntf* m_currentPage;
TableOfContents* m_tableOfContents;
bool m_hasChanges;
ReportPages* m_reportPages;
};
class JSFunctionDesc{
@ -366,6 +371,8 @@ public:
Q_INVOKABLE QVariant getFieldByRowIndex(const QString& fieldName, int rowIndex);
Q_INVOKABLE void reopenDatasource(const QString& datasourceName);
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 clearTableOfContents();
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 expandScripts(QString context, QVariant &varValue, QObject* reportItem);
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 clearTableOfContents();
ScriptValueType moveQObjectToScript(QObject* object, const QString objectName);
protected:
void updateModel();
bool containsFunction(const QString &functionName);
@ -440,6 +450,8 @@ private:
bool createGetFieldFunction();
bool createGetFieldByKeyFunction();
bool createGetFieldByRowIndex();
bool createAddBookmarkFunction();
bool createFindPageIndexByBookmark();
bool createAddTableOfContentsItemFunction();
bool createClearTableOfContentsFunction();
bool createReopenDatasourceFunction();