diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index 94dc11f..882bc66 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -31,6 +31,7 @@ #include #include +#include #ifndef USE_QJSENGINE #include #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(horizontalLayout), dynamic_cast(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(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(row); + if (layout){ + for (int i = 0; i < layout->childrenCount(); ++i) { + BaseDesignIntf* item = dynamic_cast(layout->at(i)); + DataSourceManager* dm = dynamic_cast(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(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) { diff --git a/limereport/lrscriptenginemanager.h b/limereport/lrscriptenginemanager.h index bbdef99..b9a06c9 100644 --- a/limereport/lrscriptenginemanager.h +++ b/limereport/lrscriptenginemanager.h @@ -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; };