0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

DatasourceFunctions have been extended

This commit is contained in:
Arin Alexander 2019-02-05 01:04:23 +03:00
parent d09ae57d0f
commit 5a5c9e76df
2 changed files with 92 additions and 3 deletions

View File

@ -31,6 +31,7 @@
#include <QDate>
#include <QStringList>
#include <QUuid>
#ifndef USE_QJSENGINE
#include <QScriptValueIterator>
#endif
@ -1823,7 +1824,7 @@ bool DatasourceFunctions::isEOF(const QString &datasourceName)
{
if (m_dataManager && m_dataManager->dataSource(datasourceName))
return m_dataManager->dataSource(datasourceName)->eof();
return false;
return true;
}
bool DatasourceFunctions::invalidate(const QString& datasourceName)
@ -1835,6 +1836,73 @@ bool DatasourceFunctions::invalidate(const QString& datasourceName)
return false;
}
QObject* DatasourceFunctions::createTableBuilder(BaseDesignIntf* horizontalLayout)
{
return new TableBuilder(dynamic_cast<LimeReport::HorizontalLayout*>(horizontalLayout), dynamic_cast<DataSourceManager*>(m_dataManager));
}
QObject* TableBuilder::addRow()
{
checkBaseLayout();
HorizontalLayout* newRow = new HorizontalLayout(m_baseLayout, m_baseLayout);
for(int i = 0; i < m_horizontalLayout->childrenCount(); ++i){
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(m_horizontalLayout->at(i));
BaseDesignIntf* cloneItem = item->cloneItem(item->itemMode(), newRow, newRow);
newRow->addChild(cloneItem);
}
m_baseLayout->addChild(newRow);
return newRow;
}
QObject* TableBuilder::currentRow()
{
checkBaseLayout();
if (m_baseLayout && m_baseLayout->childrenCount()>0)
return m_baseLayout->at(m_baseLayout->childrenCount()-1);
return 0;
}
void TableBuilder::fillInRowData(QObject* row)
{
HorizontalLayout* layout = dynamic_cast<HorizontalLayout*>(row);
if (layout){
for (int i = 0; i < layout->childrenCount(); ++i) {
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(layout->at(i));
DataSourceManager* dm = dynamic_cast<DataSourceManager*>(m_dataManager);
if (item && dm)
item->updateItemSize(dm);
}
}
}
void TableBuilder::buildTable(const QString& datasourceName)
{
checkBaseLayout();
m_dataManager->dataSource(datasourceName)->first();
while(!m_dataManager->dataSource(datasourceName)->eof()){
fillInRowData(addRow());
m_dataManager->dataSource(datasourceName)->next();
}
m_horizontalLayout->setVisible(false);
}
void TableBuilder::checkBaseLayout()
{
if (!m_baseLayout){
m_baseLayout = dynamic_cast<VerticalLayout*>(m_horizontalLayout->parentItem());
if (!m_baseLayout){
m_baseLayout = new VerticalLayout(m_horizontalLayout->parent(), m_horizontalLayout->parentItem());
m_baseLayout->setItemLocation(m_horizontalLayout->itemLocation());
m_baseLayout->setPos(m_horizontalLayout->pos());
m_baseLayout->setWidth(m_horizontalLayout->width());
m_baseLayout->setHeight(0);
m_baseLayout->addChild(m_horizontalLayout);
m_baseLayout->setObjectName(QUuid::createUuid().toString());
m_baseLayout->setItemTypeName("VerticalLayout");
}
}
}
#ifndef USE_QJSENGINE
void ComboBoxPrototype::addItem(const QString &text)
{

View File

@ -54,6 +54,8 @@
#include "lrcollection.h"
#include "lrdatasourceintf.h"
#include "lrdatasourcemanagerintf.h"
#include "lrhorizontallayout.h"
#include "lrverticallayout.h"
namespace LimeReport{
@ -298,16 +300,35 @@ private:
QObject* createWrapper(QObject* item);
};
class TableBuilder: public QObject{
Q_OBJECT
public:
TableBuilder(LimeReport::HorizontalLayout* layout, DataSourceManager* dataManager)
: m_horizontalLayout(layout), m_baseLayout(0), m_dataManager(dataManager){}
~TableBuilder(){}
Q_INVOKABLE QObject* addRow();
Q_INVOKABLE QObject* currentRow();
Q_INVOKABLE void fillInRowData(QObject* row);
Q_INVOKABLE void buildTable(const QString& datasourceName);
private:
void checkBaseLayout();
private:
LimeReport::HorizontalLayout* m_horizontalLayout;
LimeReport::VerticalLayout* m_baseLayout;
DataSourceManager* m_dataManager;
};
class DatasourceFunctions : public QObject{
Q_OBJECT
public:
explicit DatasourceFunctions(IDataSourceManager* dataManager): m_dataManager(dataManager){}
explicit DatasourceFunctions(IDataSourceManager* dataManager)
: m_dataManager(dataManager){}
Q_INVOKABLE bool first(const QString& datasourceName);
Q_INVOKABLE bool next(const QString& datasourceName);
Q_INVOKABLE bool prior(const QString& datasourceName);
Q_INVOKABLE bool isEOF(const QString& datasourceName);
Q_INVOKABLE bool invalidate(const QString& datasourceName);
Q_INVOKABLE QObject *createTableBuilder(BaseDesignIntf* horizontalLayout);
private:
IDataSourceManager* m_dataManager;
};