diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 5288a635..cabf69e3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,19 +1,19 @@ find_package(Qt5Widgets REQUIRED) find_package(KF5WidgetsAddons) find_package(KF5GuiAddons) remove_definitions( -DQT_NO_KEYWORDS -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_NO_CAST_FROM_ASCII ) add_definitions(-DKREPORTEXAMPLE_DATA_DIR="\\"${CMAKE_CURRENT_SOURCE_DIR}\\"") set(kreportexample_SRCS main.cpp window.cpp - designerwindow.cpp + DesignerWidget.cpp KReportExampleData.cpp ) add_executable(kreportexample ${kreportexample_SRCS}) target_link_libraries(kreportexample Qt5::Widgets KReport) diff --git a/examples/designerwindow.cpp b/examples/DesignerWidget.cpp similarity index 99% rename from examples/designerwindow.cpp rename to examples/DesignerWidget.cpp index 90f4637f..634885af 100644 --- a/examples/designerwindow.cpp +++ b/examples/DesignerWidget.cpp @@ -1,122 +1,122 @@ /* This file is part of the KDE project Copyright (C) 2015 by Adam Pigg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "designerwindow.h" +#include "DesignerWidget.h" #include "KReportExampleData.h" #include #include #include #include #include #include #include #include #include #include ReportDesignerWidget::ReportDesignerWidget(QWidget *parent) : QScrollArea(parent) { m_reportDesigner = new KReportDesigner(this); setWidget(m_reportDesigner); connect(m_reportDesigner, SIGNAL(itemInserted(QString)), this, SLOT(slotItemInserted(QString))); connect(m_reportDesigner, SIGNAL(propertySetChanged()), this, SLOT(slotDesignerPropertySetChanged())); connect(m_reportDesigner, SIGNAL(dirty()), this, SLOT(designDirty())); m_reportDesigner->setReportData(new KReportExampleData); } ReportDesignerWidget::~ReportDesignerWidget() { } QToolBar* ReportDesignerWidget::createMainToolBar(QMainWindow *mainWindow) { Q_ASSERT(mainWindow); if (!m_mainToolBar) { m_mainToolBar = mainWindow->addToolBar(tr("Main")); QList designerActions = m_reportDesigner->designerActions(); foreach(QAction* action, designerActions) { m_mainToolBar->addAction(action); } } return m_mainToolBar; } QToolBar* ReportDesignerWidget::createItemsToolBar(QMainWindow *mainWindow) { if (!m_itemToolBar) { m_itemToolBar = mainWindow->addToolBar(tr("Items")); QActionGroup *group = new QActionGroup(this); QList itemActions = KReportDesigner::itemActions(group); foreach(QAction* action, itemActions) { m_itemToolBar->addAction(action); } m_reportDesigner->plugItemActions(itemActions); } return m_itemToolBar; } QDockWidget* ReportDesignerWidget::createPropertyEditorDockWidget(QMainWindow *mainWindow, Qt::DockWidgetArea area) { if (!m_propertyDock) { m_propertyDock = new QDockWidget(tr("Property Editor"), mainWindow); m_propertyEditor = new KPropertyEditorView; m_propertyEditor->changeSet(m_reportDesigner->propertySet()); m_propertyDock->setWidget(m_propertyEditor); mainWindow->addDockWidget(area, m_propertyDock); m_propertyEditor->resize(200, m_propertyEditor->height()); slotDesignerPropertySetChanged(); } emit designDirty(); return m_propertyDock; } void ReportDesignerWidget::slotItemInserted(const QString &itemId) { QList itemActions = m_itemToolBar->actions(); foreach(QAction* action, itemActions) { if (action->objectName() == itemId) { action->setChecked(false); } } } void ReportDesignerWidget::slotDesignerPropertySetChanged() { if (m_propertyEditor) { m_propertyEditor->changeSet(m_reportDesigner->itemPropertySet()); } } void ReportDesignerWidget::designDirty() { emit designChanged(m_reportDesigner->document()); } QDomElement ReportDesignerWidget::document() const { return m_reportDesigner->document(); } diff --git a/examples/designerwindow.h b/examples/DesignerWidget.h similarity index 98% rename from examples/designerwindow.h rename to examples/DesignerWidget.h index b37e52e8..582a2d2a 100644 --- a/examples/designerwindow.h +++ b/examples/DesignerWidget.h @@ -1,81 +1,81 @@ /* This file is part of the KDE project Copyright (C) 2015 by Adam Pigg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KREPORTDESIGNERWIDGET_H #define KREPORTDESIGNERWIDGET_H #include #include #include #include #include #include class KReportDesigner; class QDomElement; class QMainWindow; class QScrollArea; //! KReportExample designer widget class ReportDesignerWidget : public QScrollArea { Q_OBJECT public: ReportDesignerWidget(QWidget *parent = nullptr); ~ReportDesignerWidget(); //! Creates main toolbar for main window @a mainWindow //! @a mainWindow is required. To be called once. QToolBar* createMainToolBar(QMainWindow *mainWindow); //! Creates items toolbar for main window @a mainWindow //! @a mainWindow is required. To be called once. QToolBar* createItemsToolBar(QMainWindow *mainWindow); //! Creates a property editor dock widget for the main window @a mainWindow. //! The widget is added to the area @a area is it is not Qt::NoDockWidgetArea. //! @a mainWindow is required. To be called once. QDockWidget* createPropertyEditorDockWidget(QMainWindow *mainWindow, Qt::DockWidgetArea area = Qt::NoDockWidgetArea); //! @return current document QDomElement document() const; Q_SIGNALS: void designChanged(const QDomElement&); private Q_SLOTS: void slotItemInserted(const QString &itemId); void slotDesignerPropertySetChanged(); void designDirty(); private: KReportDesigner *m_reportDesigner; KPropertySet *m_propertySet; QPointer m_mainToolBar; QPointer m_itemToolBar; QPointer m_propertyDock; QPointer m_propertyEditor; }; -#endif // DESIGNERWINDOW_H +#endif // KREPORTDESIGNERWIDGET_H diff --git a/examples/window.cpp b/examples/window.cpp index 5b736202..df9da1af 100644 --- a/examples/window.cpp +++ b/examples/window.cpp @@ -1,132 +1,132 @@ /* This file is part of the KDE project Copyright (C) 2015 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "window.h" -#include "designerwindow.h" +#include "DesignerWidget.h" #include #include #include #include #include #include #include #include #include #include Window::Window(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { QSplitter *centralWidget = new QSplitter(Qt::Vertical, this); m_designerWidget = new ReportDesignerWidget(centralWidget); m_designerWidget->createMainToolBar(this); m_designerWidget->createItemsToolBar(this); m_designerWidget->createPropertyEditorDockWidget(this, Qt::RightDockWidgetArea); connect(m_designerWidget, &ReportDesignerWidget::designChanged, this, &Window::showDesign); createMenus(); m_reportView = new KReportView(centralWidget); setCentralWidget(centralWidget); centralWidget->setSizes(QList() << height() / 2 << height() / 2); #if 0 if (loadDocument()) { m_preRenderer = new KReportPreRenderer(m_document.documentElement()); if (!m_preRenderer->isValid()) { return; } } #endif KReportPluginManager* manager = KReportPluginManager::self(); //! @todo Q_UNUSED(manager); // restore visual settings QSettings settings("org.kde.kreport", "KReportExample"); restoreGeometry(settings.value("MainWindow/geometry").toByteArray()); restoreState(settings.value("MainWindow/windowState").toByteArray()); showDesign(m_designerWidget->document()); } Window::~Window() { } void Window::closeEvent(QCloseEvent *event) { // store visual settings QSettings settings("org.kde.kreport", "KReportExample"); settings.setValue("MainWindow/geometry", saveGeometry()); settings.setValue("MainWindow/windowState", saveState()); QMainWindow::closeEvent(event); } bool Window::loadDocument() { qDebug() << KREPORTEXAMPLE_DATA_DIR; QFile file(QLatin1String(KREPORTEXAMPLE_DATA_DIR) + "/report.xml"); if (!file.open(QIODevice::ReadOnly)) { return false; } QString errorMsg; int errorLine; int errorColumn; if (!m_document.setContent(&file, &errorMsg, &errorLine, &errorColumn)) { qWarning() << "Error reading XML from" << file.fileName() << "Message:" << errorMsg << "Line:" << errorLine << "Column:" << errorColumn; return false; } return true; } void Window::createMenus() { m_fileMenu = menuBar()->addMenu(tr("&File")); m_exitAction = new QAction(tr("E&xit"), this); m_exitAction->setShortcuts(QKeySequence::Quit); connect(m_exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); m_fileMenu->addAction(m_exitAction); } void Window::showDesign(const QDomElement &design) { qDebug() << "Show design"; KReportPreRenderer preRenderer(design); if (!preRenderer.isValid()) { return; } preRenderer.setSourceData(new KReportExampleData()); preRenderer.setName("example_report"); if (preRenderer.generateDocument()) { m_reportView->setDocument(preRenderer.document()); m_reportView->moveToFirstPage(); } }