diff --git a/examples/window.cpp b/examples/window.cpp index 5662927e..9045d3d3 100644 --- a/examples/window.cpp +++ b/examples/window.cpp @@ -1,115 +1,130 @@ /* 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 #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()); } 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(); } } diff --git a/examples/window.h b/examples/window.h index a151c173..ca95b0f6 100644 --- a/examples/window.h +++ b/examples/window.h @@ -1,60 +1,63 @@ /* 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. */ #ifndef KREPORTEXAMPLE_WINDOW_H #define KREPORTEXAMPLE_WINDOW_H #include "KReportExampleData.h" #include #include #include #include #include #include class ReportDesignerWidget; /*! @short KReportExample application's main window */ class Window : public QMainWindow { Q_OBJECT public: Window(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); virtual ~Window(); public Q_SLOTS: void showDesign(const QDomElement &design); +protected: + void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; + private: void createMenus(); bool loadDocument(); ReportDesignerWidget *m_designerWidget; QMenu *m_fileMenu; QAction *m_exitAction; KReportView *m_reportView; QDomDocument m_document; int m_currentPage; }; #endif