KReport

KReportDesigner.h
1 /* This file is part of the KDE project
2  * Copyright (C) 2001-2007 by OpenMFG, LLC <[email protected]>
3  * Copyright (C) 2007-2008 by Adam Pigg <[email protected]>
4  * Copyright (C) 2011-2017 JarosÅ‚aw Staniek <[email protected]>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef KREPORTDESIGNER_H
20 #define KREPORTDESIGNER_H
21 
22 #include <QWidget>
23 
24 #include "KReportDocument.h"
25 #include "KReportDataSource.h"
26 
27 class KProperty;
28 class KPropertySet;
29 
30 class KReportItemBase;
31 
32 class QGraphicsScene;
33 class QActionGroup;
35 class QString;
36 
39 class KReportUnit;
40 class KReportDesignerSectionScene;
41 class KReportDesignerSectionView;
42 class QAction;
43 
44 #ifdef KREPORT_SCRIPTING
46 #endif
47 
48 
49 /*!
50  * @brief The ReportDesigner is the main widget for designing a report
51  */
52 class KREPORT_EXPORT KReportDesigner : public QWidget
53 {
54  Q_OBJECT
55 public:
56  /**
57  @brief Constructor that create a blank designer
58  @param parent QWidget parent
59  */
60  explicit KReportDesigner(QWidget *parent = nullptr);
61 
62  /**
63  @brief Constructor that create a designer, and loads the report described in the QDomElement
64  @param parent QWidget parent
65  @param desc Report structure XML element
66  */
67  KReportDesigner(QWidget *parent, const QDomElement &desc);
68 
69  /**
70  @brief Desctructor
71  */
72  ~KReportDesigner() override;
73 
74  /**
75  @brief Sets the report data
76  The report data interface contains functions to retrieve data
77  and information about the fields.
78  @param source Pointer to KReportDataSource instance, ownership is transferred
79  */
80  void setDataSource(KReportDataSource* source);
81 
82 #ifdef KREPORT_SCRIPTING
83  /**
84  @brief Sets the script source for the designer
85  The script source contains function to return scripts supplied by the parent application
86  @param source Pointer to KReportScriptSource instance, ownership is NOT transferred as it may be an application window
87  */
88  void setScriptSource(KReportScriptSource *source);
89 #endif
90 
91  /**
92  @brief Return a pointer to the reports data
93  @return Pointer to report data
94  */
95  KReportDataSource *reportDataSource() const;
96 
97  /**
98  @brief Return a pointer to the section specified
99  @param type KReportSectionData::Section enum value of the section to return
100  @return Pointer to report section object, or 0 if no section exists
101  */
102  KReportDesignerSection* section(KReportSectionData::Type type) const;
103 
104  /**
105  @brief Creates new section
106  @return Pointer to a new report section section object, ownership is transferred to
107  the caller
108  */
109  Q_REQUIRED_RESULT KReportDesignerSection* createSection();
110 
111  /**
112  @brief Deletes the section specified
113  @param type KReportSectionData::Section enum value of the section to return
114  */
115  void removeSection(KReportSectionData::Type type);
116 
117  /**
118  @brief Create a new section and insert it into the report
119  @param type KReportSectionData::Section enum value of the section to return
120  */
121  void insertSection(KReportSectionData::Type type);
122 
123  /**
124  @brief Return a pointer to the detail section.
125  The detail section contains the actual detail section and related group sections
126  @return Pointer to detail section
127  */
128  KReportDesignerSectionDetail* detailSection() const;
129 
130  /**
131  @brief Sets the title of the reportData
132  @param title Report Title
133  */
134  void setReportTitle(const QString &title);
135 
136  /**
137  @brief Sets the parameters for the display of the background gridpoints
138  @param visible Grid visibility
139  @param divisions Number of minor divisions between major points
140  */
141  void setGridOptions(bool visible, int divisions);
142 
143  /**
144  @brief Return the title of the report
145  */
146  QString reportTitle() const;
147 
148  /**
149  @brief Return an XML description of the report
150  @return QDomElement describing the report definition
151  */
152  QDomElement document() const;
153 
154  /**
155  @brief Return true if the design has been modified
156  @return modified status
157  */
158  bool isModified() const;
159 
160  /**
161  @return a list of field names in the selected KReportData
162  */
163  QStringList fieldNames() const;
164 
165  /**
166  @return a list of field keys in the selected KReportData
167  The keys can be used to reference the names
168  */
169  QStringList fieldKeys() const;
170 
171  /**
172  @brief Calculate the width of the page in pixels given the paper size, orientation, dpi and margin
173  @return integer value of width in pixels
174  */
175  int pageWidthPx() const;
176 
177  /**
178  @return the scene (section) that is currently active
179  */
180  QGraphicsScene* activeScene() const;
181 
182  /**
183  @brief Sets the active Scene
184  @param scene The scene to make active
185  */
186  void setActiveScene(QGraphicsScene* scene);
187 
188  /**
189  @return the property set for the general report properties
190  */
191  KPropertySet* propertySet() const;
192 
193  /**
194  @brief Give a hint on the size of the widget
195  */
196  QSize sizeHint() const override;
197 
198  /**
199  @brief Return the current unit assigned to the report
200  */
201  KReportUnit pageUnit() const;
202 
203  /**
204  @brief Handle the context menu event for a report section
205  @param scene The associated scene (section)
206  */
207  void sectionContextMenuEvent(KReportDesignerSectionScene *scene, QGraphicsSceneContextMenuEvent * event);
208 
209  /**
210  @brief Handle the mouse release event for a report section
211  */
212  void sectionMouseReleaseEvent(KReportDesignerSectionView *v, QMouseEvent * e);
213 
214  void sectionMousePressEvent(KReportDesignerSectionView *v, QMouseEvent * e);
215 
216  /**
217  @brief Sets the property set for the currently selected item
218  @param set Property set of item
219  */
220  void changeSet(KPropertySet *set);
221 
222  /**
223  @brief Return the property set for the curently selected item
224  */
225  KPropertySet* selectedItemPropertySet() const;
226 
227  /**
228  @brief Sets the modified status, defaulting to true for modified
229  @param modified Modified status
230  */
231  void setModified(bool modified);
232 
233  /**
234  @brief Return a unique name that can be used by the entity
235  @param name Name of entity
236  */
237  QString suggestEntityName(const QString &name) const;
238 
239  /**
240  @brief Checks if the supplied name is unique among all entities
241  */
242  bool isEntityNameUnique(const QString &name, KReportItemBase *ignore = nullptr) const;
243 
244  /**
245  @brief Returns a list of actions that represent the entities that can be inserted into the report.
246  Actions are created as children of @a group and belong to the group.
247  @return list of actions */
248  static QList<QAction*> itemActions(QActionGroup* group = nullptr);
249 
250  /**
251  @brief Populates the toolbar with actions that can be applied to the report
252  Actions are created as children of @a group and belong to the group.
253  @return list of actions */
254  QList<QAction*> designerActions();
255 
256  /**
257  @return X position of mouse when mouse press occurs
258  */
259  qreal getSelectionPressX() const;
260 
261  /**
262  @return Y position of mouse when mouse press occurs
263  */
264  qreal getSelectionPressY() const;
265 
266  /**
267  @return difference between X position of mouse release and press
268  */
269  qreal countSelectionWidth() const;
270 
271  /**
272  @return difference between Y position of mouse release and press
273  */
274  qreal countSelectionHeight() const;
275 
276  /**
277  @return point that contains X,Y coordinates of mouse press
278  */
279  QPointF getPressPoint() const;
280 
281  /**
282  @return point that contains X,Y coordinates of mouse press
283  */
284  QPointF getReleasePoint() const;
285 
286  void plugItemActions(const QList<QAction*> &actList);
287 
288  /**
289  * @brief Adds meta-properties to the property set @a set for consumption by property editor
290  * - "this:classString" - user-visible translated name of element type, e.g. tr("Label")
291  * - "this:iconName" - name of user-visible icon, e.g. "kreport-label-element"
292  *
293  * All the properties are set to invisible.
294  * @see propertySet()
295  */
296  static void addMetaProperties(KPropertySet* set, const QString &classString,
297  const QString &iconName);
298 
299 public Q_SLOTS:
300 
301  void slotEditDelete();
302  void slotEditCut();
303  void slotEditCopy();
304  void slotEditPaste();
305  void slotEditPaste(QGraphicsScene *);
306 
307  void slotItem(const QString&);
308 
309  void slotSectionEditor();
310 
311  void slotRaiseSelected();
312  void slotLowerSelected();
313 
314 private:
315  /**
316  @brief Sets the detail section to the given section
317  */
318  void setDetail(KReportDesignerSectionDetail *rsd);
319 
320  void resizeEvent(QResizeEvent * event) override;
321 
322  //Properties
323  void createProperties();
324 
325  unsigned int selectionCount() const;
326 
327  void setSectionCursor(const QCursor&);
328  void unsetSectionCursor();
329 
330  void createActions();
331 
332  QSize pageSizePt() const;
333 
334  void recalculateMaxMargins();
335 
336 private Q_SLOTS:
337  void slotPropertyChanged(KPropertySet &s, KProperty &p);
338 
339  /**
340  @brief When the 'page' button in the top left is pressed, change the property set to the reports properties.
341  */
342  void slotPageButton_Pressed();
343 
344  void slotItemTriggered(bool checked);
345 
346 Q_SIGNALS:
347  void pagePropertyChanged(KPropertySet &s);
348  void propertySetChanged();
349  void dirty();
350  void reportDataChanged();
351  void itemInserted(const QString& entity);
352 
353 private:
355  class Private;
356  Private * const d;
357 };
358 
359 #endif
Base class for items that are drawn syncronously.
This class is the base to all Report Section's visual representation.
The central detail section which contains the bulk of the report.
Converts between different units.
Definition: KReportUnit.h:70
Q_SLOTSQ_SLOTS
virtual void resizeEvent(QResizeEvent *event)
Abstraction of report data source.
Q_SIGNALSQ_SIGNALS
Abstraction of report script source.
The ReportDesigner is the main widget for designing a report.
Q_DISABLE_COPY(Class)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Sep 26 2022 03:55:11 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.