QElectroTech  0.70
qetelementeditor.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef CUSTOM_ELEMENT_EDITOR_H
19 #define CUSTOM_ELEMENT_EDITOR_H
20 #include "qetmainwindow.h"
21 #include "qet.h"
22 #include "elementscene.h"
23 #include "elementslocation.h"
24 
25 
26 class ElementItemEditor;
27 class ElementView;
28 
34  Q_OBJECT
35 
36  // constructor, destructor
37  public:
38  QETElementEditor(QWidget * = nullptr);
39  ~QETElementEditor() override;
40  private:
42  void setupActions();
43  void setupMenus();
44  void setupInterface();
45 
46  // attributes
47  private:
49  bool read_only;
57  QDockWidget *m_tools_dock;
59  QStackedWidget *m_tools_dock_stack;
63  QHash<QString, ElementItemEditor *> m_editors;
65  QDockWidget *m_undo_dock;
67  QDockWidget *m_parts_dock;
69  QListWidget *m_parts_list;
75  QAction *undo, *redo;
82  QString min_title;
84  QString filename_;
89 
90  // methods
91  public:
92  void setNames(const NamesList &);
93  void setLocation(const ElementsLocation &);
94  ElementsLocation location() const;
95  void setFileName(const QString &);
96  QString fileName() const;
97  void setReadOnly(bool);
98  bool isReadOnly() const;
99  void fromFile(const QString &);
100  void fromLocation(const ElementsLocation &);
101  bool toFile(const QString &);
102  bool toLocation(const ElementsLocation &location);
103  bool isEditing(const ElementsLocation &);
104  bool isEditing(const QString &);
105  ElementScene *elementScene() const;
106  void readSettings();
107  void writeSettings();
108  static QPointF pasteOffset();
109  static QString getOpenElementFileName(QWidget * = nullptr, const QString & = QString());
110  void contextMenu(QPoint p, QList<QAction *> actions = QList<QAction*>());
111 
112  signals:
114 
115  protected:
116  void closeEvent(QCloseEvent *) override;
117  void firstActivation(QEvent *) override;
118 
119  private:
120  bool canClose();
121  QWidget *clearToolsDock();
122  void copyAndPasteXml(const QDomDocument &);
123 
124  public slots:
125  void addLine();
126  void addRect();
127  void addEllipse();
128  void addPolygon();
129  void addArc();
130  void addText();
131  void addTerminal();
132  void addDynamicTextField();
133  void UncheckAddPrimitive();
134 
135  void slot_new();
136  void slot_open();
137  void slot_openDxf();
138  void slot_openFile();
139  void openRecentFile(const QString &);
140  void openElement(const QString &);
141  void slot_reload();
142  bool slot_save();
143  bool slot_saveAs();
144  bool slot_saveAsFile();
146  void slot_setNoDragToView();
148  void slot_updateMenus();
149  void slot_updateTitle();
150  void slot_createPartsList();
151  void slot_updatePartsList();
153  bool checkElement();
154  void pasteFromFile();
155  void pasteFromElement();
157 };
158 
162 inline void QETElementEditor::setNames(const NamesList &nameslist) {
163  m_elmt_scene -> setNames(nameslist);
164 }
165 
170  return(location_);
171 }
172 
176 inline QString QETElementEditor::fileName() const {
177  return(filename_);
178 }
179 
184  return(m_elmt_scene);
185 }
186 
187 #endif
~QETElementEditor() override
Destructeur.
QToolBar * depth_toolbar
QHash< QString, ElementItemEditor * > m_editors
Hash associating primitive names with their matching edition widget.
QToolBar * element_toolbar
void saveToLocation(ElementsLocation loc)
QString filename_
filename of the currently edited element
void addArc()
QETElementEditor::addArc Set arc creation interface to scene.
bool toLocation(const ElementsLocation &location)
QETElementEditor::toLocation Save the element to Location.
QMenu * file_menu
menus
QString fileName() const
ElementsLocation location_
location of the currently edited element
void addEllipse()
QETElementEditor::addEllipse Set ellipse creation interface to scene.
ElementView * m_view
view widget for the editing scene
QActionGroup * m_depth_action_group
bool opened_from_file
whether the currently edited element comes from a file or a location
QDockWidget * m_tools_dock
container for widgets dedicated to primitive edition
ElementScene * m_elmt_scene
editing scene
void copyAndPasteXml(const QDomDocument &)
void slot_updateSelectionFromPartsList()
ElementScene * elementScene() const
void UncheckAddPrimitive()
QETElementEditor::UncheckAddPrimitive Uncheck all action related to primitive.
bool read_only
whether the editor is "read-only"
void addLine()
QETElementEditor::addLine Set line creation interface to scene.
QToolBar * view_toolbar
QToolBar * main_toolbar
void addTerminal()
QETElementEditor::addTerminal Set terminal creation interface to scene.
bool slot_saveAsFile()
QETElementEditor::slot_saveAsFile Ask a file to user and save the current edited element to this file...
void slot_openDxf()
QETElementEditor::slot_openDxf.
void setupMenus()
QETElementEditor::setupMenus.
QAction * new_element
actions for the "file" menu
bool checkElement()
QETElementEditor::checkElement Do several check about element. If error is occurred return false...
bool slot_saveAs()
QETElementEditor::slot_saveAs Ask a location to user and save the current edited element to this loca...
void addRect()
QETElementEditor::addRect Set rectangle creation interface to scene.
QETElementEditor(QWidget *=nullptr)
static QPointF pasteOffset()
QActionGroup * parts
Action group.
void fromLocation(const ElementsLocation &)
QETElementEditor::fromLocation Location of the element to edit.
void openElement(const QString &)
bool slot_save()
QETElementEditor::slot_save Save the current editing element. If the filepath or location is unknow...
void setLocation(const ElementsLocation &)
QETElementEditor::setLocation The new location to edit.
QDockWidget * m_parts_dock
Container for the list of existing primitives.
QAction * selectall
actions for the "edit" menu
void openRecentFile(const QString &)
QDockWidget * m_undo_dock
container for the undo list
QAction * paste_from_elmt
void readSettings()
QETElementEditor::readSettings Read settings.
void closeEvent(QCloseEvent *) override
static QString getOpenElementFileName(QWidget *=nullptr, const QString &=QString())
QString min_title
minimum window title
QLabel * m_default_informations
label displayed when several primitives are selected
void fromFile(const QString &)
QActionGroup * m_zoom_ag
QAction * m_edit_properties
void addDynamicTextField()
QETElementEditor::addDynamicTextField Set dynamic text field creation interface to scene...
QListWidget * m_parts_list
List of primitives.
void firstActivation(QEvent *) override
void addText()
QETElementEditor::addText Set text creation interface to scene.
void contextMenu(QPoint p, QList< QAction *> actions=QList< QAction *>())
QETElementEditor::contextMenu Display a context menu, with all available action.
void pasteFromElement()
QETElementEditor::pasteFromElement Ask an element to user, copy the xml definition of the element to ...
void addPolygon()
QETElementEditor::addPolygon Set polygon creation interface to scene.
QAction * edit_size_hs
bool toFile(const QString &)
QETElementEditor::toFile Save to file the drawed element.
void setupActions()
QETElementEditor::setupActions Create action used in Element editor.
bool isReadOnly() const
QAction * save_as_file
QToolBar * parts_toolbar
toolbars
void slot_reload()
QETElementEditor::slot_reload Reload the element from the file or location.
void setNames(const NamesList &)
QAction * paste_in_area
bool isEditing(const ElementsLocation &)
void setFileName(const QString &)
void writeSettings()
QETElementEditor::writeSettings Write the settings.
QAction * paste_from_file
QWidget * clearToolsDock()
ElementsLocation location() const
void setupInterface()
QETElementEditor::setupInterface.
QStackedWidget * m_tools_dock_stack
Stack of widgets for tools_dock.