QElectroTech  0.70
elementpropertieswidget.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 */
19 #include "element.h"
20 #include "elementinfowidget.h"
21 #include "masterpropertieswidget.h"
23 #include "diagram.h"
24 #include "diagramposition.h"
25 #include "qeticons.h"
27 #include "dynamicelementtextitem.h"
28 #include "elementtextitemgroup.h"
29 
30 #include <QVBoxLayout>
31 #include <QLabel>
32 #include <QUndoStack>
33 
42  m_diagram (elmt->diagram()),
43  m_tab (nullptr),
44  m_general_widget(nullptr)
45 {
46  buildGui();
47  setElement(elmt);
48 }
49 
60  m_tab (nullptr),
61  m_general_widget(nullptr)
62 {
63  if(text->parentElement())
64  {
65  m_diagram = text->parentElement()->diagram();
66  buildGui();
67  setDynamicText(text);
68  }
69 }
70 
81  m_tab (nullptr),
82  m_general_widget(nullptr)
83 {
84  if(group->parentItem() && group->parentItem()->type() == Element::Type)
85  {
86  Element *elmt = static_cast<Element *>(group->parentItem());
87  m_diagram = elmt->diagram();
88  buildGui();
89  setTextsGroup(group);
90  }
91 }
92 
99 {
100  if (m_element == element) return;
101  Element *previous_element = m_element;
102  m_element = element;
103 
104  if (previous_element)
105  {
106  //If previous element is same type as new element we just call setElement for each editor
107  if(previous_element->linkType() == m_element->linkType())
108  {
110  {
111  aepew->setElement(m_element);
113  }
114  return;
115  }
116  }
117  updateUi();
118 }
119 
127 {
128  if(text->parentElement())
129  {
130  setElement(text->parentElement());
132  {
133  if (QString(aepew->metaObject()->className()) == "DynamicElementTextItemEditor")
134  {
135  DynamicElementTextItemEditor *detie = static_cast<DynamicElementTextItemEditor *>(aepew);
136  m_tab->setCurrentWidget(detie);
137  detie->setCurrentText(text);
138  }
139  }
140  }
141 }
142 
150 {
151  if(group->parentItem() && group->parentItem()->type() == Element::Type)
152  {
153  setElement(static_cast<Element *>(group->parentItem()));
155  {
156  if (QString(aepew->metaObject()->className()) == "DynamicElementTextItemEditor")
157  {
158  DynamicElementTextItemEditor *detie = static_cast<DynamicElementTextItemEditor *>(aepew);
159  m_tab->setCurrentWidget(detie);
160  detie->setCurrentGroup(group);
161  }
162  }
163  }
164 }
165 
172 {
173  QList <QUndoCommand *> undo_list;
174 
175  foreach (PropertiesEditorWidget *pew, m_list_editor)
176  if (QUndoCommand *undo = pew->associatedUndo())
177  undo_list << undo;
178 
179  if (undo_list.isEmpty()) return;
180 
181  QString str;
182  foreach(QUndoCommand *uc, undo_list) str += uc->text() += " ";
183 
184  QUndoStack &stack = m_element -> diagram() -> undoStack();
185  stack.beginMacro(str);
186  foreach(QUndoCommand *uc, undo_list) stack.push(uc);
187  stack.endMacro();
188 
190  pew->updateUi();
191 }
192 
198  foreach (PropertiesEditorWidget *pew, m_list_editor) pew->reset();
199 }
200 
202 {
203  if (m_live_edit == live_edit) return true;
204  m_live_edit = live_edit;
205 
207  aepew->setLiveEdit(m_live_edit);
208 
209  return true;
210 }
211 
217 {
218  if (m_element && m_diagram)
219  {
220  m_diagram->findElementRequired(m_element.data()->location());
221  emit findEditClicked();
222  }
223 }
224 
230 {
231  if (m_element && m_diagram)
232  {
233  m_diagram->findElementRequired(m_element.data()->location());
234  m_diagram->editElementRequired(m_element.data()->location());
235  emit findEditClicked();
236  }
237 }
238 
244 {
245  m_tab = new QTabWidget(this);
246  QVBoxLayout *main_layout = new QVBoxLayout(this);
247  main_layout -> addWidget(m_tab);
248  setLayout(main_layout);
249 }
250 
256 {
257  //We keep the current title of the tab, to return to the same tab
258  //if possible, at the end of this method
259  QString tab_text;
260  tab_text = m_tab->tabText(m_tab->currentIndex());
261 
262  //Purge the tab widget and delete all widget
263  m_tab->clear();
264  qDeleteAll(m_list_editor);
265  m_list_editor.clear();
266  if(m_general_widget) {
267  delete m_general_widget;
268  m_general_widget = nullptr;
269  }
270 
271  //Create editor according to the type of element
272  switch (m_element -> linkType()) {
273  case Element::Simple:
275  break;
276  case Element::NextReport:
278  break;
281  break;
282  case Element::Master:
285  break;
286  case Element::Slave:
288  break;
289  case Element::Terminale:
291  break;
292  default:
293  break;
294  }
296 
297  //Add each editors in tab widget
299  {
300  aepew->setLiveEdit(m_live_edit);
301  m_tab->addTab(aepew, aepew->title());
302  }
304 
305  //Go to the tab, edited at the beginning of this method
306  if (!tab_text.isEmpty())
307  {
308  for(int i=0 ; i<m_tab->count() ; ++i)
309  {
310  if (tab_text == m_tab->tabBar()->tabText(i))
311  {
312  m_tab->setCurrentIndex(i);
313  break;
314  }
315  }
316  }
317 }
318 
324 {
325  int index = m_tab->currentIndex();
326  if (m_general_widget)
327  {
328  m_tab->removeTab(m_tab->indexOf(m_general_widget));
329  delete m_general_widget;
330  }
332  m_tab -> addTab(m_general_widget, tr("Général"));
333  m_tab->setCurrentIndex(index);
334 }
335 
341 {
342  QString description_string(tr("Élement\n"));
343 
344  // some element characteristic
345  description_string += QString(tr("Nom : %1\n")).arg(m_element -> name());
346  int folio_index = m_diagram -> folioIndex();
347  if (folio_index != -1) {
348  description_string += QString(tr("Folio : %1\n")).arg(folio_index + 1);
349  }
350  description_string += QString(tr("Position : %1\n")).arg(m_diagram -> convertPosition(m_element -> scenePos()).toString());
351  description_string += QString(tr("Rotation : %1°\n")).arg(m_element.data()->rotation());
352  description_string += QString(tr("Dimensions : %1*%2\n")).arg(m_element -> size().width()).arg(m_element -> size().height());
353  description_string += QString(tr("Bornes : %1\n")).arg(m_element -> terminals().count());
354  description_string += QString(tr("Emplacement : %1\n")).arg(m_element.data()->location().toString());
355 
356  // widget himself
357  QWidget *general_widget = new QWidget (m_tab);
358  QVBoxLayout *vlayout_ = new QVBoxLayout (general_widget);
359  general_widget -> setLayout(vlayout_);
360 
361  //widget for the text
362  QLabel *label = new QLabel (description_string, general_widget);
363  label->setWordWrap(true);
364  vlayout_->addWidget(label);
365 
366  //widget for the pixmap
367  QLabel *pix = new QLabel(general_widget);
368  vlayout_->addWidget(pix, 0, Qt::AlignHCenter);
369  vlayout_ -> addStretch();
370 
371  //button widget
372  QPushButton *find_in_panel = new QPushButton(QET::Icons::ZoomDraw, tr("Retrouver dans le panel"), general_widget);
373  connect(find_in_panel, SIGNAL(clicked()), this, SLOT(findInPanel()));
374  QPushButton *edit_element = new QPushButton(QET::Icons::ElementEdit, tr("Éditer l'élément"), general_widget);
375  connect(edit_element, SIGNAL(clicked()), this, SLOT(editElement()));
376  QHBoxLayout *hlayout_ = new QHBoxLayout;
377  hlayout_->addWidget(find_in_panel);
378  hlayout_->addWidget(edit_element);
379  vlayout_->addLayout(hlayout_);
380 
381  //Set the maximum size of the pixmap to the minimum size of the layout
382  QPixmap pixmap = m_element->pixmap();
383  int margin = vlayout_->contentsMargins().left() + vlayout_->contentsMargins().right();
384  int widht_ = vlayout_->minimumSize().width()-margin;
385 
386  if (pixmap.size().width() > widht_ || pixmap.size().height() > widht_) {
387  pix->setPixmap(m_element->pixmap().scaled (widht_, widht_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
388  }
389  else {
390  pix->setPixmap(pixmap);
391  }
392 
393  return general_widget;
394 }
ElementPropertiesWidget(Element *elmt, QWidget *parent=nullptr)
ElementPropertiesWidget::ElementPropertiesWidget Default constructor.
virtual kind linkType() const
Definition: element.h:138
void setDynamicText(DynamicElementTextItem *text)
ElementPropertiesWidget::setDynamicText convenience function: same as call : ElementPropertiesWidget:...
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
void editElement()
ElementPropertiesWidget::editElement If m_element is a custom element, emit findElementRequired and e...
virtual void setElement(Element *element)=0
QWidget * generalWidget()
ElementPropertiesWidget::generalWidget.
bool setLiveEdit(bool live_edit) override
PropertiesEditorWidget::setLiveEdit Set the editor in live edit mode. When an editor is in live edit ...
The MasterPropertiesWidget class This class is a widget for make link between a master element with s...
Diagram * diagram() const
QetGraphicsItem::diagram return the diagram of this item.
void addGeneralWidget()
ElementPropertiesWidget::addGeneralWidget Add or update the general widget on this tab widget...
void editElementRequired(const ElementsLocation &)
Signal emitted when users wish to locate an element from the diagram within elements collection...
The PropertiesEditorWidget class This class extend QWidget method for have common way to edit propert...
QList< AbstractElementPropertiesEditorWidget * > m_list_editor
void setTextsGroup(ElementTextItemGroup *group)
ElementPropertiesWidget::setTextsGroup Conveniance function : same as call : ElementPropertiesWidget:...
The AbstractElementPropertiesEditorWidget class This class provide common method for all widget used ...
void findInPanel()
ElementPropertiesWidget::findInPanel If m_element is a custom element, emit findElementRequired.
void buildGui()
ElementPropertiesWidget::build Build the content of this widget.
void setCurrentGroup(ElementTextItemGroup *group)
DynamicElementTextItemEditor::setCurrentGroup Expand and select the item for group ...
QIcon tr
Definition: qeticons.cpp:204
virtual bool setLiveEdit(bool live_edit)
PropertiesEditorWidget::setLiveEdit Set the editor in live edit mode. When an editor is in live edit ...
Element * parentElement() const
DynamicElementTextItem::ParentElement.
virtual QUndoCommand * associatedUndo() const
PropertiesEditorWidget::associatedUndo By default, return a nullptr.
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
void updateUi() override
ElementPropertiesWidget::updateUi Update the content of this widget.
The LinkSingleElementWidget class this class provide a widget to select an element to be linked to th...
void setCurrentText(DynamicElementTextItem *text)
DynamicElementTextItemEditor::setCurrentText Expand and select the item for text .
void reset() override
ElementPropertiesWidget::reset Reset the edited properties.
QIcon ElementEdit
Definition: qeticons.cpp:85
void findElementRequired(const ElementsLocation &)
The ElementInfoWidget class this class is a widget to edit an element informations.
QIcon ZoomDraw
Definition: qeticons.cpp:177
void apply() override
ElementPropertiesWidget::apply Apply the new properties by pushing an undo command to the parent proj...
void setElement(Element *element) override
ElementPropertiesWidget::setElement Set to be the edited element.