labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

AbstractPart.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  File : AbstractPart.cpp
3  Project : LabPlot
4  Description : Base class of Aspects with MDI windows as views.
5  --------------------------------------------------------------------
6  Copyright : (C) 2008 Knut Franke (knut.franke@gmx.de)
7  Copyright : (C) 2012 Alexander Semke (alexander.semke@web.de)
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 
31 #include "backend/core/Workbook.h"
35 #include "backend/matrix/Matrix.h"
38 #ifdef HAVE_MQTT
40 #endif
41 
42 #include <QMenu>
43 #include <QStyle>
44 
45 #include <KLocalizedString>
46 
47 /**
48  * \class AbstractPart
49  * \brief Base class of Aspects with MDI windows as views (AspectParts).
50  */
52  : AbstractAspect(name, type) {
53 }
54 
56  if (m_mdiWindow)
57  delete m_mdiWindow;
58 }
59 
60 /**
61  * \fn QWidget *AbstractPart::view() const
62  * \brief Construct a primary view on me.
63  *
64  * The caller receives ownership of the view.
65  *
66  * This method may be called multiple times during the life time of a Part, or it might not get
67  * called at all. Parts must not depend on the existence of a view for their operation.
68  */
69 
70 /**
71  * \brief Wrap the view() into a PartMdiView.
72  *
73  * A new view is only created the first time this method is called;
74  * after that, a pointer to the pre-existing view is returned.
75  */
77  if (!m_mdiWindow)
78  m_mdiWindow = new PartMdiView(const_cast<AbstractPart*>(this));
79 
80  return m_mdiWindow;
81 }
82 
84  return m_mdiWindow;
85 }
86 
87 /*!
88  * this function is called when PartMdiView, the mdi-subwindow-wrapper of the actual view,
89  * is closed (=deleted) in MainWindow. Makes sure that the view also gets deleted.
90  */
92  //if the parent is a Workbook or Datapicker, the actual view was already deleted when QTabWidget was deleted.
93  //here just set the pointer to 0.
94  if (dynamic_cast<const Workbook*>(parentAspect()) || dynamic_cast<const Datapicker*>(parentAspect())
95  || dynamic_cast<const Datapicker*>(parentAspect()->parentAspect())) {
96  m_partView = nullptr;
97  return;
98  }
99 
100  if (m_partView) {
101  delete m_partView;
102  m_partView = nullptr;
103  m_mdiWindow = nullptr;
104  }
105 }
106 
107 /**
108  * \brief Return AbstractAspect::createContextMenu() plus operations on the primary view.
109  */
111  QMenu* menu = AbstractAspect::createContextMenu();
112  Q_ASSERT(menu);
113  menu->addSeparator();
114 
115  if (m_mdiWindow) {
116  if ( (dynamic_cast<Spreadsheet*>(this) || dynamic_cast<Matrix*>(this))
117  && !dynamic_cast<const LiveDataSource*>(this)
118 #ifdef HAVE_MQTT
119  && !dynamic_cast<const MQTTTopic*>(this)
120 #endif
121  ) {
122  QMenu* subMenu = new QMenu(i18n("Import Data"), menu);
123  subMenu->addAction(QIcon::fromTheme("document-import"), i18n("From File"), this, SIGNAL(importFromFileRequested()));
124  subMenu->addAction(QIcon::fromTheme("document-import"), i18n("From SQL Database"), this, SIGNAL(importFromSQLDatabaseRequested()));
125  menu->addMenu(subMenu);
126  menu->addSeparator();
127  }
128 
129  menu->addAction(QIcon::fromTheme("document-export-database"), i18n("Export"), this, SIGNAL(exportRequested()));
130  menu->addAction(QIcon::fromTheme("document-print"), i18n("Print"), this, SIGNAL(printRequested()));
131  menu->addAction(QIcon::fromTheme("document-print-preview"), i18n("Print Preview"), this, SIGNAL(printPreviewRequested()));
132  menu->addSeparator();
133 
134  const QStyle *widget_style = m_mdiWindow->style();
135  if (m_mdiWindow->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized)) {
136  QAction* action = menu->addAction(i18n("&Restore"), m_mdiWindow, SLOT(showNormal()));
137  action->setIcon(widget_style->standardIcon(QStyle::SP_TitleBarNormalButton));
138  }
139 
140  if (!(m_mdiWindow->windowState() & Qt::WindowMinimized)) {
141  QAction* action = menu->addAction(i18n("Mi&nimize"), m_mdiWindow, SLOT(showMinimized()));
142  action->setIcon(widget_style->standardIcon(QStyle::SP_TitleBarMinButton));
143  }
144 
145  if (!(m_mdiWindow->windowState() & Qt::WindowMaximized)) {
146  QAction* action = menu->addAction(i18n("Ma&ximize"), m_mdiWindow, SLOT(showMaximized()));
147  action->setIcon(widget_style->standardIcon(QStyle::SP_TitleBarMaxButton));
148  }
149  } else {
150  //data spreadsheets in the datapicker curves cannot be hidden/minimized, don't show this menu entry
151  if ( !(dynamic_cast<const Spreadsheet*>(this) && dynamic_cast<const DatapickerCurve*>(this->parentAspect())) )
152  menu->addAction(i18n("Show"), this, SIGNAL(showRequested()));
153  }
154 
155  return menu;
156 }
157 
159  //TODO: moving workbook children doesn't work at the moment, don't allow to move it for now
162  return false;
163  else
164  return true;
165 }
166 
169 }
AspectType
Base class of all persistent objects in a Project.
AspectType type() const
virtual QMenu * createContextMenu()
Return a new context menu.
AbstractAspect * parentAspect() const
Return my parent Aspect or 0 if I currently don't have one.
Base class of Aspects with MDI windows as views (AspectParts).
Definition: AbstractPart.h:36
void printPreviewRequested()
QMenu * createContextMenu() override
Return AbstractAspect::createContextMenu() plus operations on the primary view.
AbstractPart(const QString &name, AspectType type)
bool hasMdiSubWindow() const
QVector< AspectType > dropableOn() const override
void deleteView() const
PartMdiView * m_mdiWindow
Definition: AbstractPart.h:62
PartMdiView * mdiSubWindow() const
Wrap the view() into a PartMdiView.
void printRequested()
void importFromFileRequested()
void importFromSQLDatabaseRequested()
QWidget * m_partView
Definition: AbstractPart.h:65
~AbstractPart() override
void exportRequested()
void showRequested()
bool isDraggable() const override
Top-level container for Curve-Point and Datasheet/Spreadsheet of datapicker.
Top-level container for DatapickerCurve and DatapickerImage.
Definition: Datapicker.h:45
Represents data stored in a file. Reading and writing is done with the help of appropriate I/O-filter...
Represents a topic of a subscription made in MQTTClient.
Definition: MQTTTopic.h:39
Definition: Matrix.h:41
QMdiSubWindow wrapper for aspect views.
Definition: PartMdiView.h:38
Aspect providing a spreadsheet table with column logic.
Definition: Spreadsheet.h:40
Top-level container for Spreadsheet and Matrix.
Definition: Workbook.h:40
#define i18n(m)
Definition: nsl_common.h:38