File indexing completed on 2025-02-16 04:22:35
0001 /* This file is part of the KDE project 0002 Copyright (C) 2015 by Adam Pigg <adam@piggz.co.uk> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "DesignerWidget.h" 0021 #include "KReportExampleDataSource.h" 0022 0023 #include <KReportDesigner> 0024 #include <KReportDesignerSectionDetail> 0025 #include <KReportDesignerSection> 0026 0027 #include <QAction> 0028 #include <QActionGroup> 0029 #include <QDockWidget> 0030 #include <QDomElement> 0031 #include <QMainWindow> 0032 #include <QScrollArea> 0033 #include <QToolBar> 0034 0035 ReportDesignerWidget::ReportDesignerWidget(QWidget *parent) 0036 : QScrollArea(parent) 0037 { 0038 m_reportDesigner = new KReportDesigner(this); 0039 setWidget(m_reportDesigner); 0040 0041 connect(m_reportDesigner, SIGNAL(itemInserted(QString)), 0042 this, SLOT(slotItemInserted(QString))); 0043 connect(m_reportDesigner, SIGNAL(propertySetChanged()), 0044 this, SLOT(slotDesignerPropertySetChanged())); 0045 connect(m_reportDesigner, SIGNAL(dirty()), this, SLOT(designDirty())); 0046 0047 auto dataSource = new KReportExampleDataSource; 0048 m_reportDesigner->setDataSource(dataSource); 0049 m_reportDesigner->setScriptSource(dataSource); 0050 } 0051 0052 ReportDesignerWidget::~ReportDesignerWidget() 0053 { 0054 } 0055 0056 QToolBar* ReportDesignerWidget::createMainToolBar(QMainWindow *mainWindow) 0057 { 0058 Q_ASSERT(mainWindow); 0059 if (!m_mainToolBar) { 0060 m_mainToolBar = mainWindow->addToolBar(tr("Main")); 0061 m_mainToolBar->setObjectName("MainToolBar"); // needed by QMainWindow::saveState() 0062 QList<QAction*> designerActions = m_reportDesigner->designerActions(); 0063 foreach(QAction* action, designerActions) { 0064 m_mainToolBar->addAction(action); 0065 } 0066 } 0067 return m_mainToolBar; 0068 } 0069 0070 QToolBar* ReportDesignerWidget::createItemsToolBar(QMainWindow *mainWindow) 0071 { 0072 if (!m_itemToolBar) { 0073 m_itemToolBar = new QToolBar(tr("Items")); 0074 mainWindow->addToolBar(Qt::LeftToolBarArea, m_itemToolBar); // good position for a toolbox 0075 m_itemToolBar->setObjectName("ItemsToolBar"); // needed by QMainWindow::saveState() 0076 QActionGroup *group = new QActionGroup(this); 0077 QList<QAction*> itemActions = KReportDesigner::itemActions(group); 0078 foreach(QAction* action, itemActions) { 0079 m_itemToolBar->addAction(action); 0080 } 0081 m_reportDesigner->plugItemActions(itemActions); 0082 } 0083 return m_itemToolBar; 0084 } 0085 0086 QDockWidget* ReportDesignerWidget::createPropertyEditorDockWidget(QMainWindow *mainWindow, 0087 Qt::DockWidgetArea area) 0088 { 0089 if (!m_propertyDock) { 0090 m_propertyDock = new QDockWidget(tr("Property Editor"), mainWindow); 0091 m_propertyDock->setObjectName("PropertyEditorDockWidget"); // needed by QMainWindow::saveState() 0092 m_propertyEditor = new KPropertyEditorView; 0093 m_propertyEditor->changeSet(m_reportDesigner->propertySet()); 0094 m_propertyDock->setWidget(m_propertyEditor); 0095 mainWindow->addDockWidget(area, m_propertyDock); 0096 m_propertyEditor->resize(200, m_propertyEditor->height()); 0097 slotDesignerPropertySetChanged(); 0098 } 0099 emit designDirty(); 0100 return m_propertyDock; 0101 } 0102 0103 void ReportDesignerWidget::slotItemInserted(const QString &itemId) 0104 { 0105 QList<QAction*> itemActions = m_itemToolBar->actions(); 0106 foreach(QAction* action, itemActions) { 0107 if (action->objectName() == itemId) { 0108 action->setChecked(false); 0109 } 0110 } 0111 } 0112 0113 void ReportDesignerWidget::slotDesignerPropertySetChanged() 0114 { 0115 if (m_propertyEditor) { 0116 m_propertyEditor->changeSet(m_reportDesigner->selectedItemPropertySet()); 0117 } 0118 } 0119 0120 void ReportDesignerWidget::designDirty() 0121 { 0122 emit designChanged(m_reportDesigner->document()); 0123 } 0124 0125 QDomElement ReportDesignerWidget::document() const 0126 { 0127 return m_reportDesigner->document(); 0128 }