diff --git a/include/lrreportengine.h b/include/lrreportengine.h index afbbcdc..94b78d2 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -60,6 +60,10 @@ private: class DataSourceManager; class ReportEnginePrivate; +class PageDesignIntf; +class PageItemDesignIntf; + +typedef QList< QSharedPointer > ReportPages; class LIMEREPORT_EXPORT ReportEngine : public QObject{ Q_OBJECT @@ -69,7 +73,9 @@ public: explicit ReportEngine(QObject *parent = 0); ~ReportEngine(); bool printReport(QPrinter *printer=0); + bool printPages(ReportPages pages, QPrinter *printer, PrintRange printRange = PrintRange()); void printToFile(const QString& fileName); + PageDesignIntf *createPreviewScene(QObject *parent = 0); bool printToPDF(const QString& fileName); void previewReport(); void designReport(); diff --git a/limereport/databrowser/lrdatabrowser.cpp b/limereport/databrowser/lrdatabrowser.cpp index 4629d0e..37f6eaf 100644 --- a/limereport/databrowser/lrdatabrowser.cpp +++ b/limereport/databrowser/lrdatabrowser.cpp @@ -778,14 +778,4 @@ void DataBrowser::on_variablesTree_itemDoubleClicked(QTreeWidgetItem *item, int } } -} // namespace LimeReport - - - - - - - - - - +} // namespace LimeReport \ No newline at end of file diff --git a/limereport/images/addPage.png b/limereport/images/addPage.png new file mode 100644 index 0000000..0307330 Binary files /dev/null and b/limereport/images/addPage.png differ diff --git a/limereport/images/addPage1.png b/limereport/images/addPage1.png new file mode 100644 index 0000000..211a2ff Binary files /dev/null and b/limereport/images/addPage1.png differ diff --git a/limereport/images/deletePage.png b/limereport/images/deletePage.png new file mode 100644 index 0000000..f8b7cfe Binary files /dev/null and b/limereport/images/deletePage.png differ diff --git a/limereport/images/deletePage1.png b/limereport/images/deletePage1.png new file mode 100644 index 0000000..45f33ce Binary files /dev/null and b/limereport/images/deletePage1.png differ diff --git a/limereport/images/green_logo_32x32.png b/limereport/images/green_logo_32x32.png new file mode 100644 index 0000000..b1752f7 Binary files /dev/null and b/limereport/images/green_logo_32x32.png differ diff --git a/limereport/images/logo_16x16.png b/limereport/images/logo_16x16.png new file mode 100644 index 0000000..07dbfbd Binary files /dev/null and b/limereport/images/logo_16x16.png differ diff --git a/limereport/items/editors/lrfonteditorwidget.cpp b/limereport/items/editors/lrfonteditorwidget.cpp index 2fbb96e..812c5a9 100644 --- a/limereport/items/editors/lrfonteditorwidget.cpp +++ b/limereport/items/editors/lrfonteditorwidget.cpp @@ -41,6 +41,16 @@ FontEditorWidget::FontEditorWidget(ReportDesignWidget *reportEditor, QWidget *pa initEditor(); } +FontEditorWidget::FontEditorWidget(PageDesignIntf *page, const QString &title, QWidget *parent) + :ItemEditorWidget(page,title,parent), m_ignoreSlots(false) { + initEditor(); +} + +FontEditorWidget::FontEditorWidget(LimeReport::PageDesignIntf *page, QWidget *parent) + :ItemEditorWidget(page,parent), m_ignoreSlots(false){ + initEditor(); +} + void FontEditorWidget::setItemEvent(BaseDesignIntf* item) { @@ -116,22 +126,26 @@ void FontEditorWidget::slotFontChanged(const QFont &font) void FontEditorWidget::slotFontSizeChanged(const QString &value) { - if (reportEditor() && !m_ignoreSlots){ - QFont resFont(m_fontNameEditor->currentFont()); - resFont.setPointSize(value.toInt()); - reportEditor()->setFont(resFont); - } + if (m_ignoreSlots) return; + + QFont resFont(fontNameEditor()->currentFont()); + resFont.setPointSize(value.toInt()); + + if (reportEditor()) reportEditor()->setFont(resFont); + if (page()) page()->setFont(resFont); } void FontEditorWidget::slotFontAttribsChanged(bool) { - if (reportEditor()&& !m_ignoreSlots){ - QFont resFont(m_fontNameEditor->currentFont()); - resFont.setBold(m_fontBold->isChecked()); - resFont.setItalic(m_fontItalic->isChecked()); - resFont.setUnderline(m_fontUnderline->isChecked()); - reportEditor()->setFont(resFont); - } + if (m_ignoreSlots) return; + + QFont resFont(m_fontNameEditor->currentFont()); + resFont.setBold(m_fontBold->isChecked()); + resFont.setItalic(m_fontItalic->isChecked()); + resFont.setUnderline(m_fontUnderline->isChecked()); + if (reportEditor()) reportEditor()->setFont(resFont); + if (page()) page()->setFont(resFont); + } void FontEditorWidget::slotPropertyChanged(const QString &objectName, const QString &property, const QVariant& oldValue, const QVariant& newValue) diff --git a/limereport/items/editors/lrfonteditorwidget.h b/limereport/items/editors/lrfonteditorwidget.h index eb7864e..23f9ab7 100644 --- a/limereport/items/editors/lrfonteditorwidget.h +++ b/limereport/items/editors/lrfonteditorwidget.h @@ -45,8 +45,11 @@ class FontEditorWidget :public ItemEditorWidget{ public: explicit FontEditorWidget(ReportDesignWidget* reportEditor, const QString &title, QWidget *parent = 0); explicit FontEditorWidget(ReportDesignWidget* reportEditor, QWidget *parent = 0); + explicit FontEditorWidget(PageDesignIntf* page, const QString &title, QWidget *parent = 0); + explicit FontEditorWidget(PageDesignIntf* page, QWidget *parent = 0); protected: void setItemEvent(BaseDesignIntf *item); + QFontComboBox* fontNameEditor(){return m_fontNameEditor;} private slots: void slotFontChanged(const QFont& font); void slotFontSizeChanged(const QString& value); diff --git a/limereport/items/lrshapeitem.cpp b/limereport/items/lrshapeitem.cpp index 1639fc2..16c72f9 100644 --- a/limereport/items/lrshapeitem.cpp +++ b/limereport/items/lrshapeitem.cpp @@ -60,8 +60,24 @@ ShapeItem::ShapeItem(QObject *owner, QGraphicsItem *parent) { } +Qt::PenStyle ShapeItem::penStyle() const +{ + return m_penStyle; +} + +void ShapeItem::setPenStyle(const Qt::PenStyle &value) +{ + if ((value!=m_penStyle)){ + Qt::PenStyle oldValue = m_penStyle; + m_penStyle=value; + update(); + notify("penStyle",(int)oldValue,(int)value); + } +} + void ShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + painter->save(); QPen pen(m_shapeColor); @@ -150,21 +166,6 @@ void ShapeItem::setLineWidth(qreal value) } } -Qt::PenStyle ShapeItem::penStyle() const -{ - return m_penStyle; -} - -void ShapeItem::setPenStyle(const Qt::PenStyle &value) -{ - if (m_penStyle!=value){ - Qt::PenStyle oldValue = m_penStyle; - m_penStyle = value; - update(); - notify("penStyle",(int)oldValue,(int)value); - } -} - BaseDesignIntf *ShapeItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent) { return new ShapeItem(owner,parent); diff --git a/limereport/items/lrtextitem.cpp b/limereport/items/lrtextitem.cpp index d9197f7..9fd38aa 100644 --- a/limereport/items/lrtextitem.cpp +++ b/limereport/items/lrtextitem.cpp @@ -150,20 +150,45 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q break; } -// for(QTextBlock it=m_text->begin();it!=m_text->end();it=it.next()){ -// for (int i=0;ilineCount();i++){ -// painter->setOpacity(qreal(foregroundOpacity())/100); -// it.layout()->lineAt(i).draw(painter,QPointF(0,0)); -// } -// } + int lineHeight = painter->fontMetrics().height(); + qreal curpos = 0; + + if (m_underlines){ + QPen pen = painter->pen(); + pen.setWidth(m_underlineLineSize); + painter->setPen(pen); + } painter->setOpacity(qreal(foregroundOpacity())/100); - - //m_text->setDefaultTextOption(); QAbstractTextDocumentLayout::PaintContext ctx; ctx.palette.setColor(QPalette::Text, fontColor()); + for(QTextBlock it=m_text->begin();it!=m_text->end();it=it.next()){ + it.blockFormat().setLineHeight(m_lineSpacing,QTextBlockFormat::LineDistanceHeight); + for (int i=0;ilineCount();i++){ + QTextLine line = it.layout()->lineAt(i); + if (m_underlines){ + painter->drawLine(QPointF(0,line.rect().bottomLeft().y()),QPoint(rect().width(),line.rect().bottomRight().y())); + lineHeight = line.height()+m_lineSpacing; + curpos = line.rect().bottom(); + } + } + } m_text->documentLayout()->draw(painter,ctx); + if (m_underlines){ + if (lineHeight<0) lineHeight = painter->fontMetrics().height(); + for (curpos+=lineHeight; curposdrawLine(QPointF(0,curpos),QPoint(rect().width(),curpos)); + } + } + + //painter->setOpacity(qreal(foregroundOpacity())/100); + + //m_text->setDefaultTextOption(); + //QAbstractTextDocumentLayout::PaintContext ctx; + //ctx.palette.setColor(QPalette::Text, fontColor()); + //m_text->documentLayout()->draw(painter,ctx); + // m_layout.draw(ppainter,QPointF(marginSize(),0),); // ppainter->setFont(transformToSceneFont(font())); // QTextOption o; @@ -186,6 +211,10 @@ void TextItem::Init() // m_text->setDefaultFont(transformToSceneFont(font())); m_textSize=QSizeF(); m_foregroundOpacity = 100; + m_underlines = false; + m_adaptFontToSize = false; + m_underlineLineSize = 1; + m_lineSpacing = 1; } void TextItem::setContent(const QString &value) @@ -204,9 +233,9 @@ void TextItem::setContent(const QString &value) } if (!isLoading()){ - update(rect()); - notify("content",oldValue,value); - //updateLayout(); + initText(); + update(rect()); + notify("content",oldValue,value); } } } @@ -223,7 +252,7 @@ void TextItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, i } if ((m_textSize.height()>height()) && (m_autoHeight) ){ - setHeight(m_textSize.height()+5); + setHeight(m_textSize.height()+borderLineSize()*2); } BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight); } @@ -262,23 +291,91 @@ QString TextItem::replaceReturns(QString text) return result; } +void TextItem::setTextFont(const QFont& value){ + m_text->setDefaultFont(value); + if ((m_angle==Angle0)||(m_angle==Angle180)){ + m_text->setTextWidth(rect().width()-fakeMarginSize()*2); + } else { + m_text->setTextWidth(rect().height()-fakeMarginSize()*2); + } +} + +void TextItem::adaptFontSize(){ + QFont _font = transformToSceneFont(font()); + do{ + setTextFont(_font); + if (_font.pixelSize()>2) + _font.setPixelSize(_font.pixelSize()-1); + else break; + } while(m_text->size().height()>this->height() || m_text->size().width()>(this->width())-fakeMarginSize()*2); +} +int TextItem::underlineLineSize() const +{ + return m_underlineLineSize; +} + +void TextItem::setUnderlineLineSize(int value) +{ + int oldValue = m_underlineLineSize; + m_underlineLineSize = value; + update(); + notify("underlineLineSize",oldValue,value); +} + +int TextItem::lineSpacing() const +{ + return m_lineSpacing; +} + +void TextItem::setLineSpacing(int value) +{ + int oldValue = m_lineSpacing; + m_lineSpacing = value; + initText(); + update(); + notify("lineSpacing",oldValue,value); +} + + void TextItem::initText() { QTextOption to; to.setAlignment(m_alignment); if (m_autoWidth!=MaxStringLength) - to.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); + if (m_adaptFontToSize && (!(m_autoHeight || m_autoWidth))) + to.setWrapMode(QTextOption::WordWrap); + else + to.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); else to.setWrapMode(QTextOption::NoWrap); m_text->setDocumentMargin(0); m_text->setDefaultTextOption(to); - m_text->setDefaultFont(transformToSceneFont(font())); + + QFont _font = transformToSceneFont(font()); + if (m_adaptFontToSize && (!(m_autoHeight || m_autoWidth))){ + adaptFontSize(); + } else { + setTextFont(transformToSceneFont(font())); + } + if ((m_angle==Angle0)||(m_angle==Angle180)){ m_text->setTextWidth(rect().width()-fakeMarginSize()*2); } else { m_text->setTextWidth(rect().height()-fakeMarginSize()*2); } + + for ( QTextBlock block = m_text->begin(); block.isValid(); block = block.next()) + { + QTextCursor tc = QTextCursor(block); + QTextBlockFormat fmt = block.blockFormat(); + + if(fmt.lineHeight() != m_lineSpacing) { + fmt.setLineHeight(m_lineSpacing,QTextBlockFormat::LineDistanceHeight); + tc.setBlockFormat( fmt ); + } + } + m_textSize=m_text->size(); } @@ -320,9 +417,11 @@ bool TextItem::trimValue() const return m_trimValue; } -void TextItem::setTrimValue(bool trimValue) +void TextItem::setTrimValue(bool value) { - m_trimValue = trimValue; + bool oldValue = m_trimValue; + m_trimValue = value; + notify("trimValue",oldValue,value); } @@ -333,8 +432,9 @@ void TextItem::geometryChangedEvent(QRectF , QRectF) // } else { // m_text->setTextWidth(rect().height()-fakeMarginSize()*2); // } -// m_textSize=m_text->size(); if (itemMode() == DesignMode) initText(); + else if (adaptFontToSize()) initText(); + } bool TextItem::isNeedUpdateSize(RenderPass pass) const @@ -395,6 +495,17 @@ void TextItem::setAutoWidth(TextItem::AutoWidth value) } } +void TextItem::setAdaptFontToSize(bool value) +{ + if (m_adaptFontToSize!=value){ + bool oldValue = m_adaptFontToSize; + m_adaptFontToSize=value; + initText(); + invalidateRect(rect()); + notify("updateFontToSize",oldValue,value); + } +} + bool TextItem::canBeSplitted(int height) const { return height>(m_text->begin().layout()->lineAt(0).height()); @@ -409,8 +520,10 @@ BaseDesignIntf *TextItem::cloneUpperPart(int height, QObject *owner, QGraphicsIt for (QTextBlock it=m_text->begin();it!=m_text->end();it=it.next()){ for (int i=0;ilineCount();i++){ - linesHeight+=it.layout()->lineAt(i).height(); - if (linesHeight>(height-(fakeMarginSize()*2+borderLineSize()*2))) {linesHeight-=it.layout()->lineAt(i).height(); goto loop_exit;} + linesHeight+=it.layout()->lineAt(i).height()+lineSpacing(); + if (linesHeight>(height-(fakeMarginSize()*2+borderLineSize()*2))) { + linesHeight-=it.layout()->lineAt(i).height(); goto loop_exit; + } tmpText+=it.text().mid(it.layout()->lineAt(i).textStart(),it.layout()->lineAt(i).textLength())+'\n'; } } @@ -433,7 +546,7 @@ BaseDesignIntf *TextItem::cloneBottomPart(int height, QObject *owner, QGraphicsI for (curBlock=m_text->begin();curBlock!=m_text->end();curBlock=curBlock.next()){ for (curLine=0;curLinelineCount();curLine++){ - linesHeight+=curBlock.layout()->lineAt(curLine).height(); + linesHeight+=curBlock.layout()->lineAt(curLine).height()+lineSpacing(); if (linesHeight>(height-(fakeMarginSize()*2+borderLineSize()*2))) {goto loop_exit;} } } @@ -565,6 +678,16 @@ void TextItem::setForegroundOpacity(int value) } } +void TextItem::setUnderlines(bool value) +{ + if (m_underlines != value){ + bool oldValue = m_underlines; + m_underlines = value; + update(); + notify("underlines",oldValue,value); + } +} + } //namespace LimeReport diff --git a/limereport/items/lrtextitem.h b/limereport/items/lrtextitem.h index d95cb3c..d2243e7 100644 --- a/limereport/items/lrtextitem.h +++ b/limereport/items/lrtextitem.h @@ -56,7 +56,11 @@ class TextItem : public LimeReport::ContentItemDesignIntf { Q_PROPERTY(QColor fontColor READ fontColor WRITE setFontColorProperty) Q_PROPERTY(AngleType angle READ angle WRITE setAngle) Q_PROPERTY(int foregroundOpacity READ foregroundOpacity WRITE setForegroundOpacity) + Q_PROPERTY(bool underlines READ underlines WRITE setUnderlines) + Q_PROPERTY(bool adaptFontToSize READ adaptFontToSize WRITE setAdaptFontToSize) Q_PROPERTY(bool trimValue READ trimValue WRITE setTrimValue) + Q_PROPERTY(int lineSpacing READ lineSpacing WRITE setLineSpacing) + Q_PROPERTY(int underlineLineSize READ underlineLineSize WRITE setUnderlineLineSize) Q_PROPERTY(bool allowHTML READ allowHTML WRITE setAllowHTML) Q_PROPERTY(bool allowHTMLInFields READ allowHTMLInFields WRITE setAllowHTMLInFields) public: @@ -72,9 +76,6 @@ public: QString content() const; void setContent(const QString& value); - //void setMarginSize(int value); - - void setAlignment(Qt::Alignment value); Qt::Alignment alignment(){return m_alignment;} @@ -89,6 +90,9 @@ public: void setAutoWidth(AutoWidth value); AutoWidth autoWidth() const {return m_autoWidth;} + void setAdaptFontToSize(bool value); + bool adaptFontToSize() const {return m_adaptFontToSize;} + bool canBeSplitted(int height) const; bool isSplittable() const { return true;} bool isEmpty() const{return m_text->isEmpty();} @@ -108,10 +112,18 @@ public: void setAngle(const AngleType& value); int foregroundOpacity(){return m_foregroundOpacity;} void setForegroundOpacity(int value); + bool underlines(){return m_underlines;} + void setUnderlines(bool value); bool trimValue() const; void setTrimValue(bool trimValue); + int lineSpacing() const; + void setLineSpacing(int value); + + int underlineLineSize() const; + void setUnderlineLineSize(int value); + bool allowHTML() const; void setAllowHTML(bool allowHTML); @@ -126,6 +138,8 @@ protected: int fakeMarginSize(); private: void initText(); + void setTextFont(const QFont &value); + void adaptFontSize(); private: QString m_strText; @@ -137,7 +151,11 @@ private: QSizeF m_textSize; AngleType m_angle; int m_foregroundOpacity; + bool m_underlines; + bool m_adaptFontToSize; bool m_trimValue; + int m_lineSpacing; + int m_underlineLineSize; bool m_allowHTML; bool m_allowHTMLInFields; }; diff --git a/limereport/limereport.pri b/limereport/limereport.pri index 8b82707..db8b5ec 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -87,7 +87,8 @@ SOURCES += \ $$REPORT_PATH/lrgroupfunctions.cpp \ $$REPORT_PATH/lrsimplecrypt.cpp \ $$REPORT_PATH/lraboutdialog.cpp \ - $$REPORT_PATH/lrsettingdialog.cpp + $$REPORT_PATH/lrsettingdialog.cpp \ + $$REPORT_PATH/scriptbrowser/lrscriptbrowser.cpp contains(CONFIG, zint){ SOURCES += $$REPORT_PATH/items/lrbarcodeitem.cpp @@ -183,7 +184,8 @@ HEADERS += \ $$REPORT_PATH/lraboutdialog.h \ $$REPORT_PATH/lrcallbackdatasourceintf.h \ $$REPORT_PATH/lrsettingdialog.h \ - $$PWD/lrpreviewreportwidget_p.h + $$REPORT_PATH/lrpreviewreportwidget_p.h \ + $$REPORT_PATH/scriptbrowser/lrscriptbrowser.h \ contains(CONFIG,zint){ HEADERS += $$REPORT_PATH/items/lrbarcodeitem.h @@ -199,11 +201,13 @@ FORMS += \ $$REPORT_PATH/lrpreviewreportwidget.ui \ $$REPORT_PATH/items/lrtextitemeditor.ui \ $$REPORT_PATH/lraboutdialog.ui \ - $$REPORT_PATH/lrsettingdialog.ui + $$REPORT_PATH/lrsettingdialog.ui \ + $$REPORT_PATH/scriptbrowser/lrscriptbrowser.ui \ RESOURCES += \ $$REPORT_PATH/objectinspector/lobjectinspector.qrc \ $$REPORT_PATH/databrowser/lrdatabrowser.qrc \ $$REPORT_PATH/report.qrc \ - $$REPORT_PATH/items/items.qrc + $$REPORT_PATH/items/items.qrc \ + $$REPORT_PATH/scriptbrowser/lrscriptbrowser.qrc diff --git a/limereport/lrbanddesignintf.cpp b/limereport/lrbanddesignintf.cpp index fe6c139..879b4bc 100644 --- a/limereport/lrbanddesignintf.cpp +++ b/limereport/lrbanddesignintf.cpp @@ -681,6 +681,13 @@ void BandDesignIntf::initMode(ItemMode mode) BaseDesignIntf::initMode(mode); if ((mode==PreviewMode)||(mode==PrintMode)){ m_bandMarker->setVisible(false); + } else { + if (!m_bandMarker->scene() && this->scene()){ + this->scene()->addItem(m_bandMarker); + m_bandMarker->setParentItem(this->parentItem()); + m_bandMarker->setHeight(this->height()); + } + m_bandMarker->setVisible(true); } } diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 494ec20..08d11cb 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -74,8 +74,8 @@ class DataSourceModel : public QAbstractItemModel{ public: DataSourceModel():m_rootNode(new DataNode()){} DataSourceModel(DataSourceManager* dataManager); - QModelIndex index(int row, int column, const QModelIndex &parent) const; ~DataSourceModel(); + QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex parent(const QModelIndex &child) const; int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; diff --git a/limereport/lrgraphicsviewzoom.cpp b/limereport/lrgraphicsviewzoom.cpp index 8676f22..89ae87e 100644 --- a/limereport/lrgraphicsviewzoom.cpp +++ b/limereport/lrgraphicsviewzoom.cpp @@ -29,7 +29,17 @@ void GraphicsViewZoomer::setModifiers(Qt::KeyboardModifiers modifiers) { } void GraphicsViewZoomer::setZoomFactorBase(double value) { - m_zoomFactorBase = value; + m_zoomFactorBase = value; +} + +void GraphicsViewZoomer::setView(QGraphicsView *view) +{ + if (m_view!=view){ + m_view->viewport()->removeEventFilter(this); + m_view = view; + m_view->viewport()->installEventFilter(this); + m_view->setMouseTracking(true); + } } bool GraphicsViewZoomer::eventFilter(QObject *object, QEvent *event) { diff --git a/limereport/lrgraphicsviewzoom.h b/limereport/lrgraphicsviewzoom.h index d9f1720..e1f6d49 100644 --- a/limereport/lrgraphicsviewzoom.h +++ b/limereport/lrgraphicsviewzoom.h @@ -13,6 +13,7 @@ public: void gentleZoom(double factor); void setModifiers(Qt::KeyboardModifiers modifiers); void setZoomFactorBase(double value); + void setView(QGraphicsView* view); private: QGraphicsView* m_view; Qt::KeyboardModifiers m_modifiers; diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 5dd36d4..b182a36 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -123,6 +123,7 @@ namespace LimeReport { PageItemDesignIntf *pageItem(); void setPageItem(PageItemDesignIntf::Ptr pageItem); void setPageItems(QList pages); + QList pageItems(){return m_reportPages;} bool isItemInsertMode(); ReportEnginePrivate* reportEditor(); diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index 8632837..0f27de7 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -139,5 +139,8 @@ private: bool m_fullPage; bool m_oldPrintMode; }; + +typedef QList ReportPages; + } #endif // LRPAGEITEM_H diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index 441b77a..f4adbde 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -61,12 +61,25 @@ PreviewReportWindow::PreviewReportWindow(ReportEnginePrivate *report,QWidget *pa setCentralWidget(m_previewReportWidget); layout()->setContentsMargins(1,1,1,1); connect(m_previewReportWidget,SIGNAL(pageChanged(int)), this,SLOT(slotPageChanged(int)) ); + connect(m_previewReportWidget->d_ptr->m_previewPage,SIGNAL(selectionChanged()),this,SLOT(slotSelectionChanged())); + connect(m_pagesNavigator,SIGNAL(valueChanged(int)),this,SLOT(slotPageNavigatorChanged(int))); + m_fontEditor = new FontEditorWidget(m_previewReportWidget->d_ptr->m_previewPage,tr("Font"),this); + m_fontEditor->setObjectName("fontTools"); + m_fontEditor->setIconSize(ui->toolBar->iconSize()); + m_textAlignmentEditor = new TextAlignmentEditorWidget(m_previewReportWidget->d_ptr->m_previewPage,tr("Text align"),this); + m_textAlignmentEditor->setObjectName("textAlignmentTools"); + m_textAlignmentEditor->setIconSize(ui->toolBar->iconSize()); + addToolBar(Qt::TopToolBarArea,m_fontEditor); + addToolBar(Qt::TopToolBarArea,m_textAlignmentEditor); m_scalePercent = new QComboBox(this); m_scalePercent->setEditable(true); ui->toolBar->insertWidget(ui->actionZoomOut, m_scalePercent); initPercentCombobox(); + +// connect(ui->graphicsView->verticalScrollBar(),SIGNAL(valueChanged(int)), this, SLOT(slotSliderMoved(int))); + connect(ui->actionShowMessages, SIGNAL(triggered()), this, SLOT(slotShowErrors())); connect(m_previewReportWidget, SIGNAL(scalePercentChanged(int)), this, SLOT(slotScalePercentChanged(int))); connect(m_scalePercent, SIGNAL(currentIndexChanged(QString)), this, SLOT(scaleComboboxChanged(QString))); restoreSetting(); @@ -209,6 +222,12 @@ void PreviewReportWindow::moveEvent(QMoveEvent* e) #endif } +void PreviewReportWindow::showEvent(QShowEvent *) +{ + m_fontEditor->setVisible(ui->actionEdit_Mode->isChecked()); + m_textAlignmentEditor->setVisible(ui->actionEdit_Mode->isChecked()); +} + void PreviewReportWindow::slotPrint() { m_previewReportWidget->print(); @@ -244,6 +263,28 @@ void PreviewReportWindow::slotShowErrors() m_previewReportWidget->setErrorsMesagesVisible(ui->actionShowMessages->isChecked()); } +void PreviewReportWindow::on_actionEdit_Mode_triggered(bool checked) +{ + m_previewReportWidget->d_ptr->m_previewPage->setItemMode((checked)?ItemModes(DesignMode):PreviewMode); + m_textAlignmentEditor->setVisible(checked); + m_fontEditor->setVisible(checked); + //m_reportPages.at(m_currentPage)->setItemMode((checked)?DesignMode:PreviewMode); +} + +void PreviewReportWindow::slotSelectionChanged() +{ + QGraphicsScene* page=dynamic_cast(sender()); + if (page){ + if (page->selectedItems().count()==1){ + BaseDesignIntf* item = dynamic_cast(page->selectedItems().at(0)); + if (item) { + m_fontEditor->setItem(item); + m_textAlignmentEditor->setItem(item); + } + } + } +} + ItemsReaderIntf *PreviewReportWindow::reader() { return m_reader.data(); @@ -312,4 +353,4 @@ void PreviewReportWindow::on_actionShowMessages_toggled(bool value) m_previewReportWidget->setErrorsMesagesVisible(value); } -}// namespace LimeReport \ No newline at end of file +}// namespace LimeReport diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index 995810c..dbc6995 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -41,6 +41,9 @@ #include "serializators/lrxmlreader.h" #include "lrpreviewreportwidget.h" +#include "items/editors/lrfonteditorwidget.h" +#include "items/editors/lrtextalignmenteditorwidget.h" + namespace LimeReport { namespace Ui { @@ -66,6 +69,7 @@ protected: void closeEvent(QCloseEvent *); void resizeEvent(QResizeEvent *e); void moveEvent(QMoveEvent *e); + void showEvent(QShowEvent *); public slots: void slotPrint(); void slotPriorPage(); @@ -75,6 +79,8 @@ public slots: void slotPageNavigatorChanged(int value); void slotShowErrors(); void on_actionSaveToFile_triggered(); + void slotSelectionChanged(); + void on_actionEdit_Mode_triggered(bool checked); void slotFirstPage(); void slotLastPage(); void slotPrintToPDF(); @@ -90,8 +96,6 @@ private slots: private: ItemsReaderIntf* reader(); void initPercentCombobox(); - //bool pageIsVisible(PageItemDesignIntf::Ptr page); - //QRectF calcPageShift(PageItemDesignIntf::Ptr page); private: Ui::PreviewReportWindow *ui; QSpinBox* m_pagesNavigator; @@ -100,6 +104,9 @@ private: bool m_changingPage; QSettings* m_settings; bool m_ownedSettings; + FontEditorWidget* m_fontEditor; + TextAlignmentEditorWidget* m_textAlignmentEditor; + int m_priorScrolValue; PreviewReportWidget* m_previewReportWidget; QComboBox* m_scalePercent; }; diff --git a/limereport/lrpreviewreportwindow.ui b/limereport/lrpreviewreportwindow.ui index 7618999..816ea1f 100644 --- a/limereport/lrpreviewreportwindow.ui +++ b/limereport/lrpreviewreportwindow.ui @@ -73,6 +73,8 @@ false + + diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index bdaab42..a7afece 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -41,6 +41,8 @@ #include #include #include +#include +#include namespace LimeReport { @@ -49,11 +51,10 @@ namespace LimeReport { ReportDesignWidget::ReportDesignWidget(ReportEnginePrivate *report, QMainWindow *mainWindow, QWidget *parent) : QWidget(parent), m_mainWindow(mainWindow), m_verticalGridStep(10), m_horizontalGridStep(10), m_useGrid(false) { - QVBoxLayout *mainLayout = new QVBoxLayout(this); - mainLayout->setContentsMargins(1,1,1,1); - m_view = new QGraphicsView(qobject_cast(this)); - m_view->setBackgroundBrush(QBrush(Qt::gray)); - mainLayout->addWidget(m_view); + m_tabWidget = new QTabWidget(this); + m_tabWidget->setTabPosition(QTabWidget::South); + QVBoxLayout* mainLayout = new QVBoxLayout(this); + mainLayout->addWidget(m_tabWidget); setLayout(mainLayout); if (!report) { @@ -66,16 +67,15 @@ ReportDesignWidget::ReportDesignWidget(ReportEnginePrivate *report, QMainWindow if (!m_report->pageCount()) m_report->appendPage("page1"); } - setActivePage(m_report->pageAt(0)); - foreach(QGraphicsItem* item, activePage()->selectedItems()){ - item->setSelected(false); - } + createTabs(); + connect(m_report,SIGNAL(pagesLoadFinished()),this,SLOT(slotPagesLoadFinished())); connect(m_report,SIGNAL(cleared()),this,SIGNAL(cleared())); - m_view->scale(0.5,0.5); + connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentTabChanged(int))); + //m_instance=this; - //m_view->viewport()->installEventFilter(this); - m_zoomer = new GraphicsViewZoomer(m_view); + m_scriptEditor->setPlainText(report->scriptContext()->initScript()); + m_zoomer = new GraphicsViewZoomer(activeView()); #ifdef Q_OS_WIN m_defaultFont = QFont("Arial",10); #endif @@ -133,20 +133,43 @@ void ReportDesignWidget::loadState(QSettings* settings) if (v.isValid()){ m_useGrid = v.toBool(); } - settings->endGroup(); - applySettings(); } + +void ReportDesignWidget::createTabs(){ + for (int i = 0; ipageCount();++i){ + QGraphicsView* view = new QGraphicsView(qobject_cast(this)); + view->setBackgroundBrush(QBrush(Qt::gray)); + view->setFrameShape(QFrame::NoFrame); + view->setScene(m_report->pageAt(i)); + + foreach(QGraphicsItem* item, m_report->pageAt(i)->selectedItems()){ + item->setSelected(false); + } + + view->centerOn(0,0); + view->scale(0.5,0.5); + connectPage(m_report->pageAt(i)); + m_tabWidget->addTab(view,QIcon(),tr("Page")+QString::number(i+1)); + } + m_scriptEditor = new QTextEdit(this); + m_tabWidget->addTab(m_scriptEditor,QIcon(),tr("Script")); + m_tabWidget->setCurrentIndex(0); +} + ReportDesignWidget::~ReportDesignWidget() { delete m_zoomer; } -void ReportDesignWidget::setActivePage(PageDesignIntf *page) +QGraphicsView* ReportDesignWidget::activeView(){ + return dynamic_cast(m_tabWidget->currentWidget()); +} + +void ReportDesignWidget::connectPage(PageDesignIntf *page) { - m_view->setScene(page); connect(page,SIGNAL(itemInserted(LimeReport::PageDesignIntf*,QPointF,QString)),this,SIGNAL(itemInserted(LimeReport::PageDesignIntf*,QPointF,QString))); connect(page,SIGNAL(itemInsertCanceled(QString)),this,SIGNAL(itemInsertCanceled(QString))); connect(page,SIGNAL(itemPropertyChanged(QString,QString,QVariant,QVariant)),this,SIGNAL(itemPropertyChanged(QString,QString,QVariant,QVariant))); @@ -166,48 +189,55 @@ void ReportDesignWidget::setActivePage(PageDesignIntf *page) connect(page, SIGNAL(pageUpdateFinished(LimeReport::PageDesignIntf*)), this, SIGNAL(activePageUpdated(LimeReport::PageDesignIntf*))); - m_view->centerOn(0, 0); + //activeView()->centerOn(0,0); emit activePageChanged(); } void ReportDesignWidget::createStartPage() { - PageDesignIntf* reportPage = m_report->appendPage("page1"); - setActivePage(reportPage); + m_report->appendPage("page1"); + createTabs(); } void ReportDesignWidget::removeDatasource(const QString &datasourceName) { - m_report->dataManager()->removeDatasource(datasourceName); + if (m_report->dataManager()) + m_report->dataManager()->removeDatasource(datasourceName); } void ReportDesignWidget::addBand(const QString &bandType) { - activePage()->addBand(bandType); + if (activePage()) + activePage()->addBand(bandType); } void ReportDesignWidget::addBand(BandDesignIntf::BandsType bandType) { - activePage()->addBand(bandType); + if (activePage()) + activePage()->addBand(bandType); } void ReportDesignWidget::startInsertMode(const QString &itemType) { - activePage()->startInsertMode(itemType); + if (activePage()) + activePage()->startInsertMode(itemType); } void ReportDesignWidget::startEditMode() { - activePage()->startEditMode(); + if (activePage()) + activePage()->startEditMode(); } PageDesignIntf * ReportDesignWidget::activePage() { - return qobject_cast(m_view->scene()); + if (activeView()) + return qobject_cast(activeView()->scene()); + return 0; } QList ReportDesignWidget::selectedItems(){ - return m_view->scene()->selectedItems(); + return activePage()->selectedItems(); } void ReportDesignWidget::deleteItem(QGraphicsItem *item){ @@ -227,11 +257,13 @@ void ReportDesignWidget::slotItemSelected(BaseDesignIntf *item){ } void ReportDesignWidget::saveToFile(const QString &fileName){ + m_report->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); m_report->saveToFile(fileName); } bool ReportDesignWidget::save() { + m_report->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); if (!m_report->reportFileName().isEmpty()){ if (m_report->saveToFile()){ m_report->emitSaveFinished(); @@ -254,24 +286,36 @@ bool ReportDesignWidget::save() bool ReportDesignWidget::loadFromFile(const QString &fileName) { - if (!m_report->loadFromFile(fileName)) return false; - setActivePage(m_report->pageAt(0)); - return true; + if (m_report->loadFromFile(fileName)){ + createTabs(); + //connectPage(m_report->pageAt(0)); + m_scriptEditor->setPlainText(m_report->scriptContext()->initScript()); + emit loaded(); + return true; + } else { + QMessageBox::critical(this,tr("Error"),tr("Wrong file format")); + return false; + } } void ReportDesignWidget::scale(qreal sx, qreal sy) { - m_view->scale(sx,sy); + //m_view->scale(sx,sy); + if (activeView()) activeView()->scale(sx,sy); } QString ReportDesignWidget::reportFileName() { - return m_report->reportFileName(); + if (m_report) + return m_report->reportFileName(); + return QString(); } bool ReportDesignWidget::isNeedToSave() { - return m_report->isNeedToSave(); + if(m_report) + return m_report->isNeedToSave(); + return false; } bool ReportDesignWidget::emitLoadReport() @@ -281,82 +325,98 @@ bool ReportDesignWidget::emitLoadReport() void ReportDesignWidget::updateSize() { - activePage()->slotUpdateItemSize(); + if (activePage()) + activePage()->slotUpdateItemSize(); } void ReportDesignWidget::undo() { - activePage()->undo(); + if (activePage()) + activePage()->undo(); } void ReportDesignWidget::redo() { - activePage()->redo(); + if (activePage()) + activePage()->redo(); } void ReportDesignWidget::copy() { - activePage()->copy(); + if (activePage()) + activePage()->copy(); } void ReportDesignWidget::paste() { - activePage()->paste(); + if (activePage()) + activePage()->paste(); } void ReportDesignWidget::cut() { - activePage()->cut(); + if (activePage()) + activePage()->cut(); } void ReportDesignWidget::brinToFront() { - activePage()->bringToFront(); + if (activePage()) + activePage()->bringToFront(); } void ReportDesignWidget::sendToBack() { - activePage()->sendToBack(); + if (activePage()) + activePage()->sendToBack(); } void ReportDesignWidget::alignToLeft() { - activePage()->alignToLeft(); + if (activePage()) + activePage()->alignToLeft(); } void ReportDesignWidget::alignToRight() { - activePage()->alignToRigth(); + if (activePage()) + activePage()->alignToRigth(); } void ReportDesignWidget::alignToVCenter() { - activePage()->alignToVCenter(); + if (activePage()) + activePage()->alignToVCenter(); } void ReportDesignWidget::alignToTop() { - activePage()->alignToTop(); + if (activePage()) + activePage()->alignToTop(); } void ReportDesignWidget::alignToBottom() { - activePage()->alignToBottom(); + if (activePage()) + activePage()->alignToBottom(); } void ReportDesignWidget::alignToHCenter() { - activePage()->alignToHCenter(); + if (activePage()) + activePage()->alignToHCenter(); } void ReportDesignWidget::sameHeight() { - activePage()->sameHeight(); + if (activePage()) + activePage()->sameHeight(); } void ReportDesignWidget::sameWidth() { - activePage()->sameWidth(); + if (activePage()) + activePage()->sameWidth(); } void ReportDesignWidget::editLayoutMode(bool value) @@ -370,22 +430,74 @@ void ReportDesignWidget::editLayoutMode(bool value) void ReportDesignWidget::addHLayout() { - activePage()->addHLayout(); + if (activePage()) + activePage()->addHLayout(); } void ReportDesignWidget::setFont(const QFont& font) { - activePage()->setFont(font); + if (activePage()) + activePage()->setFont(font); } void ReportDesignWidget::setTextAlign(const bool& horizontalAlign, const Qt::AlignmentFlag& alignment) { - activePage()->changeSelectedGrpoupTextAlignPropperty(horizontalAlign, alignment); + if (activePage()) + activePage()->changeSelectedGrpoupTextAlignPropperty(horizontalAlign, alignment); } void ReportDesignWidget::setBorders(const BaseDesignIntf::BorderLines& borders) { - activePage()->setBorders(borders); + if (activePage()) + activePage()->setBorders(borders); +} + +void ReportDesignWidget::previewReport() +{ + report()->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); + report()->previewReport(); +} + +void ReportDesignWidget::printReport() +{ + report()->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); + setCursor(Qt::WaitCursor); + report()->printReport(); + setCursor(Qt::ArrowCursor); +} + +void ReportDesignWidget::addPage() +{ + QGraphicsView* view = new QGraphicsView(qobject_cast(this)); + view->setBackgroundBrush(QBrush(Qt::gray)); + view->setFrameShape(QFrame::NoFrame); + PageDesignIntf* page = m_report->appendPage("page"+QString::number(m_report->pageCount()+1)); + view->setScene(page); + int index = m_report->pageCount()-1; + m_tabWidget->insertTab(index,view,QIcon(),tr("Page")+QString::number(m_report->pageCount())); + m_tabWidget->setCurrentIndex(index); + connectPage(page); + view->scale(0.5,0.5); + view->centerOn(0,0); + emit pageAdded(page); +} + +void ReportDesignWidget::deleteCurrentPage() +{ + if (m_report->pageCount()>1){ + QGraphicsView* view = dynamic_cast(m_tabWidget->currentWidget()); + if (view){ + PageDesignIntf* page = dynamic_cast(view->scene()); + if (page){ + if (m_report->deletePage(page)){ + int index = m_tabWidget->currentIndex(); + m_tabWidget->removeTab(m_tabWidget->currentIndex()); + if (index>0) m_tabWidget->setCurrentIndex(index-1); + emit pageDeleted(); + } + } + } + } } void ReportDesignWidget::editSetting() @@ -421,12 +533,16 @@ void ReportDesignWidget::setUseGrid(bool value) bool ReportDesignWidget::isCanUndo() { - return activePage()->isCanUndo(); + if (activePage()) + return activePage()->isCanUndo(); + return false; } bool ReportDesignWidget::isCanRedo() { - return activePage()->isCanRedo(); + if (activePage()) + return activePage()->isCanRedo(); + return false; } void ReportDesignWidget::slotSelectionChanged() @@ -449,10 +565,20 @@ DataSourceManager* ReportDesignWidget::dataManager() return m_report->dataManager(); } +ScriptEngineManager* ReportDesignWidget::scriptManager() +{ + return m_report->scriptManager(); +} + +ScriptEngineContext*ReportDesignWidget::scriptContext() +{ + return m_report->scriptContext(); +} + void ReportDesignWidget::slotPagesLoadFinished() { applySettings(); - setActivePage(m_report->pageAt(0)); + //setActivePage(m_report->pageAt(0)); emit loaded(); } @@ -462,7 +588,19 @@ void ReportDesignWidget::slotDatasourceCollectionLoaded(const QString & /*collec void ReportDesignWidget::slotSceneRectChanged(QRectF) { - m_view->centerOn(0,0); + if (activeView()) activeView()->centerOn(0,0); +} + +void ReportDesignWidget::slotCurrentTabChanged(int index) +{ + QGraphicsView* view = dynamic_cast(m_tabWidget->widget(index)); + if (view) { + if (view->scene()){ + foreach (QGraphicsItem* item, view->scene()->selectedItems()) item->setSelected(false); + } + m_zoomer->setView(view); + } + emit activePageChanged(); } bool ReportDesignWidget::eventFilter(QObject *target, QEvent *event) @@ -480,6 +618,10 @@ bool ReportDesignWidget::eventFilter(QObject *target, QEvent *event) void ReportDesignWidget::clear() { m_report->clearReport(); + m_tabWidget->clear(); + m_report->setReportFileName(""); + m_report->scriptContext()->setInitScript(""); + m_scriptEditor->setPlainText(""); } } diff --git a/limereport/lrreportdesignwidget.h b/limereport/lrreportdesignwidget.h index 8b807d4..28a1998 100644 --- a/limereport/lrreportdesignwidget.h +++ b/limereport/lrreportdesignwidget.h @@ -33,6 +33,7 @@ #include #include #include +#include #include "lrpagedesignintf.h" #include "lrdatadesignintf.h" @@ -59,6 +60,8 @@ public: void createStartPage(); void clear(); DataSourceManager* dataManager(); + ScriptEngineManager* scriptManager(); + ScriptEngineContext* scriptContext(); void removeDatasource(const QString& datasourceName); void addBand(const QString& bandType); void addBand(BandDesignIntf::BandsType bandType); @@ -69,6 +72,7 @@ public: bool isCanRedo(); void deleteItem(QGraphicsItem *item); PageDesignIntf* activePage(); + QGraphicsView* activeView(); QList selectedItems(); QStringList datasourcesNames(); void scale( qreal sx, qreal sy); @@ -90,7 +94,7 @@ public slots: bool save(); bool loadFromFile(const QString&); void deleteSelectedItems(); - void setActivePage(PageDesignIntf* page); + void connectPage(PageDesignIntf* page); void undo(); void redo(); void copy(); @@ -113,12 +117,17 @@ public slots: void setBorders(const BaseDesignIntf::BorderLines& borders); void editSetting(); void setUseGrid(bool value); + void previewReport(); + void printReport(); + void addPage(); + void deleteCurrentPage(); private slots: void slotItemSelected(LimeReport::BaseDesignIntf *item); void slotSelectionChanged(); void slotPagesLoadFinished(); void slotDatasourceCollectionLoaded(const QString&); void slotSceneRectChanged(QRectF); + void slotCurrentTabChanged(int index); signals: void insertModeStarted(); void itemInserted(LimeReport::PageDesignIntf*,QPointF,const QString&); @@ -135,13 +144,19 @@ signals: void bandDeleted(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*); void itemAdded(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*); void itemDeleted(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*); + void pageAdded(PageDesignIntf* page); + void pageDeleted(); +protected: + void createTabs(); private: bool eventFilter(QObject *target, QEvent *event); ReportDesignWidget(ReportEnginePrivate* report,QMainWindow *mainWindow,QWidget *parent = 0); private: ReportEnginePrivate* m_report; QGraphicsView *m_view; + QTextEdit* m_scriptEditor; QMainWindow *m_mainWindow; + QTabWidget* m_tabWidget; GraphicsViewZoomer* m_zoomer; QFont m_defaultFont; int m_verticalGridStep; diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index b0ebae7..b7a6d0b 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -47,6 +47,7 @@ #include "lrbasedesignobjectmodel.h" #include "lrreportdesignwidget.h" #include "lrdatabrowser.h" +#include "scriptbrowser/lrscriptbrowser.h" #include "lrbasedesignintf.h" #include "lrpagedesignintf.h" @@ -70,6 +71,7 @@ ReportDesignWindow::ReportDesignWindow(ReportEnginePrivate *report, QWidget *par createToolBars(); createObjectInspector(); createDataWindow(); + createScriptWindow(); createObjectsBrowser(); m_instance=this; m_statusBar=new QStatusBar(this); @@ -96,6 +98,15 @@ void ReportDesignWindow::createActions() m_newReportAction->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_N)); connect(m_newReportAction,SIGNAL(triggered()),this,SLOT(slotNewReport())); + m_newPageAction = new QAction(tr("New Report Page"),this); + m_newPageAction->setIcon(QIcon(":/report/images/addPage")); + connect(m_newPageAction,SIGNAL(triggered()),this,SLOT(slotNewPage())); + + m_deletePageAction = new QAction(tr("Delete Report Page"),this); + m_deletePageAction->setIcon(QIcon(":/report/images/deletePage")); + connect(m_deletePageAction,SIGNAL(triggered()),this,SLOT(slotDeletePage())); + m_deletePageAction->setEnabled(false); + m_editModeAction = new QAction(tr("Edit Mode"),this); m_editModeAction->setIcon(QIcon(":/report/images/editMode")); m_editModeAction->setCheckable(true); @@ -261,6 +272,10 @@ void ReportDesignWindow::createToolBars() m_mainToolBar->addAction(m_settingsAction); m_mainToolBar->addSeparator(); + m_mainToolBar->addAction(m_newPageAction); + m_mainToolBar->addAction(m_deletePageAction); + m_mainToolBar->addSeparator(); + m_mainToolBar->addAction(m_copyAction); m_mainToolBar->addAction(m_pasteAction); m_mainToolBar->addAction(m_cutAction); @@ -421,18 +436,18 @@ void ReportDesignWindow::initReportEditor(ReportEnginePrivate* report) { m_reportDesignWidget=new ReportDesignWidget(report,this,this); setCentralWidget(m_reportDesignWidget); - connect(m_reportDesignWidget, SIGNAL(itemSelected(LimeReport::BaseDesignIntf*)), - this, SLOT(slotItemSelected(LimeReport::BaseDesignIntf*))); - connect(m_reportDesignWidget, SIGNAL(itemPropertyChanged(QString,QString,QVariant,QVariant)), - this, SLOT(slotItemPropertyChanged(QString,QString,QVariant,QVariant))); - connect(m_reportDesignWidget, SIGNAL(insertModeStarted()), this, SLOT(slotInsertModeStarted())); - - connect(m_reportDesignWidget, SIGNAL(multiItemSelected()), this, SLOT(slotMultiItemSelected())); - connect(m_reportDesignWidget, SIGNAL(itemInserted(LimeReport::PageDesignIntf*,QPointF,QString)), - this, SLOT(slotItemInserted(LimeReport::PageDesignIntf*,QPointF,QString))); - connect(m_reportDesignWidget, SIGNAL(itemInsertCanceled(QString)), this, SLOT(slotItemInsertCanceled(QString))); - connect(m_reportDesignWidget->report(),SIGNAL(datasourceCollectionLoadFinished(QString)), this, SLOT(slotUpdateDataBrowser(QString))); - connect(m_reportDesignWidget, SIGNAL(commandHistoryChanged()),this,SLOT(slotCommandHistoryChanged())); + connect(m_reportDesignWidget,SIGNAL(itemSelected(LimeReport::BaseDesignIntf*)), + this,SLOT(slotItemSelected(LimeReport::BaseDesignIntf*))); + connect(m_reportDesignWidget,SIGNAL(itemPropertyChanged(QString,QString,QVariant,QVariant)), + this,SLOT(slotItemPropertyChanged(QString,QString,QVariant,QVariant))); + connect(m_reportDesignWidget,SIGNAL(insertModeStarted()),this,SLOT(slotInsertModeStarted())); + connect(m_reportDesignWidget,SIGNAL(multiItemSelected()),this,SLOT(slotMultiItemSelected())); + connect(m_reportDesignWidget,SIGNAL(itemInserted(LimeReport::PageDesignIntf*,QPointF,QString)), + this,SLOT(slotItemInserted(LimeReport::PageDesignIntf*,QPointF,QString))); + connect(m_reportDesignWidget,SIGNAL(itemInsertCanceled(QString)),this,SLOT(slotItemInsertCanceled(QString))); + connect(m_reportDesignWidget->report(),SIGNAL(datasourceCollectionLoadFinished(QString)),this,SLOT(slotUpdateDataBrowser(QString))); + connect(m_reportDesignWidget,SIGNAL(commandHistoryChanged()),this,SLOT(slotCommandHistoryChanged())); + connect(m_reportDesignWidget,SIGNAL(activePageChanged()),this,SLOT(slotActivePageChanged())); connect(m_reportDesignWidget, SIGNAL(bandAdded(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*)), this, SLOT(slotBandAdded(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*))); connect(m_reportDesignWidget, SIGNAL(bandDeleted(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*)), @@ -440,6 +455,8 @@ void ReportDesignWindow::initReportEditor(ReportEnginePrivate* report) connect(m_reportDesignWidget->report(), SIGNAL(renderStarted()), this, SLOT(renderStarted())); connect(m_reportDesignWidget->report(), SIGNAL(renderPageFinished(int)), this, SLOT(renderPageFinished(int))); connect(m_reportDesignWidget->report(), SIGNAL(renderFinished()), this, SLOT(renderFinished())); + connect(m_reportDesignWidget, SIGNAL(pageAdded(PageDesignIntf*)), this, SLOT(slotPageAdded(PageDesignIntf*))); + connect(m_reportDesignWidget, SIGNAL(pageDeleted()), this, SLOT(slotPageDeleted())); } void ReportDesignWindow::createObjectInspector() @@ -491,6 +508,20 @@ void ReportDesignWindow::createDataWindow() m_dataBrowser->setReportEditor(m_reportDesignWidget); } +void ReportDesignWindow::createScriptWindow() +{ + QDockWidget *dataDoc = new QDockWidget(this); + dataDoc->setWindowTitle(tr("Script Browser")); + m_scriptBrowser=new ScriptBrowser(dataDoc); + dataDoc->setWidget(m_scriptBrowser); + dataDoc->setObjectName("scriptDoc"); + addDockWidget(Qt::LeftDockWidgetArea,dataDoc); + m_scriptBrowser->setReportEditor(m_reportDesignWidget); +#ifdef HAVE_UI_LOADER + m_scriptBrowser->updateDialogsTree(); +#endif +} + void ReportDesignWindow::updateRedoUndo() { m_undoAction->setEnabled(m_reportDesignWidget->isCanUndo()); @@ -701,7 +732,24 @@ QSettings*ReportDesignWindow::settings() void ReportDesignWindow::slotNewReport() { - if (checkNeedToSave()) startNewReport(); + if (checkNeedToSave()) { + m_lblReportName->setText(""); + startNewReport(); + m_deletePageAction->setEnabled(false); + } +} + +void ReportDesignWindow::slotNewPage(){ + if (m_reportDesignWidget){ + m_reportDesignWidget->addPage(); + } +} + +void ReportDesignWindow::slotDeletePage() +{ + if (m_reportDesignWidget && m_reportDesignWidget->report()->pageCount()>1){ + m_reportDesignWidget->deleteCurrentPage(); + } } void ReportDesignWindow::slotNewTextItem() @@ -872,12 +920,32 @@ void ReportDesignWindow::slotLoadReport() QApplication::processEvents(); setCursor(Qt::WaitCursor); m_reportDesignWidget->clear(); - m_reportDesignWidget->loadFromFile(fileName); - m_lblReportName->setText(fileName); - m_propertyModel->setObject(0); - updateRedoUndo(); + if (m_reportDesignWidget->loadFromFile(fileName)){ + m_lblReportName->setText(fileName); + m_propertyModel->setObject(0); + updateRedoUndo(); + setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); + if (!m_recentFiles.contains(fileName)){ + if (m_recentFiles.count()==10){ + QMap::const_iterator it = m_recentFiles.constBegin(); + QDateTime minDate = QDateTime::currentDateTime(); + while (it != m_recentFiles.constEnd()) { + if (minDate>it.value()) minDate = it.value(); + ++it; + } + m_recentFiles.remove(m_recentFiles.key(minDate)); + } + m_recentFiles.insert(fileName,QDateTime::currentDateTime()); + } else { + m_recentFiles[fileName] = QDateTime::currentDateTime(); + } + createRecentFilesMenu(); + m_deletePageAction->setEnabled(m_reportDesignWidget->report()->pageCount()>1); + } else { + slotNewReport(); + } unsetCursor(); - setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); + setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); addRecentFile(fileName); } } @@ -951,13 +1019,13 @@ void ReportDesignWindow::slotTest() void ReportDesignWindow::slotPrintReport() { setCursor(Qt::WaitCursor); - m_reportDesignWidget->report()->printReport(); + m_reportDesignWidget->printReport(); setCursor(Qt::ArrowCursor); } void ReportDesignWindow::slotPreviewReport() { - m_reportDesignWidget->report()->previewReport(); + m_reportDesignWidget->previewReport(); } void ReportDesignWindow::slotItemActionCliked() @@ -1010,6 +1078,12 @@ void ReportDesignWindow::slotBandDeleted(PageDesignIntf *, BandDesignIntf *band) } } +void ReportDesignWindow::slotActivePageChanged() +{ + m_propertyModel->setObject(0); + updateRedoUndo(); +} + void ReportDesignWindow::renderStarted() { if (m_showProgressDialog){ @@ -1104,6 +1178,16 @@ void ReportDesignWindow::slotLoadRecentFile(const QString fileName) } } +void ReportDesignWindow::slotPageAdded(PageDesignIntf *page) +{ + m_deletePageAction->setEnabled(m_reportDesignWidget->report()->pageCount()>1); +} + +void ReportDesignWindow::slotPageDeleted() +{ + m_deletePageAction->setEnabled(m_reportDesignWidget->report()->pageCount()>1); +} + void ReportDesignWindow::closeEvent(QCloseEvent * event) { if (checkNeedToSave()){ diff --git a/limereport/lrreportdesignwindow.h b/limereport/lrreportdesignwindow.h index d70f4a9..474d212 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -50,6 +50,7 @@ class ObjectInspectorWidget; class QObjectPropertyModel; class ReportDesignWidget; class DataBrowser; +class ScriptBrowser; class BaseDesignIntf; class PageDesignIntf; class ObjectBrowser; @@ -72,6 +73,8 @@ public: private slots: void slotNewReport(); + void slotNewPage(); + void slotDeletePage(); void slotNewTextItem(); void slotNewBand(const QString& bandType); void slotNewBand(int bandType); @@ -103,6 +106,7 @@ private slots: void slotItemActionCliked(); void slotBandAdded(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*band); void slotBandDeleted(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*band); + void slotActivePageChanged(); void renderStarted(); void renderPageFinished(int renderedPageCount); void renderFinished(); @@ -113,6 +117,8 @@ private slots: void slotUseGrid(bool value); void slotUseMagnet(bool value); void slotLoadRecentFile(const QString fileName); + void slotPageAdded(PageDesignIntf* page); + void slotPageDeleted(); protected: void closeEvent(QCloseEvent *event); void resizeEvent(QResizeEvent *); @@ -130,6 +136,7 @@ private: void createObjectsBrowser(); void initReportEditor(ReportEnginePrivate* report); void createDataWindow(); + void createScriptWindow(); void updateRedoUndo(); void startNewReport(); void writePosition(); @@ -174,6 +181,8 @@ private: QAction* m_settingsAction; QAction* m_useGridAction; QAction* m_useMagnetAction; + QAction* m_newPageAction; + QAction* m_deletePageAction; QAction* m_newPageHeader; QAction* m_newPageFooter; @@ -202,6 +211,7 @@ private: ReportDesignWidget* m_reportDesignWidget; DataBrowser * m_dataBrowser; + ScriptBrowser* m_scriptBrowser; ObjectBrowser* m_objectsBrowser; diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 7a63217..aaf8dfa 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -61,6 +61,7 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) : m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")) { m_datasources= new DataSourceManager(this); + m_scriptEngineContext = new ScriptEngineContext(this); m_datasources->setObjectName("datasources"); connect(m_datasources,SIGNAL(loadCollectionFinished(QString)),this,SLOT(slotDataSourceCollectionLoaded(QString))); } @@ -103,6 +104,17 @@ PageDesignIntf *ReportEnginePrivate::appendPage(const QString &pageName) return page; } +bool ReportEnginePrivate::deletePage(PageDesignIntf *page){ + QList::iterator it = m_pages.begin(); + while (it != m_pages.end()){ + if (*it == page) { + it = m_pages.erase(it); + return true; + } else ++it; + } + return false; +} + PageDesignIntf *ReportEnginePrivate::createPreviewPage() { return createPage(); @@ -152,6 +164,7 @@ void ReportEnginePrivate::clearReport() m_pages.clear(); m_datasources->clear(DataSourceManager::Owned); m_fileName=""; + m_scriptEngineContext->clear(); emit cleared(); } @@ -261,9 +274,44 @@ bool ReportEnginePrivate::printReport(QPrinter* printer) printer =(printer)?printer:m_printer.data(); if (printer&&printer->isValid()){ try{ - dataManager()->setDesignTime(false); - printReport(renderToPages(),*printer,PrintRange()); + dataManager()->setDesignTime(false); + ReportPages pages = renderToPages(); dataManager()->setDesignTime(true); + if (pages.count()>0){ + printReport(pages,*printer,PrintRange()); + } + } catch(ReportError &exception){ + saveError(exception.what()); + } + return true; + } else return false; +} + +bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer, PrintRange printRange) +{ + + if (!printer&&!m_printerSelected){ + QPrintDialog dialog(m_printer.data(),QApplication::activeWindow()); + m_printerSelected = dialog.exec()!=QDialog::Rejected; + if (m_printerSelected){ + printRange.setRangeType(dialog.printRange()); + printRange.setFromPage(dialog.fromPage()); + printRange.setToPage(dialog.toPage()); + } + + } + if (!printer&&!m_printerSelected) return false; + + printer =(printer)?printer:m_printer.data(); + if (printer&&printer->isValid()){ + try{ + if (pages.count()>0){ + printReport( + pages, + *printer, + printRange + ); + } } catch(ReportError &exception){ saveError(exception.what()); } @@ -401,6 +449,11 @@ void ReportEnginePrivate::cancelRender() m_reportRender->cancelRender(); } +PageDesignIntf* ReportEngine::createPreviewScene(QObject* parent){ + Q_D(ReportEngine); + return d->createPreviewScene(parent); +} + void ReportEnginePrivate::designReport() { if (!m_designerWindow) { @@ -456,7 +509,8 @@ bool ReportEnginePrivate::loadFromFile(const QString &fileName) dataManager()->connectAutoConnections(); return true; }; - } + } + m_lastError = reader->lastError(); return false; } @@ -555,6 +609,7 @@ QString ReportEnginePrivate::renderToString() dataManager()->setDesignTime(false); if (m_pages.count()){ render.setDatasources(dataManager()); + render.setScriptContext(scriptContext()); return render.renderPageToString(m_pages.at(0)); }else return QString(); } @@ -588,12 +643,18 @@ ReportPages ReportEnginePrivate::renderToPages() connect(m_reportRender.data(),SIGNAL(pageRendered(int)), this, SIGNAL(renderPageFinished(int))); if (m_pages.count()){ + ReportPages result; emit renderStarted(); m_reportRender->setDatasources(dataManager()); - ReportPages result = m_reportRender->renderPageToPages(m_pages.at(0)); + m_reportRender->setScriptContext(scriptContext()); + + foreach(PageDesignIntf* page , m_pages){ + result.append(m_reportRender->renderPageToPages(page)); + } emit renderFinished(); + m_reportRender.clear(); return result; - }else { + } else { return ReportPages(); } } @@ -628,6 +689,11 @@ bool ReportEngine::printReport(QPrinter *printer) return d->printReport(printer); } +bool ReportEngine::printPages(ReportPages pages, QPrinter *printer, PrintRange printRange){ + Q_D(ReportEngine); + return d->printPages(pages,printer, printRange); +} + void ReportEngine::printToFile(const QString &fileName) { Q_D(ReportEngine); diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index afbbcdc..94b78d2 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -60,6 +60,10 @@ private: class DataSourceManager; class ReportEnginePrivate; +class PageDesignIntf; +class PageItemDesignIntf; + +typedef QList< QSharedPointer > ReportPages; class LIMEREPORT_EXPORT ReportEngine : public QObject{ Q_OBJECT @@ -69,7 +73,9 @@ public: explicit ReportEngine(QObject *parent = 0); ~ReportEngine(); bool printReport(QPrinter *printer=0); + bool printPages(ReportPages pages, QPrinter *printer, PrintRange printRange = PrintRange()); void printToFile(const QString& fileName); + PageDesignIntf *createPreviewScene(QObject *parent = 0); bool printToPDF(const QString& fileName); void previewReport(); void designReport(); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index da9ce08..d015d50 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -55,7 +55,8 @@ class ReportEnginePrivate : public QObject, public ICollectionContainer Q_OBJECT Q_DECLARE_PUBLIC(ReportEngine) Q_PROPERTY(ACollectionProperty pages READ fakeCollectionReader()) - Q_PROPERTY(QObject* datasourcesManager READ dataManager()) + Q_PROPERTY(QObject* datasourcesManager READ dataManager) + Q_PROPERTY(QObject* scriptContext READ scriptContext) friend class PreviewReportWidget; public: static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer); @@ -63,12 +64,16 @@ public: public: explicit ReportEnginePrivate(QObject *parent = 0); virtual ~ReportEnginePrivate(); - PageDesignIntf* appendPage(const QString &pageName = ""); - PageDesignIntf* createPreviewPage(); - PageDesignIntf* pageAt(int index){return (index<=(m_pages.count()-1)) ? m_pages.at(index):0;} - int pageCount() {return m_pages.count();} - DataSourceManager* dataManager(){return m_datasources;} - IDataSourceManager* dataManagerIntf(){return m_datasources;} + + PageDesignIntf* appendPage(const QString& pageName=""); + bool deletePage(PageDesignIntf *page); + PageDesignIntf* createPreviewPage(); + PageDesignIntf* pageAt(int index){return (index<=(m_pages.count()-1)) ? m_pages.at(index):0;} + int pageCount() {return m_pages.count();} + DataSourceManager* dataManager(){return m_datasources;} + ScriptEngineContext* scriptContext(){return m_scriptEngineContext;} + ScriptEngineManager* scriptManager(){return &ScriptEngineManager::instance();} + IDataSourceManager* dataManagerIntf(){return m_datasources;} IScriptEngineManager* scriptManagerIntf(){ ScriptEngineManager::instance().setDataManager(dataManager()); @@ -77,6 +82,7 @@ public: void clearReport(); bool printReport(QPrinter *printer=0); + bool printPages(ReportPages pages, QPrinter *printer, PrintRange printRange = PrintRange()); void printToFile(const QString& fileName); bool printToPDF(const QString& fileName); void previewReport(); @@ -144,6 +150,7 @@ private: private: QList m_pages; DataSourceManager* m_datasources; + ScriptEngineContext* m_scriptEngineContext; ReportRender::Ptr m_reportRender; QString m_fileName; QString m_lastError; diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 8446336..12f6e42 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -158,6 +158,19 @@ void ReportRender::setDatasources(DataSourceManager *value) m_datasources=value; } +void ReportRender::setScriptContext(ScriptEngineContext* scriptContext) +{ + m_scriptEngineContext=scriptContext; +} + +bool ReportRender::runInitScript(){ + if (m_scriptEngineContext){ + QScriptValue res = ScriptEngineManager::instance().scriptEngine()->evaluate(m_scriptEngineContext->initScript()); + if (res.isBool()) return res.toBool(); + } + return true; +} + void ReportRender::initDatasources(){ try{ datasources()->setAllDatasourcesToFirst(); @@ -181,6 +194,20 @@ void ReportRender::renderPage(PageDesignIntf* patternPage) initVariables(); initGroupFunctions(); +#ifdef HAVE_UI_LOADER + initDialogs(); +#endif + if (runInitScript()){ + + clearPageMap(); + + try{ + datasources()->setAllDatasourcesToFirst(); + } catch(ReportError &exception){ + //TODO posible should thow exeption + QMessageBox::critical(0,tr("Error"),exception.what()); + return; + } clearPageMap(); resetPageNumber(); @@ -204,6 +231,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage) savePage(); if (!m_renderCanceled) secondRenderPass(); + } } int ReportRender::pageCount() @@ -244,6 +272,18 @@ void ReportRender::initVariables() m_datasources->setReportVariable("#PAGE_COUNT",0); } +#ifdef HAVE_UI_LOADER +void ReportRender::initDialogs(){ + if (m_scriptEngineContext){ + QScriptEngine* se = ScriptEngineManager::instance().scriptEngine(); + foreach(DialogDescriber::Ptr dialog, m_scriptEngineContext->dialogsDescriber()){ + QScriptValue sv = se->newQObject(m_scriptEngineContext->getDialog(dialog->name())); + se->globalObject().setProperty(dialog->name(),sv); + } + } +} +#endif + void ReportRender::clearPageMap() { m_renderedPages.clear(); @@ -523,6 +563,10 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da dataSource->next(); } closeDataGroup(band); +// if (gb->isNeedToStartNewPage()){ +// savePage(); +// startNewPage(); +// } } if (!gb->isStarted()){ if (band->reprintOnEachPage()) @@ -851,6 +895,7 @@ void ReportRender::startNewPage() m_currentIndex=0; renderPageHeader(m_patternPageItem); + //renderPageFooter(m_patternPageItem); m_pageFooterHeight = calcPageFooterHeight(m_patternPageItem); m_maxHeightByColumn[m_currentColumn] -= m_pageFooterHeight; m_currentIndex=10; diff --git a/limereport/lrreportrender.h b/limereport/lrreportrender.h index a5c7562..ee583a4 100644 --- a/limereport/lrreportrender.h +++ b/limereport/lrreportrender.h @@ -33,6 +33,7 @@ #include "lrcollection.h" #include "lrdatasourcemanager.h" #include "lrpageitemdesignintf.h" +#include "lrscriptenginemanager.h" #include "serializators/lrstorageintf.h" namespace LimeReport{ @@ -55,7 +56,6 @@ private: bool m_footerGroup; }; -typedef QList ReportPages; struct PagesRange{ int firstPage; @@ -73,6 +73,7 @@ public: ~ReportRender(); ReportRender(QObject *parent = 0); void setDatasources(DataSourceManager* value); + void setScriptContext(ScriptEngineContext* scriptContext); DataSourceManager* datasources(){return m_datasources;} int pageCount(); PageItemDesignIntf::Ptr pageAt(int index); @@ -86,7 +87,11 @@ private: void renderPage(PageDesignIntf *patternPage); void initDatasources(); void initRenderPage(); +#ifdef HAVE_UI_LOADER + void initDialogs(); +#endif void initVariables(); + bool runInitScript(); void clearPageMap(); void renderBand(BandDesignIntf *patternBand, DataRenderMode mode = NotStartNewPage, bool isLast = false); void renderDataBand(BandDesignIntf* dataBand); @@ -141,6 +146,7 @@ private: void renameChildItems(BaseDesignIntf *item); private: DataSourceManager* m_datasources; + ScriptEngineContext* m_scriptEngineContext; PageItemDesignIntf* m_renderPageItem; PageItemDesignIntf* m_patternPageItem; QList m_renderedPages; diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index 1e3f264..b748e48 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -32,6 +32,11 @@ #include #include #include +#ifdef HAVE_UI_LOADER +#include +#include +#include +#endif #include "lrdatasourcemanager.h" Q_DECLARE_METATYPE(QColor) @@ -375,6 +380,11 @@ void ScriptEngineManager::setDataManager(DataSourceManager *dataManager){ } } +void ScriptEngineManager::updateModel() +{ + +} + ScriptEngineManager::ScriptEngineManager() :m_model(0), m_dataManager(0) { @@ -523,5 +533,196 @@ QString ScriptExtractor::substring(const QString &value, int start, int end) return value.mid(start,end-start); } +QString DialogDescriber::name() const +{ + return m_name; +} + +void DialogDescriber::setName(const QString& name) +{ + m_name = name; +} + +QByteArray DialogDescriber::description() const +{ + return m_description; +} + +void DialogDescriber::setDescription(const QByteArray &description) +{ + m_description = description; +} + +#ifdef HAVE_UI_LOADER +void ScriptEngineContext::addDialog(const QString& name, const QByteArray& description) +{ + m_dialogs.push_back(DialogDescriber::create(name,description)); +} + +bool ScriptEngineContext::previewDialog(const QString& dialogName) +{ + QDialog* dialog = getDialog(dialogName); + if (dialog) { + dialog->exec(); + return true; + } else { + m_lastError = tr("Dialog with name: %1 can`t be created").arg(dialogName); + return false; + } +} + +bool ScriptEngineContext::containsDialog(const QString& dialogName) +{ + foreach(DialogDescriber::Ptr dialog, m_dialogs){ + if (dialog->name()==dialogName) + return true; + } + return false; +} + +void ScriptEngineContext::deleteDialog(const QString& dialogName) +{ + { + QVector::Iterator it = m_dialogs.begin(); + while(it!=m_dialogs.end()){ + if ((*it)->name()==dialogName){ + it = m_dialogs.erase(it); + } else { + ++it; + } + } + } + { + QList::Iterator it = m_createdDialogs.begin(); + while(it!=m_createdDialogs.end()){ + if ((*it)->objectName()==dialogName){ + it = m_createdDialogs.erase(it); + } else { + ++it; + } + } + } +} + +#endif + +void ScriptEngineContext::clear() +{ +#ifdef HAVE_UI_LOADER + m_dialogs.clear(); + m_createdDialogs.clear(); +#endif + m_initScript.clear(); + m_lastError=""; +} + +QObject* ScriptEngineContext::createElement(const QString& collectionName, const QString& elementType) +{ + Q_UNUSED(elementType) +#ifdef HAVE_UI_LOADER + if (collectionName.compare("dialogs",Qt::CaseInsensitive)==0){ + m_dialogs.push_back(DialogDescriber::create()); + return m_dialogs.at(m_dialogs.count()-1).data(); + } +#else + Q_UNUSED(collectionName) +#endif + return 0; +} + +int ScriptEngineContext::elementsCount(const QString& collectionName) +{ +#ifdef HAVE_UI_LOADER + if (collectionName.compare("dialogs",Qt::CaseInsensitive)==0){ + return m_dialogs.count(); + }; +#else + Q_UNUSED(collectionName) +#endif + return 0; +} + +QObject* ScriptEngineContext::elementAt(const QString& collectionName, int index) +{ +#ifdef HAVE_UI_LOADER + if (collectionName.compare("dialogs",Qt::CaseInsensitive)==0){ + return m_dialogs.at(index).data(); + }; +#else + Q_UNUSED(collectionName) + Q_UNUSED(index) +#endif + return 0; +} + +void ScriptEngineContext::collectionLoadFinished(const QString& collectionName) +{ + Q_UNUSED(collectionName); +} + +#ifdef HAVE_UI_LOADER +QDialog* ScriptEngineContext::createDialog(DialogDescriber* cont) +{ + QUiLoader loader; + QByteArray desc = cont->description(); + QBuffer buffer(&desc); + buffer.open(QIODevice::ReadOnly); + QDialog* dialog = dynamic_cast(loader.load(&buffer)); + m_createdDialogs.push_back(QSharedPointer(dialog)); + return dialog; +} + +QDialog* ScriptEngineContext::findDialog(const QString& dialogName) +{ + foreach(DialogPtr dialog, m_createdDialogs){ + if (dialog->objectName()==dialogName) + return dialog.data(); + } + return 0; +} + +DialogDescriber* ScriptEngineContext::findDialogContainer(const QString& dialogName) +{ + foreach (DialogDescriber::Ptr dialogCont , m_dialogs) { + if (dialogCont->name().compare(dialogName,Qt::CaseInsensitive)==0){ + return dialogCont.data(); + } + } + return 0; +} + +QDialog* ScriptEngineContext::getDialog(const QString& dialogName) +{ + QDialog* dialog = findDialog(dialogName); + if (dialog){ + return dialog; + } else { + DialogDescriber* cont = findDialogContainer(dialogName); + if (cont){ + dialog = createDialog(cont); + if (dialog) + return dialog; + } + } + return 0; +} +#endif +QString ScriptEngineContext::initScript() const +{ + return m_initScript; +} + +void ScriptEngineContext::setInitScript(const QString& initScript) +{ + m_initScript = initScript; +} + +DialogDescriber::Ptr DialogDescriber::create(const QString& name, const QByteArray& desc) { + Ptr res(new DialogDescriber()); + res->setName(name); + res->setDescription(desc); + return res; +} + } //namespace LimeReport diff --git a/limereport/lrscriptenginemanager.h b/limereport/lrscriptenginemanager.h index 155b4c3..32ef2c5 100644 --- a/limereport/lrscriptenginemanager.h +++ b/limereport/lrscriptenginemanager.h @@ -39,8 +39,13 @@ #include #include +#ifdef HAVE_UI_LOADER +#include +#endif + #include "base/lrsingleton.h" #include "lrscriptenginemanagerintf.h" +#include "lrcollection.h" namespace LimeReport{ @@ -57,7 +62,7 @@ struct ScriptFunctionDesc{ class ScriptEngineNode { public: - enum NodeType{Root,Category,Function}; + enum NodeType{Root,Category,Function,Dialog,DialogElement}; ScriptEngineNode(const QString& name="", const QString& description ="", NodeType type=Root, ScriptEngineNode* parent=0, const QIcon& icon=QIcon()) :m_name(name), m_description(description), m_icon(icon), m_type(type), m_parent(parent){} virtual ~ScriptEngineNode(); @@ -95,6 +100,7 @@ public: int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; void setScriptEngineManager(ScriptEngineManager* scriptManager); + inline ScriptEngineManager* scriptEngineManager(){return m_scriptManager;} private slots: void slotScriptEngineChanged(); private: @@ -105,6 +111,64 @@ private: ScriptEngineNode* m_rootNode; }; +class DialogDescriber : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QByteArray description READ description WRITE setDescription) +public: + typedef QSharedPointer Ptr; + static Ptr create(const QString& name, const QByteArray &desc); + static Ptr create(){return Ptr(new DialogDescriber);} + QString name() const; + void setName(const QString& name); + QByteArray description() const; + void setDescription(const QByteArray& description); +private : + QString m_name; + QByteArray m_description; +}; + +class ScriptEngineContext : public QObject, public ICollectionContainer +{ + Q_OBJECT + Q_PROPERTY(ACollectionProperty dialogs READ fakeCollectionReader) + Q_PROPERTY(QString initScript READ initScript WRITE setInitScript) +public: +#ifdef HAVE_UI_LOADER + typedef QSharedPointer DialogPtr; +#endif + explicit ScriptEngineContext(QObject* parent=0):QObject(parent){} +#ifdef HAVE_UI_LOADER + void addDialog(const QString& name, const QByteArray &description); + bool previewDialog(const QString& dialogName); + bool containsDialog(const QString& dialogName); + const QVector& dialogsDescriber(){return m_dialogs;} + void deleteDialog(const QString& dialogName); + QDialog *getDialog(const QString &dialogName); +#endif + void clear(); + QString initScript() const; + void setInitScript(const QString& initScript); +protected: + QObject* createElement(const QString& collectionName,const QString& elementType); + int elementsCount(const QString& collectionName); + QObject* elementAt(const QString& collectionName,int index); + void collectionLoadFinished(const QString &collectionName); +#ifdef HAVE_UI_LOADER + QDialog *createDialog(DialogDescriber *cont); + QDialog *findDialog(const QString &dialogName); + DialogDescriber* findDialogContainer(const QString& dialogName); +#endif +private: +#ifdef HAVE_UI_LOADER + QVector m_dialogs; + QList m_createdDialogs; +#endif + QString m_lastError; + QString m_initScript; +}; + class ScriptEngineManager : public QObject, public Singleton, public IScriptEngineManager { Q_OBJECT @@ -122,8 +186,11 @@ public: QStringList functionsNames(); const QList& functionsDescriber(){return m_functions;} ScriptEngineModel* model(){return m_model;} + void setContext(ScriptEngineContext* context){m_context=context;} DataSourceManager* dataManager() const {return m_dataManager;} void setDataManager(DataSourceManager* dataManager); +protected: + void updateModel(); private: Q_DISABLE_COPY(ScriptEngineManager) private: @@ -132,6 +199,7 @@ private: QString m_lastError; QList m_functions; ScriptEngineModel* m_model; + ScriptEngineContext* m_context; DataSourceManager* m_dataManager; }; diff --git a/limereport/objectinspector/editors/lrcoloreditor.cpp b/limereport/objectinspector/editors/lrcoloreditor.cpp index 0d743e5..e845d76 100644 --- a/limereport/objectinspector/editors/lrcoloreditor.cpp +++ b/limereport/objectinspector/editors/lrcoloreditor.cpp @@ -53,6 +53,7 @@ ColorEditor::ColorEditor(QWidget *parent) : setFocusProxy(m_button); setAutoFillBackground(true); setLayout(layout); + setAutoFillBackground(true); connect(m_button,SIGNAL(clicked()),this,SLOT(slotClicked())); } diff --git a/limereport/objectinspector/editors/lrimageeditor.cpp b/limereport/objectinspector/editors/lrimageeditor.cpp index c48d887..aae4f99 100644 --- a/limereport/objectinspector/editors/lrimageeditor.cpp +++ b/limereport/objectinspector/editors/lrimageeditor.cpp @@ -37,13 +37,17 @@ ImageEditor::ImageEditor(QWidget* parent) :QWidget(parent) { m_button.setIcon(QIcon(":items/ImageItem")); + m_clearButton.setIcon(QIcon(":items/clear.png")); QHBoxLayout* layout = new QHBoxLayout(this); layout->addWidget(&m_button); - layout->setSpacing(0); + layout->addWidget(&m_clearButton); + layout->setSpacing(1); layout->setContentsMargins(1,0,1,1); setLayout(layout); setFocusProxy(&m_button); + setAutoFillBackground(true); connect(&m_button,SIGNAL(clicked()),this,SLOT(slotButtonClicked())); + connect(&m_clearButton,SIGNAL(clicked()),this,SLOT(slotClearButtonClicked())); } QImage ImageEditor::image() @@ -57,4 +61,10 @@ void ImageEditor::slotButtonClicked() emit editingFinished(); } -} // namespace LimeReport +void ImageEditor::slotClearButtonClicked() +{ + m_image = QImage(); + emit editingFinished(); +} + +} //namespace LimeReport diff --git a/limereport/objectinspector/editors/lrimageeditor.h b/limereport/objectinspector/editors/lrimageeditor.h index ada3c87..4b116b7 100644 --- a/limereport/objectinspector/editors/lrimageeditor.h +++ b/limereport/objectinspector/editors/lrimageeditor.h @@ -46,8 +46,10 @@ signals: void editingFinished(); private slots: void slotButtonClicked(); + void slotClearButtonClicked(); private: QPushButton m_button; + QPushButton m_clearButton; QImage m_image; }; diff --git a/limereport/objectinspector/lrobjectpropitem.h b/limereport/objectinspector/lrobjectpropitem.h index 6e2d796..6c3045b 100644 --- a/limereport/objectinspector/lrobjectpropitem.h +++ b/limereport/objectinspector/lrobjectpropitem.h @@ -88,7 +88,7 @@ namespace LimeReport{ void setColorIndex(int propertyValue); void setModel(QAbstractItemModel* model){m_model=model;} QAbstractItemModel* model(){return m_model;} - void setModelIndex(QModelIndex index){m_index=index;} + void setModelIndex(const QModelIndex& index){m_index=index;} QModelIndex modelIndex(){return m_index;} bool isClass(){return m_isClass;} #ifdef INSPECT_BASEDESIGN diff --git a/limereport/objectsbrowser/lrobjectbrowser.cpp b/limereport/objectsbrowser/lrobjectbrowser.cpp index c9c7f6e..07192f7 100644 --- a/limereport/objectsbrowser/lrobjectbrowser.cpp +++ b/limereport/objectsbrowser/lrobjectbrowser.cpp @@ -106,6 +106,7 @@ void ObjectBrowser::buildTree(BaseDesignIntf* ignoredItem){ m_treeView->clear(); m_itemsMap.clear(); + if (!m_report->activePage()) return; ObjectBrowserNode *topLevelItem=new ObjectBrowserNode(m_treeView); topLevelItem->setText(0,m_report->activePage()->objectName()); @@ -204,7 +205,7 @@ void ObjectBrowser::slotItemDeleted(PageDesignIntf *, BaseDesignIntf *item) void ObjectBrowser::slotObjectTreeItemSelectionChanged() { - if (!m_changingItemSelection){ + if (!m_changingItemSelection && m_report->activePage()){ m_changingItemSelection = true; m_report->activePage()->clearSelection(); foreach(QTreeWidgetItem* item, m_treeView->selectedItems()){ @@ -214,6 +215,10 @@ void ObjectBrowser::slotObjectTreeItemSelectionChanged() if (si) { m_report->activePage()->animateItem(si); si->setSelected(true); + QPointF p = si->mapToScene(si->pos()); + if (si->parentItem()) + p = si->parentItem()->mapToScene(si->pos()); + m_report->activeView()->centerOn(p); } } } diff --git a/limereport/report.qrc b/limereport/report.qrc index ad0f243..a2c526c 100644 --- a/limereport/report.qrc +++ b/limereport/report.qrc @@ -165,5 +165,7 @@ images/FitWidth.png images/OneToOne.png images/logo_32x32.png + images/addPage1.png + images/deletePage1.png diff --git a/limereport/scriptbrowser/images/Dialog.png b/limereport/scriptbrowser/images/Dialog.png new file mode 100644 index 0000000..f6cc4e3 Binary files /dev/null and b/limereport/scriptbrowser/images/Dialog.png differ diff --git a/limereport/scriptbrowser/images/Dialog_add.png b/limereport/scriptbrowser/images/Dialog_add.png new file mode 100644 index 0000000..144134f Binary files /dev/null and b/limereport/scriptbrowser/images/Dialog_add.png differ diff --git a/limereport/scriptbrowser/images/Dialog_delete.png b/limereport/scriptbrowser/images/Dialog_delete.png new file mode 100644 index 0000000..9e069d6 Binary files /dev/null and b/limereport/scriptbrowser/images/Dialog_delete.png differ diff --git a/limereport/scriptbrowser/images/Dialog_run.png b/limereport/scriptbrowser/images/Dialog_run.png new file mode 100644 index 0000000..345bab9 Binary files /dev/null and b/limereport/scriptbrowser/images/Dialog_run.png differ diff --git a/limereport/scriptbrowser/images/function3.png b/limereport/scriptbrowser/images/function3.png new file mode 100644 index 0000000..d6371b9 Binary files /dev/null and b/limereport/scriptbrowser/images/function3.png differ diff --git a/limereport/scriptbrowser/images/function_add.png b/limereport/scriptbrowser/images/function_add.png new file mode 100644 index 0000000..259a781 Binary files /dev/null and b/limereport/scriptbrowser/images/function_add.png differ diff --git a/limereport/scriptbrowser/images/function_delete.png b/limereport/scriptbrowser/images/function_delete.png new file mode 100644 index 0000000..4046838 Binary files /dev/null and b/limereport/scriptbrowser/images/function_delete.png differ diff --git a/limereport/scriptbrowser/images/function_edit.png b/limereport/scriptbrowser/images/function_edit.png new file mode 100644 index 0000000..f68aa20 Binary files /dev/null and b/limereport/scriptbrowser/images/function_edit.png differ diff --git a/limereport/scriptbrowser/images/green_cube.png b/limereport/scriptbrowser/images/green_cube.png new file mode 100644 index 0000000..2f0b2bd Binary files /dev/null and b/limereport/scriptbrowser/images/green_cube.png differ diff --git a/limereport/scriptbrowser/images/green_cube1.png b/limereport/scriptbrowser/images/green_cube1.png new file mode 100644 index 0000000..3b9fc5c Binary files /dev/null and b/limereport/scriptbrowser/images/green_cube1.png differ diff --git a/limereport/scriptbrowser/lrscriptbrowser.cpp b/limereport/scriptbrowser/lrscriptbrowser.cpp new file mode 100644 index 0000000..ea38798 --- /dev/null +++ b/limereport/scriptbrowser/lrscriptbrowser.cpp @@ -0,0 +1,195 @@ +/*************************************************************************** + * This file is part of the Lime Report project * + * Copyright (C) 2015 by Alexander Arin * + * arin_a@bk.ru * + * * + ** GNU General Public License Usage ** + * * + * This library is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ** GNU Lesser General Public License ** + * * + * This library is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library. * + * If not, see . * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + ****************************************************************************/ +#include "lrscriptbrowser.h" +#include "ui_lrscriptbrowser.h" + +#ifdef HAVE_UI_LOADER +#include +#include +#endif +#include + +namespace LimeReport{ + +ScriptBrowser::ScriptBrowser(QWidget *parent) : + QWidget(parent), + ui(new Ui::ScriptBrowser) +{ + ui->setupUi(this); +#ifndef HAVE_UI_LOADER + ui->tpDialogs->setVisible(false); + ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tpDialogs)); +#endif +} + +ScriptBrowser::~ScriptBrowser() +{ + delete ui; +} + +void ScriptBrowser::setReportEditor(ReportDesignWidget* report) +{ + m_report=report; + connect(m_report,SIGNAL(cleared()),this,SLOT(slotClear())); + connect(m_report,SIGNAL(loaded()),this,SLOT(slotUpdate())); + updateFunctionTree(); +} + +void ScriptBrowser::updateFunctionTree() +{ + ScriptEngineManager* sm = reportEditor()->scriptManager(); + QMap categ; + foreach(ScriptFunctionDesc fd, sm->functionsDescriber()){ + QString functionCategory = (fd.category!="") ? fd.category : tr("NO CATEGORY"); + if (categ.contains(functionCategory)){ + QTreeWidgetItem* item = new QTreeWidgetItem(categ.value(fd.category),QStringList(fd.name)); + item->setIcon(0,QIcon(":/report/images/function")); + } else { + QTreeWidgetItem* categItem = new QTreeWidgetItem(ui->twFunctions,QStringList(functionCategory)); + categItem->setIcon(0,QIcon(":/report/images/folder")); + categ.insert(functionCategory,categItem); + QTreeWidgetItem* item = new QTreeWidgetItem(categItem,QStringList(fd.name)); + item->setIcon(0,QIcon(":/report/images/function")); + } + } +} + +#ifdef HAVE_UI_LOADER +void ScriptBrowser::fillProperties(QTreeWidgetItem* objectItem, QObject* item){ + for(int i=0; imetaObject()->propertyCount(); ++i){ + QStringList row; + row<metaObject()->property(i).typeName()<metaObject()->property(i).name(); + /*QTreeWidgetItem* propItem = */new QTreeWidgetItem(objectItem,row); + } +} + +void ScriptBrowser::fillDialog(QTreeWidgetItem* dialogItem,const QString& description){ + + QUiLoader loader; + QByteArray baDesc = description.toUtf8(); + QBuffer buff(&baDesc); + buff.open(QIODevice::ReadOnly); + QDialog* dialog = dynamic_cast(loader.load(&buff)); + if (dialog){ + foreach (QObject* child, dialog->children()) { + if (!child->objectName().isEmpty()){ + QStringList row; + row<metaObject()->className()<objectName(); + QTreeWidgetItem* item = new QTreeWidgetItem(dialogItem,row); + item->setIcon(0,QIcon(":/scriptbrowser/images/item")); + fillProperties(item,child); + } + } + delete dialog; + } + +} + +void ScriptBrowser::updateDialogsTree() +{ + ui->twDialogs->clear(); + ScriptEngineContext* sc = reportEditor()->scriptContext(); + foreach(DialogDescriber::Ptr dc, sc->dialogsDescriber()){ + QTreeWidgetItem* dialogItem = new QTreeWidgetItem(ui->twDialogs,QStringList(dc->name())); + dialogItem->setIcon(0,QIcon(":/scriptbrowser/images/dialog")); + fillDialog(dialogItem,dc->description()); + } +} +#endif +void ScriptBrowser::slotClear() +{ + ui->twDialogs->clear(); + ui->twFunctions->clear(); +} + +void ScriptBrowser::slotUpdate() +{ +#ifdef HAVE_UI_LOADER + updateDialogsTree(); +#endif + updateFunctionTree(); +} + +#ifdef HAVE_UI_LOADER +void ScriptBrowser::on_tbAddDialog_clicked() +{ + QFileDialog fileDialog(this); + if (fileDialog.exec()==QDialog::Accepted){ + QStringList fileNames = fileDialog.selectedFiles(); + QUiLoader loader; + + if (!fileNames.isEmpty()){ + foreach (QString fileName, fileNames) { + QFile file(fileName); + file.open(QIODevice::ReadOnly); + if (file.isOpen()){ + QWidget* widget = loader.load(&file); + QDialog* dialog = dynamic_cast(widget); + if (dialog){ + if (!m_report->scriptContext()->containsDialog(dialog->objectName())){ + file.seek(0); + m_report->scriptContext()->addDialog(dialog->objectName(),file.readAll()); + updateDialogsTree(); + } else { + QMessageBox::critical(this,tr("Error"),tr("Dialog with name: %1 already exists").arg(dialog->objectName())); + } + } else { + if (widget) + QMessageBox::critical(this,tr("Error"),tr("ui file must cointain QDialog instead QWidget or QMainWindow")); + else + QMessageBox::critical(this,tr("Error"),tr("wrong file format")); + } + if (widget) delete widget; + } + } + } + } +} + +void ScriptBrowser::on_tbRunDialog_clicked() +{ + if (ui->twDialogs->currentItem()&& ui->twDialogs->currentItem()->parent()==0){ + m_report->scriptContext()->previewDialog(ui->twDialogs->currentItem()->text(0)); + } +} + +void ScriptBrowser::on_tbDeleteDialog_clicked() +{ + if (ui->twDialogs->currentItem()&& ui->twDialogs->currentItem()->parent()==0){ + m_report->scriptContext()->deleteDialog(ui->twDialogs->currentItem()->text(0)); + updateDialogsTree(); + } +} + +#endif + +} //namespace LimeReport + + diff --git a/limereport/scriptbrowser/lrscriptbrowser.h b/limereport/scriptbrowser/lrscriptbrowser.h new file mode 100644 index 0000000..3214617 --- /dev/null +++ b/limereport/scriptbrowser/lrscriptbrowser.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * This file is part of the Lime Report project * + * Copyright (C) 2015 by Alexander Arin * + * arin_a@bk.ru * + * * + ** GNU General Public License Usage ** + * * + * This library is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ** GNU Lesser General Public License ** + * * + * This library is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library. * + * If not, see . * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + ****************************************************************************/ +#ifndef LRSCRIPTBROWSER_H +#define LRSCRIPTBROWSER_H + +#include +#include +#include +#include "lrreportdesignwidget.h" + +namespace LimeReport{ + +namespace Ui { +class ScriptBrowser; +} + +class ScriptBrowser : public QWidget +{ + Q_OBJECT + +public: + explicit ScriptBrowser(QWidget *parent = 0); + ~ScriptBrowser(); + void setReportEditor(LimeReport::ReportDesignWidget* report); + inline ReportDesignWidget* reportEditor(){return m_report;} + void updateFunctionTree(); +#ifdef HAVE_UI_LOADER + void updateDialogsTree(); +#endif +protected: +#ifdef HAVE_UI_LOADER + void fillDialog(QTreeWidgetItem *dialogItem, const QString &description); + void fillProperties(QTreeWidgetItem *objectItem, QObject *item); +#endif +private slots: + void slotClear(); + void slotUpdate(); +#ifdef HAVE_UI_LOADER + void on_tbAddDialog_clicked(); + void on_tbRunDialog_clicked(); + void on_tbDeleteDialog_clicked(); +#endif + +private: + Ui::ScriptBrowser *ui; + ReportDesignWidget* m_report; +}; + +} // namespace LimeReport +#endif // LRSCRIPTBROWSER_H diff --git a/limereport/scriptbrowser/lrscriptbrowser.qrc b/limereport/scriptbrowser/lrscriptbrowser.qrc new file mode 100644 index 0000000..5ec7b02 --- /dev/null +++ b/limereport/scriptbrowser/lrscriptbrowser.qrc @@ -0,0 +1,14 @@ + + + images/Dialog.png + images/Dialog_add.png + images/Dialog_delete.png + images/Dialog_run.png + images/function3.png + images/function_add.png + images/function_delete.png + images/function_edit.png + images/green_cube.png + images/green_cube1.png + + diff --git a/limereport/scriptbrowser/lrscriptbrowser.ui b/limereport/scriptbrowser/lrscriptbrowser.ui new file mode 100644 index 0000000..d0a5384 --- /dev/null +++ b/limereport/scriptbrowser/lrscriptbrowser.ui @@ -0,0 +1,287 @@ + + + LimeReport::ScriptBrowser + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 1 + + + 1 + + + 1 + + + 1 + + + 2 + + + + + QTabWidget::South + + + 0 + + + + Functions + + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + 2 + + + + + ... + + + + :/scriptbrowser/images/function_add:/scriptbrowser/images/function_add + + + + 16 + 16 + + + + true + + + + + + + ... + + + + :/scriptbrowser/images/function_edit:/scriptbrowser/images/function_edit + + + + 16 + 16 + + + + true + + + + + + + ... + + + + :/scriptbrowser/images/function_delete:/scriptbrowser/images/function_delete + + + + 16 + 16 + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + false + + + + 1 + + + + + + + + + Dialogs + + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + 2 + + + + + ... + + + + :/scriptbrowser/images/dialog_add:/scriptbrowser/images/dialog_add + + + + 16 + 16 + + + + true + + + + + + + ... + + + + :/scriptbrowser/images/dialog_run:/scriptbrowser/images/dialog_run + + + + 16 + 16 + + + + true + + + + + + + ... + + + + :/scriptbrowser/images/dialog_delete:/scriptbrowser/images/dialog_delete + + + + 16 + 16 + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 2 + + + 131 + + + 100 + + + + Type + + + + + Name + + + + + + + + + + + + + + + diff --git a/limereport/serializators/lrxmlreader.cpp b/limereport/serializators/lrxmlreader.cpp index 4f2f282..545c4ca 100644 --- a/limereport/serializators/lrxmlreader.cpp +++ b/limereport/serializators/lrxmlreader.cpp @@ -204,6 +204,10 @@ bool FileXMLReader::prepareReader(QDomDocument *doc) QFile source(m_fileName); if (source.open(QFile::ReadOnly)) { doc->setContent(&source); + if (doc->documentElement().nodeName()!="Report") { + m_error = QString(QObject::tr("Wrong file format")); + return false; + } } else {m_error=QString(QObject::tr("File %1 not opened")).arg(m_fileName); return false;} } return true; diff --git a/limereport/serializators/lrxmlwriter.cpp b/limereport/serializators/lrxmlwriter.cpp index de1b9fb..dc70216 100644 --- a/limereport/serializators/lrxmlwriter.cpp +++ b/limereport/serializators/lrxmlwriter.cpp @@ -37,12 +37,19 @@ namespace LimeReport{ XMLWriter::XMLWriter() : m_doc(new QDomDocument) { - m_rootElement=m_doc->createElement("Report"); - m_doc->appendChild(m_rootElement); + init(); } XMLWriter::XMLWriter(QSharedPointer doc) : m_doc(doc){ + init(); +} + +void XMLWriter::init() +{ m_rootElement=m_doc->createElement("Report"); + QDomNode xmlNode = m_doc->createProcessingInstruction("xml", + "version=\"1.0\" encoding=\"UTF8\""); + m_doc->insertBefore(xmlNode,m_doc->firstChild()); m_doc->appendChild(m_rootElement); } diff --git a/limereport/serializators/lrxmlwriter.h b/limereport/serializators/lrxmlwriter.h index dc0deaa..399e2e2 100644 --- a/limereport/serializators/lrxmlwriter.h +++ b/limereport/serializators/lrxmlwriter.h @@ -48,7 +48,7 @@ private: bool saveToFile(QString fileName); QString saveToString(); QByteArray saveToByteArray(); - + void init(); QDomElement putQObjectItem(QString name, QObject* item); void putChildQObjectItem(QString name, QObject* item, QDomElement* parentNode); void putCollectionItem(QObject* item, QDomElement* parentNode=0); diff --git a/translations/limereport_es_ES.qm b/translations/limereport_es_ES.qm index b0946c3..3fd67a6 100644 Binary files a/translations/limereport_es_ES.qm and b/translations/limereport_es_ES.qm differ diff --git a/translations/limereport_es_ES.ts b/translations/limereport_es_ES.ts index 8c8efbc..8784b9b 100644 --- a/translations/limereport_es_ES.ts +++ b/translations/limereport_es_ES.ts @@ -1,6 +1,6 @@ - + LRVariableDialog @@ -28,15 +28,15 @@ LimeReport::AVariablesHolder variable with name - variable con el nombre + variable con el nombre already exists !! - ya existe !! + ya existe !! does not exists !! - no existe !! + no existe !! @@ -86,7 +86,7 @@ p, li { white-space: pre-wrap; } <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">arin_a@bk.ru</p></body></html> - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } @@ -395,7 +395,7 @@ p, li { white-space: pre-wrap; } User variables - Variables de usuario + Variables de usuario System variables @@ -413,6 +413,18 @@ p, li { white-space: pre-wrap; } Error + + Grab variable + + + + Report variables + + + + External variables + + LimeReport::DataFooterBand @@ -758,6 +770,14 @@ p, li { white-space: pre-wrap; } One to one + + Font + + + + Text align + + LimeReport::ProxyHolder @@ -993,6 +1013,22 @@ p, li { white-space: pre-wrap; } Report file name + + Page + + + + Script + + + + Error + + + + Wrong file format + + LimeReport::ReportDesignWindow @@ -1220,6 +1256,18 @@ p, li { white-space: pre-wrap; } File "%1" not found! + + New Report Page + + + + Delete Report Page + + + + Script Browser + + LimeReport::ReportEnginePrivate @@ -1227,6 +1275,10 @@ p, li { white-space: pre-wrap; } Error + + Preview + + LimeReport::ReportFooter @@ -1356,6 +1408,60 @@ p, li { white-space: pre-wrap; } + + LimeReport::ScriptBrowser + + Form + + + + Functions + + + + ... + + + + Dialogs + + + + Type + Tipo + + + Name + Nombre + + + NO CATEGORY + + + + Error + + + + Dialog with name: %1 already exists + + + + ui file must cointain QDialog instead QWidget or QMainWindow + + + + wrong file format + + + + + LimeReport::ScriptEngineContext + + Dialog with name: %1 can`t be created + + + LimeReport::ScriptEngineManager @@ -1382,6 +1488,10 @@ p, li { white-space: pre-wrap; } Locale + + CurrencySymbol + + LimeReport::SettingDialog @@ -1494,6 +1604,21 @@ p, li { white-space: pre-wrap; } + + LimeReport::VariablesHolder + + variable with name + variable con el nombre + + + already exists !! + ya existe !! + + + does not exists !! + no existe !! + + QObject @@ -1688,5 +1813,9 @@ p, li { white-space: pre-wrap; } Content is empty + + Wrong file format + + diff --git a/translations/limereport_ru.qm b/translations/limereport_ru.qm index c1d4046..62addf1 100644 Binary files a/translations/limereport_ru.qm and b/translations/limereport_ru.qm differ diff --git a/translations/limereport_ru.ts b/translations/limereport_ru.ts index 74f1a09..29eb2f1 100644 --- a/translations/limereport_ru.ts +++ b/translations/limereport_ru.ts @@ -1,137 +1,137 @@ - + AboutDialog About - О программе + О программе Author - Автор + Автор License - Лицензия + Лицензия Close - Закрыть + Закрыть Version 1.1.1 - Версия + Версия ConnectionDialog Connection - Соединение + Соединение Connection Name - Название + Название Driver - Драйвер + Драйвер Server - Сервер + Сервер User - Пользователь + Пользователь Password - Пароль + Пароль Database - База данных + База данных Auto connect - Автоматическое соединение + Автоматическое соединение Check connection - Проверить соединение + Проверить соединение Cancel - Отмена + Отмена Error - Ошибка + Ошибка Connection succsesfully established! - Соединение успешно установлено! + Соединение успешно установлено! Connection Name is empty - Наименование соединения не указано + Наименование соединения не указано Connection with name - Соединение + Соединение already exists - уже существует + уже существует DataBrowser Datasources - Источники данных + Источники данных Add database connection - Добавить соединение с базой + Добавить соединение с базой Add new datasource - Добавить новый источник данных + Добавить новый источник данных View data - Просмотр данных в источнике + Просмотр данных в источнике Change datasource - Изменить источник данных + Изменить источник данных Delete datasource - Удалить источник данных + Удалить источник данных Show error - Показать ошибки + Показать ошибки Variables - Переменные + Переменные Add new variable - Добавить новую переменную + Добавить новую переменную Edit variable - Редактировать переменную + Редактировать переменную Delete variable - Удалить переменную + Удалить переменную @@ -161,15 +161,15 @@ LimeReport::AVariablesHolder variable with name - переменная + переменная already exists !! - уже существует !! + уже существует !! does not exists !! - не существует !! + не существует !! @@ -223,7 +223,7 @@ p, li { white-space: pre-wrap; } <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">arin_a@bk.ru</p></body></html> - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } @@ -525,7 +525,7 @@ p, li { white-space: pre-wrap; } User variables - Пользовательские переменные + Пользовательские переменные System variables @@ -538,7 +538,7 @@ p, li { white-space: pre-wrap; } Do you really want delete variable "%1" ? - Вы действительно хотите удалить переменную "%1" ? + Вы действительно хотите удалить переменную "%1" ? Error @@ -552,6 +552,18 @@ p, li { white-space: pre-wrap; } Do you really want to delete variable "%1" ? + + Grab variable + + + + Report variables + + + + External variables + + LimeReport::DataFooterBand @@ -779,11 +791,11 @@ p, li { white-space: pre-wrap; } LimeReport::PageDesignIntf Warning - Предупреждение + Предупреждение Multi band deletion not allowed - Удаление нескольких бандов запрещено + Удаление нескольких бандов запрещено @@ -917,6 +929,14 @@ p, li { white-space: pre-wrap; } One to one + + Font + Шрифт + + + Text align + + LimeReport::ProxyHolder @@ -1152,6 +1172,22 @@ p, li { white-space: pre-wrap; } Report file name Файл отчета + + Page + + + + Script + + + + Error + Ошибка + + + Wrong file format + + LimeReport::ReportDesignWindow @@ -1379,6 +1415,18 @@ p, li { white-space: pre-wrap; } File "%1" not found! + + New Report Page + + + + Delete Report Page + + + + Script Browser + + LimeReport::ReportEnginePrivate @@ -1386,6 +1434,10 @@ p, li { white-space: pre-wrap; } Error Ошибка + + Preview + + LimeReport::ReportFooter @@ -1515,6 +1567,60 @@ p, li { white-space: pre-wrap; } + + LimeReport::ScriptBrowser + + Form + + + + Functions + Функции + + + ... + + + + Dialogs + + + + Type + Тип + + + Name + Имя переменной + + + NO CATEGORY + + + + Error + Ошибка + + + Dialog with name: %1 already exists + + + + ui file must cointain QDialog instead QWidget or QMainWindow + + + + wrong file format + + + + + LimeReport::ScriptEngineContext + + Dialog with name: %1 can`t be created + + + LimeReport::ScriptEngineManager @@ -1541,6 +1647,10 @@ p, li { white-space: pre-wrap; } Locale + + CurrencySymbol + + LimeReport::SettingDialog @@ -1653,91 +1763,106 @@ p, li { white-space: pre-wrap; } + + LimeReport::VariablesHolder + + variable with name + переменная + + + already exists !! + уже существует !! + + + does not exists !! + не существует !! + + PreviewReportWindow Preview - Предварительный просмотр + Предварительный просмотр View - Просмотр + Просмотр Report - Отчет + Отчет toolBar - Панель инструментов + Панель инструментов Print - Печать + Печать Zoom In - Увеличить + Увеличить Zoom Out - Уменьшить + Уменьшить Prior Page - Предыдущая страница + Предыдущая страница Next Page - Следующая страница + Следующая страница Close Preview - Закрыть + Закрыть Edit Mode - Режим редактирования + Режим редактирования Save to file - Записать в файл + Записать в файл Show errors - Показать ошибки + Показать ошибки First Page - Первая страница + Первая страница First page - Первая страница + Первая страница Last Page - Последняя страница + Последняя страница Print To PDF - Печать в PDF + Печать в PDF Page: - Страница: + Страница: of %1 - из %1 + из %1 Report file name - Файл отчета + Файл отчета PDF file name - Имя PDF файла + Имя PDF файла @@ -1824,7 +1949,7 @@ p, li { white-space: pre-wrap; } Master datasource "%1" not found! - Главный источник данных "%1" не найден! + Главный источник данных "%1" не найден! Child @@ -1884,19 +2009,19 @@ p, li { white-space: pre-wrap; } TopLine - Верхняя граница + Верхняя граница BottomLine - Нижняя граница + Нижняя граница LeftLine - Левая граница + Левая граница RightLine - Правая граница + Правая граница content @@ -1954,161 +2079,165 @@ p, li { white-space: pre-wrap; } Content is empty + + Wrong file format + + SQLEditDialog Datasource - Источник данных + Источник данных Connection - Соединение + Соединение Datasource Name - Имя источника + Имя источника Subdetail - Подчиненный + Подчиненный Master datasource - Главный источник + Главный источник Subquery mode - Режим подзапроса + Режим подзапроса Filter mode - Режим фильтрации + Режим фильтрации SQL - SQL запрос + SQL запрос Preview - Предпросмотр + Предпросмотр Hide Preview - Скрыть + Скрыть Child datasource - Подчиненный источник + Подчиненный источник Fields map - Поля для связи источников + Поля для связи источников Data preview - Данные + Данные Cancel - Отмена + Отмена Error - Ошибка + Ошибка Datasource Name is empty ! - Имя источника данных не заполнено ! + Имя источника данных не заполнено ! SQL is empty ! - SQL запрос пустой ! + SQL запрос пустой ! Datasource with name: "%1" already exists ! - Источник данных с именем: "%1" уже существует ! + Источник данных с именем: "%1" уже существует ! Datasource with name %1 already exist - Источник данных с именем: "%1" уже существует + Источник данных с именем: "%1" уже существует Attention - Внимание + Внимание Connection is not specified - Соединение не указано + Соединение не указано Refresh - Обновить + Обновить SettingDialog Designer setting - Настройки дизайнера + Настройки дизайнера Default font - Шрифт по умолчанию + Шрифт по умолчанию Grid - Сетка + Сетка Vertical grid step - Вертикальный шаг + Вертикальный шаг Horizontal grid step - Горизонтальный шаг + Горизонтальный шаг TextItemEditor Text Item Editor - Редактор текстового элемента + Редактор текстового элемента Content - Содержимое + Содержимое Data - Источники данных + Источники данных Functions - Функции + Функции Editor settings - Настройки + Настройки Editor font - Шрифт редактора + Шрифт редактора Cancel - Отмена + Отмена WaitForm Wait - Ожидайте + Ожидайте Please wait ... - Пожалуста подождите ... + Пожалуста подождите ...