QElectroTech  0.70
diagrampropertieseditordockwidget.cpp
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 */
20 #include "diagram.h"
21 #include "element.h"
22 #include "diagramimageitem.h"
23 #include "imagepropertieswidget.h"
24 #include "qetshapeitem.h"
26 #include "dynamicelementtextitem.h"
27 #include "elementtextitemgroup.h"
28 #include "independenttextitem.h"
30 
38  m_diagram(nullptr),
39  m_edited_qgi_type (-1)
40 {}
41 
51 {
52  if (m_diagram == diagram) return;
53 
54  if (m_diagram)
55  {
56  disconnect(m_diagram, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
57  disconnect(m_diagram, SIGNAL(destroyed()), this, SLOT(diagramWasDeleted()));
58  }
59 
60  if (diagram)
61  {
62  m_diagram = diagram;
63  connect(m_diagram, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()), Qt::QueuedConnection);
64  connect(m_diagram, SIGNAL(destroyed()), this, SLOT(diagramWasDeleted()));
66  }
67  else
68  {
69  m_diagram = nullptr;
70  m_edited_qgi_type = -1;
71  clear();
72  }
73 }
74 
81 {
82  if (!m_diagram) return;
83 
84  int count_ = m_diagram->selectedItems().size();
85 
86  //The editor widget can only edit one item
87  //or several items of the same type
88  if (count_ != 1)
89  {
90  if (count_ == 0) {
91  clear();
92  m_edited_qgi_type = -1;
93  return;
94  }
95 
96  const QList<QGraphicsItem *> list_ = m_diagram->selectedItems();
97  int type_ = list_.first()->type();
98  for (QGraphicsItem *qgi : list_)
99  {
100  if (qgi->type() != type_)
101  {
102  clear();
103  m_edited_qgi_type = -1;
104  return;
105  }
106  }
107  }
108 
109  QGraphicsItem *item = m_diagram->selectedItems().first();
110  const int type_ = item->type();
111 
112  switch (type_)
113  {
114  case Element::Type: //1000
115  {
116  if (count_ > 1)
117  {
118  clear();
119  m_edited_qgi_type = -1;
120  return;
121  }
122  //We already edit an element, just update the editor with a new element
123  if (m_edited_qgi_type == type_)
124  {
125  static_cast<ElementPropertiesWidget*>(editors().first())->setElement(static_cast<Element*>(item));
126  return;
127  }
128 
129  clear();
130  m_edited_qgi_type = type_;
131  addEditor(new ElementPropertiesWidget(static_cast<Element*>(item), this));
132  break;
133  }
134  case IndependentTextItem::Type: //1005
135  {
136  QList<IndependentTextItem *> text_list;
137  for (QGraphicsItem *qgi : m_diagram->selectedItems()) {
138  text_list.append(static_cast<IndependentTextItem*>(qgi));
139  }
140 
141  if (m_edited_qgi_type == type_)
142  {
143  static_cast<IndiTextPropertiesWidget*>(editors().first())->setText(text_list);
144  return;
145  }
146 
147  clear();
148  m_edited_qgi_type = type_;
149  addEditor(new IndiTextPropertiesWidget(text_list, this));
150  break;
151  }
152  case DiagramImageItem::Type: //1007
153  {
154  if (count_ > 1)
155  {
156  clear();
157  m_edited_qgi_type = -1;
158  return;
159  }
160 
161  clear();
162  m_edited_qgi_type = type_;
163  addEditor(new ImagePropertiesWidget(static_cast<DiagramImageItem*>(item), this));
164  break;
165  }
166  case QetShapeItem::Type: //1008
167  {
168  QList<QetShapeItem *> shapes_list;
169  for (QGraphicsItem *qgi : m_diagram->selectedItems()) {
170  shapes_list.append(static_cast<QetShapeItem*>(qgi));
171  }
172 
173  if (m_edited_qgi_type == type_)
174  {
175  static_cast<ShapeGraphicsItemPropertiesWidget*>(editors().first())->setItems(shapes_list);
176  return;
177  }
178 
179  clear();
180  m_edited_qgi_type = type_;
181  addEditor(new ShapeGraphicsItemPropertiesWidget(shapes_list, this));
182  break;
183  }
184  case DynamicElementTextItem::Type: //1010
185  {
186  if (count_ > 1)
187  {
188  clear();
189  m_edited_qgi_type = -1;
190  return;
191  }
192 
193  DynamicElementTextItem *deti = static_cast<DynamicElementTextItem *>(item);
194 
195  //For dynamic element text, we open the element editor to edit it
196  //If we already edit an element, just update the editor with a new element
198  {
199  static_cast<ElementPropertiesWidget*>(editors().first())->setDynamicText(deti);
200  return;
201  }
202 
203  clear();
205  addEditor(new ElementPropertiesWidget(deti, this));
206  break;
207  }
208  case QGraphicsItemGroup::Type:
209  {
210  if (count_ > 1)
211  {
212  clear();
213  m_edited_qgi_type = -1;
214  return;
215  }
216 
217  if(ElementTextItemGroup *group = dynamic_cast<ElementTextItemGroup *>(item))
218  {
219  //For element text item group, we open the element editor to edit it
220  //If we already edit an element, just update the editor with a new element
222  {
223  static_cast<ElementPropertiesWidget *>(editors().first())->setTextsGroup(group);
224  return;
225  }
226 
227  clear();
229  addEditor(new ElementPropertiesWidget(group, this));
230  }
231  break;
232  }
233  default:
234  m_edited_qgi_type = -1;
235  clear();
236  }
237 
238  for (PropertiesEditorWidget *pew : editors()) {
239  pew->setLiveEdit(true);
240  }
241 }
242 
248 {
249  m_diagram = nullptr;
250  m_edited_qgi_type = -1;
251  clear();
252 }
void diagramWasDeleted()
DiagramPropertiesEditorDockWidget::diagramWasDeleted Remove current editor and set m_diagram to nullp...
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
The ImagePropertiesWidget class This class provide a widget to edit the propertie of a DiagramImageIt...
void selectionChanged()
DiagramPropertiesEditorDockWidget::selectionChanged The current selection of diagram was changed...
bool addEditor(PropertiesEditorWidget *editor, int index=0)
DiagramPropertiesEditorDockWidget(QWidget *parent=nullptr)
DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget Constructor. ...
The PropertiesEditorWidget class This class extend QWidget method for have common way to edit propert...
The ShapeGraphicsItemPropertiesWidget class Provide a widget to edit the properties of a QetShapeItem...
void setDiagram(Diagram *diagram)
DiagramPropertiesEditorDockWidget::setDiagram Set the diagram to edit the selection. Connect the diagram signal selectionChanged() to this slot selectionChanged(); If diagram = nullptr, we just disconnect all signal and remove editor.
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
QList< PropertiesEditorWidget * > editors() const
PropertiesEditorDockWidget::editors.
The IndiTextPropertiesWidget class This widget is used to edit the properties of one or several indep...
virtual void clear()
PropertiesEditorDockWidget::clear Remove all editor present in this dock and delete it...