diff --git a/examples/DesignerWidget.cpp b/examples/DesignerWidget.cpp index e295b467..3a9bfe08 100644 --- a/examples/DesignerWidget.cpp +++ b/examples/DesignerWidget.cpp @@ -1,123 +1,126 @@ /* 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 "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")); + m_mainToolBar->setObjectName("MainToolBar"); // needed by QMainWindow::saveState() 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 = new QToolBar(tr("Items")); mainWindow->addToolBar(Qt::LeftToolBarArea, m_itemToolBar); // good position for a toolbox + m_itemToolBar->setObjectName("ItemsToolBar"); // needed by QMainWindow::saveState() 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_propertyDock->setObjectName("PropertyEditorDockWidget"); // needed by QMainWindow::saveState() 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/window.cpp b/examples/window.cpp index df9da1af..00c2e39f 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 "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"); + QSettings settings("org.kde", "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"); + QSettings settings("org.kde", "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(); } }