File indexing completed on 2024-04-28 04:42:09
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2001-2007 by OpenMFG, LLC <info@openmfg.com> 0003 * Copyright (C) 2007-2008 by Adam Pigg <adam@piggz.co.uk> 0004 * Copyright (C) 2011-2017 Jarosław Staniek <staniek@kde.org> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 #ifndef KREPORTDESIGNER_H 0020 #define KREPORTDESIGNER_H 0021 0022 #include <QWidget> 0023 0024 #include "KReportDocument.h" 0025 #include "KReportDataSource.h" 0026 0027 class KProperty; 0028 class KPropertySet; 0029 0030 class KReportItemBase; 0031 0032 class QGraphicsScene; 0033 class QActionGroup; 0034 class QGraphicsSceneContextMenuEvent; 0035 class QString; 0036 0037 class KReportDesignerSectionDetail; 0038 class KReportDesignerSection; 0039 class KReportUnit; 0040 class KReportDesignerSectionScene; 0041 class KReportDesignerSectionView; 0042 class QAction; 0043 0044 #ifdef KREPORT_SCRIPTING 0045 class KReportScriptSource; 0046 #endif 0047 0048 0049 /*! 0050 * @brief The ReportDesigner is the main widget for designing a report 0051 */ 0052 class KREPORT_EXPORT KReportDesigner : public QWidget 0053 { 0054 Q_OBJECT 0055 public: 0056 /** 0057 @brief Constructor that create a blank designer 0058 @param parent QWidget parent 0059 */ 0060 explicit KReportDesigner(QWidget *parent = nullptr); 0061 0062 /** 0063 @brief Constructor that create a designer, and loads the report described in the QDomElement 0064 @param parent QWidget parent 0065 @param desc Report structure XML element 0066 */ 0067 KReportDesigner(QWidget *parent, const QDomElement &desc); 0068 0069 /** 0070 @brief Desctructor 0071 */ 0072 ~KReportDesigner() override; 0073 0074 /** 0075 @brief Sets the report data 0076 The report data interface contains functions to retrieve data 0077 and information about the fields. 0078 @param source Pointer to KReportDataSource instance, ownership is transferred 0079 */ 0080 void setDataSource(KReportDataSource* source); 0081 0082 #ifdef KREPORT_SCRIPTING 0083 /** 0084 @brief Sets the script source for the designer 0085 The script source contains function to return scripts supplied by the parent application 0086 @param source Pointer to KReportScriptSource instance, ownership is NOT transferred as it may be an application window 0087 */ 0088 void setScriptSource(KReportScriptSource *source); 0089 #endif 0090 0091 /** 0092 @brief Return a pointer to the reports data 0093 @return Pointer to report data 0094 */ 0095 KReportDataSource *reportDataSource() const; 0096 0097 /** 0098 @brief Return a pointer to the section specified 0099 @param type KReportSectionData::Section enum value of the section to return 0100 @return Pointer to report section object, or 0 if no section exists 0101 */ 0102 KReportDesignerSection* section(KReportSectionData::Type type) const; 0103 0104 /** 0105 @brief Creates new section 0106 @return Pointer to a new report section section object, ownership is transferred to 0107 the caller 0108 */ 0109 Q_REQUIRED_RESULT KReportDesignerSection* createSection(); 0110 0111 /** 0112 @brief Deletes the section specified 0113 @param type KReportSectionData::Section enum value of the section to return 0114 */ 0115 void removeSection(KReportSectionData::Type type); 0116 0117 /** 0118 @brief Create a new section and insert it into the report 0119 @param type KReportSectionData::Section enum value of the section to return 0120 */ 0121 void insertSection(KReportSectionData::Type type); 0122 0123 /** 0124 @brief Return a pointer to the detail section. 0125 The detail section contains the actual detail section and related group sections 0126 @return Pointer to detail section 0127 */ 0128 KReportDesignerSectionDetail* detailSection() const; 0129 0130 /** 0131 @brief Sets the title of the reportData 0132 @param title Report Title 0133 */ 0134 void setReportTitle(const QString &title); 0135 0136 /** 0137 @brief Sets the parameters for the display of the background gridpoints 0138 @param visible Grid visibility 0139 @param divisions Number of minor divisions between major points 0140 */ 0141 void setGridOptions(bool visible, int divisions); 0142 0143 /** 0144 @brief Return the title of the report 0145 */ 0146 QString reportTitle() const; 0147 0148 /** 0149 @brief Return an XML description of the report 0150 @return QDomElement describing the report definition 0151 */ 0152 QDomElement document() const; 0153 0154 /** 0155 @brief Return true if the design has been modified 0156 @return modified status 0157 */ 0158 bool isModified() const; 0159 0160 /** 0161 @return a list of field names in the selected KReportData 0162 */ 0163 QStringList fieldNames() const; 0164 0165 /** 0166 @return a list of field keys in the selected KReportData 0167 The keys can be used to reference the names 0168 */ 0169 QStringList fieldKeys() const; 0170 0171 /** 0172 @brief Calculate the width of the page in pixels given the paper size, orientation, dpi and margin 0173 @return integer value of width in pixels 0174 */ 0175 int pageWidthPx() const; 0176 0177 /** 0178 @return the scene (section) that is currently active 0179 */ 0180 QGraphicsScene* activeScene() const; 0181 0182 /** 0183 @brief Sets the active Scene 0184 @param scene The scene to make active 0185 */ 0186 void setActiveScene(QGraphicsScene* scene); 0187 0188 /** 0189 @return the property set for the general report properties 0190 */ 0191 KPropertySet* propertySet() const; 0192 0193 /** 0194 @brief Give a hint on the size of the widget 0195 */ 0196 QSize sizeHint() const override; 0197 0198 /** 0199 @brief Return the current unit assigned to the report 0200 */ 0201 KReportUnit pageUnit() const; 0202 0203 /** 0204 @brief Handle the context menu event for a report section 0205 @param scene The associated scene (section) 0206 */ 0207 void sectionContextMenuEvent(KReportDesignerSectionScene *scene, QGraphicsSceneContextMenuEvent * event); 0208 0209 /** 0210 @brief Handle the mouse release event for a report section 0211 */ 0212 void sectionMouseReleaseEvent(KReportDesignerSectionView *v, QMouseEvent * e); 0213 0214 void sectionMousePressEvent(KReportDesignerSectionView *v, QMouseEvent * e); 0215 0216 /** 0217 @brief Sets the property set for the currently selected item 0218 @param set Property set of item 0219 */ 0220 void changeSet(KPropertySet *set); 0221 0222 /** 0223 @brief Return the property set for the curently selected item 0224 */ 0225 KPropertySet* selectedItemPropertySet() const; 0226 0227 /** 0228 @brief Sets the modified status, defaulting to true for modified 0229 @param modified Modified status 0230 */ 0231 void setModified(bool modified); 0232 0233 /** 0234 @brief Return a unique name that can be used by the entity 0235 @param name Name of entity 0236 */ 0237 QString suggestEntityName(const QString &name) const; 0238 0239 /** 0240 @brief Checks if the supplied name is unique among all entities 0241 */ 0242 bool isEntityNameUnique(const QString &name, KReportItemBase *ignore = nullptr) const; 0243 0244 /** 0245 @brief Returns a list of actions that represent the entities that can be inserted into the report. 0246 Actions are created as children of @a group and belong to the group. 0247 @return list of actions */ 0248 static QList<QAction*> itemActions(QActionGroup* group = nullptr); 0249 0250 /** 0251 @brief Populates the toolbar with actions that can be applied to the report 0252 Actions are created as children of @a group and belong to the group. 0253 @return list of actions */ 0254 QList<QAction*> designerActions(); 0255 0256 /** 0257 @return X position of mouse when mouse press occurs 0258 */ 0259 qreal getSelectionPressX() const; 0260 0261 /** 0262 @return Y position of mouse when mouse press occurs 0263 */ 0264 qreal getSelectionPressY() const; 0265 0266 /** 0267 @return difference between X position of mouse release and press 0268 */ 0269 qreal countSelectionWidth() const; 0270 0271 /** 0272 @return difference between Y position of mouse release and press 0273 */ 0274 qreal countSelectionHeight() const; 0275 0276 /** 0277 @return point that contains X,Y coordinates of mouse press 0278 */ 0279 QPointF getPressPoint() const; 0280 0281 /** 0282 @return point that contains X,Y coordinates of mouse press 0283 */ 0284 QPointF getReleasePoint() const; 0285 0286 void plugItemActions(const QList<QAction*> &actList); 0287 0288 /** 0289 * @brief Adds meta-properties to the property set @a set for consumption by property editor 0290 * - "this:classString" - user-visible translated name of element type, e.g. tr("Label") 0291 * - "this:iconName" - name of user-visible icon, e.g. "kreport-label-element" 0292 * 0293 * All the properties are set to invisible. 0294 * @see propertySet() 0295 */ 0296 static void addMetaProperties(KPropertySet* set, const QString &classString, 0297 const QString &iconName); 0298 0299 public Q_SLOTS: 0300 0301 void slotEditDelete(); 0302 void slotEditCut(); 0303 void slotEditCopy(); 0304 void slotEditPaste(); 0305 void slotEditPaste(QGraphicsScene *); 0306 0307 void slotItem(const QString&); 0308 0309 void slotSectionEditor(); 0310 0311 void slotRaiseSelected(); 0312 void slotLowerSelected(); 0313 0314 private: 0315 /** 0316 @brief Sets the detail section to the given section 0317 */ 0318 void setDetail(KReportDesignerSectionDetail *rsd); 0319 0320 void resizeEvent(QResizeEvent * event) override; 0321 0322 //Properties 0323 void createProperties(); 0324 0325 unsigned int selectionCount() const; 0326 0327 void setSectionCursor(const QCursor&); 0328 void unsetSectionCursor(); 0329 0330 void createActions(); 0331 0332 QSize pageSizePt() const; 0333 0334 void recalculateMaxMargins(); 0335 0336 private Q_SLOTS: 0337 void slotPropertyChanged(KPropertySet &s, KProperty &p); 0338 0339 /** 0340 @brief When the 'page' button in the top left is pressed, change the property set to the reports properties. 0341 */ 0342 void slotPageButton_Pressed(); 0343 0344 void slotItemTriggered(bool checked); 0345 0346 Q_SIGNALS: 0347 void pagePropertyChanged(KPropertySet &s); 0348 void propertySetChanged(); 0349 void dirty(); 0350 void reportDataChanged(); 0351 void itemInserted(const QString& entity); 0352 0353 private: 0354 Q_DISABLE_COPY(KReportDesigner) 0355 class Private; 0356 Private * const d; 0357 }; 0358 0359 #endif