2019-02-20 20:36:56 +00:00
|
|
|
|
/*
|
2019-04-03 18:29:13 +00:00
|
|
|
|
Copyright 2006-2019 The QElectroTech Team
|
2015-05-07 22:15:00 +00:00
|
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
#include "diagrampropertieseditordockwidget.h"
|
|
|
|
|
#include "elementpropertieswidget.h"
|
|
|
|
|
#include "diagram.h"
|
|
|
|
|
#include "element.h"
|
2015-05-08 17:49:29 +00:00
|
|
|
|
#include "diagramimageitem.h"
|
|
|
|
|
#include "imagepropertieswidget.h"
|
2015-06-21 20:16:41 +00:00
|
|
|
|
#include "qetshapeitem.h"
|
|
|
|
|
#include "shapegraphicsitempropertieswidget.h"
|
2017-08-03 17:36:08 +00:00
|
|
|
|
#include "dynamicelementtextitem.h"
|
2017-11-27 19:37:39 +00:00
|
|
|
|
#include "elementtextitemgroup.h"
|
2019-02-19 16:42:07 +00:00
|
|
|
|
#include "independenttextitem.h"
|
|
|
|
|
#include "inditextpropertieswidget.h"
|
2015-05-07 22:15:00 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget
|
|
|
|
|
* Constructor
|
|
|
|
|
* @param parent : parent widget
|
|
|
|
|
*/
|
|
|
|
|
DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget(QWidget *parent) :
|
|
|
|
|
PropertiesEditorDockWidget(parent),
|
2015-05-25 10:22:00 +00:00
|
|
|
|
m_diagram(nullptr),
|
2015-06-19 08:12:17 +00:00
|
|
|
|
m_edited_qgi_type (-1)
|
2015-05-07 22:15:00 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 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.
|
|
|
|
|
* @param diagram
|
|
|
|
|
* @param diagram
|
|
|
|
|
*/
|
|
|
|
|
void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
if (m_diagram == diagram) return;
|
|
|
|
|
|
|
|
|
|
if (m_diagram)
|
|
|
|
|
{
|
|
|
|
|
disconnect(m_diagram, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
|
|
|
|
|
disconnect(m_diagram, SIGNAL(destroyed()), this, SLOT(diagramWasDeleted()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (diagram)
|
|
|
|
|
{
|
|
|
|
|
m_diagram = diagram;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
connect(m_diagram, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()), Qt::QueuedConnection);
|
2015-05-07 22:15:00 +00:00
|
|
|
|
connect(m_diagram, SIGNAL(destroyed()), this, SLOT(diagramWasDeleted()));
|
|
|
|
|
selectionChanged();
|
|
|
|
|
}
|
|
|
|
|
else
|
2015-05-25 10:22:00 +00:00
|
|
|
|
{
|
2015-05-07 22:15:00 +00:00
|
|
|
|
m_diagram = nullptr;
|
2016-10-19 16:39:50 +00:00
|
|
|
|
m_edited_qgi_type = -1;
|
2015-05-25 10:22:00 +00:00
|
|
|
|
clear();
|
|
|
|
|
}
|
2015-05-07 22:15:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief DiagramPropertiesEditorDockWidget::selectionChanged
|
|
|
|
|
* The current selection of diagram was changed.
|
|
|
|
|
* We fill the dock with the appropriate ElementPropertiesWidget of the current selection.
|
|
|
|
|
*/
|
|
|
|
|
void DiagramPropertiesEditorDockWidget::selectionChanged()
|
|
|
|
|
{
|
|
|
|
|
if (!m_diagram) return;
|
2019-02-20 20:36:56 +00:00
|
|
|
|
|
|
|
|
|
int count_ = m_diagram->selectedItems().size();
|
|
|
|
|
|
|
|
|
|
//The editor widget can only edit one item
|
|
|
|
|
//or several items of the same type
|
|
|
|
|
if (count_ != 1)
|
2015-05-07 22:15:00 +00:00
|
|
|
|
{
|
2019-02-20 20:36:56 +00:00
|
|
|
|
if (count_ == 0) {
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QList<QGraphicsItem *> list_ = m_diagram->selectedItems();
|
|
|
|
|
int type_ = list_.first()->type();
|
|
|
|
|
for (QGraphicsItem *qgi : list_)
|
|
|
|
|
{
|
|
|
|
|
if (qgi->type() != type_)
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-19 08:12:17 +00:00
|
|
|
|
}
|
2015-05-08 17:49:29 +00:00
|
|
|
|
|
2015-06-19 08:12:17 +00:00
|
|
|
|
QGraphicsItem *item = m_diagram->selectedItems().first();
|
|
|
|
|
const int type_ = item->type();
|
|
|
|
|
|
|
|
|
|
switch (type_)
|
|
|
|
|
{
|
2019-02-19 16:42:07 +00:00
|
|
|
|
case Element::Type: //1000
|
2017-11-27 19:37:39 +00:00
|
|
|
|
{
|
2019-02-20 20:36:56 +00:00
|
|
|
|
if (count_ > 1)
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-06-19 08:12:17 +00:00
|
|
|
|
//We already edit an element, just update the editor with a new element
|
|
|
|
|
if (m_edited_qgi_type == type_)
|
2015-05-25 10:22:00 +00:00
|
|
|
|
{
|
2015-06-19 08:12:17 +00:00
|
|
|
|
static_cast<ElementPropertiesWidget*>(editors().first())->setElement(static_cast<Element*>(item));
|
|
|
|
|
return;
|
2015-05-25 10:22:00 +00:00
|
|
|
|
}
|
2015-06-19 08:12:17 +00:00
|
|
|
|
|
2015-05-25 10:22:00 +00:00
|
|
|
|
clear();
|
2015-06-19 08:12:17 +00:00
|
|
|
|
m_edited_qgi_type = type_;
|
2015-06-23 20:40:05 +00:00
|
|
|
|
addEditor(new ElementPropertiesWidget(static_cast<Element*>(item), this));
|
2017-11-27 19:37:39 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-02-19 16:42:07 +00:00
|
|
|
|
case IndependentTextItem::Type: //1005
|
|
|
|
|
{
|
2019-02-20 20:36:56 +00:00
|
|
|
|
QList<IndependentTextItem *> text_list;
|
|
|
|
|
for (QGraphicsItem *qgi : m_diagram->selectedItems()) {
|
|
|
|
|
text_list.append(static_cast<IndependentTextItem*>(qgi));
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 16:42:07 +00:00
|
|
|
|
if (m_edited_qgi_type == type_)
|
|
|
|
|
{
|
2019-02-20 20:36:56 +00:00
|
|
|
|
static_cast<IndiTextPropertiesWidget*>(editors().first())->setText(text_list);
|
2019-02-19 16:42:07 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = type_;
|
2019-02-20 20:36:56 +00:00
|
|
|
|
addEditor(new IndiTextPropertiesWidget(text_list, this));
|
2019-02-19 16:42:07 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DiagramImageItem::Type: //1007
|
2017-11-27 19:37:39 +00:00
|
|
|
|
{
|
2019-02-20 20:36:56 +00:00
|
|
|
|
if (count_ > 1)
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-25 10:22:00 +00:00
|
|
|
|
clear();
|
2015-06-19 08:12:17 +00:00
|
|
|
|
m_edited_qgi_type = type_;
|
|
|
|
|
addEditor(new ImagePropertiesWidget(static_cast<DiagramImageItem*>(item), this));
|
2017-11-27 19:37:39 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-02-19 16:42:07 +00:00
|
|
|
|
case QetShapeItem::Type: //1008
|
2017-11-27 19:37:39 +00:00
|
|
|
|
{
|
2019-03-04 15:34:42 +00:00
|
|
|
|
QList<QetShapeItem *> shapes_list;
|
|
|
|
|
for (QGraphicsItem *qgi : m_diagram->selectedItems()) {
|
|
|
|
|
shapes_list.append(static_cast<QetShapeItem*>(qgi));
|
2019-02-20 20:36:56 +00:00
|
|
|
|
}
|
2019-03-04 15:34:42 +00:00
|
|
|
|
|
2015-06-21 20:16:41 +00:00
|
|
|
|
if (m_edited_qgi_type == type_)
|
|
|
|
|
{
|
2019-03-04 15:34:42 +00:00
|
|
|
|
static_cast<ShapeGraphicsItemPropertiesWidget*>(editors().first())->setItems(shapes_list);
|
2015-06-21 20:16:41 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = type_;
|
2019-03-19 17:44:18 +00:00
|
|
|
|
addEditor(new ShapeGraphicsItemPropertiesWidget(shapes_list, this));
|
2017-11-27 19:37:39 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-02-19 16:42:07 +00:00
|
|
|
|
case DynamicElementTextItem::Type: //1010
|
2017-11-27 19:37:39 +00:00
|
|
|
|
{
|
2019-02-20 20:36:56 +00:00
|
|
|
|
if (count_ > 1)
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
|
DynamicElementTextItem *deti = static_cast<DynamicElementTextItem *>(item);
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
2017-11-27 19:37:39 +00:00
|
|
|
|
//For dynamic element text, we open the element editor to edit it
|
|
|
|
|
//If we already edit an element, just update the editor with a new element
|
2017-08-03 17:36:08 +00:00
|
|
|
|
if (m_edited_qgi_type == Element::Type)
|
|
|
|
|
{
|
2017-08-22 18:27:23 +00:00
|
|
|
|
static_cast<ElementPropertiesWidget*>(editors().first())->setDynamicText(deti);
|
2017-08-03 17:36:08 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = Element::Type;
|
2017-08-22 18:27:23 +00:00
|
|
|
|
addEditor(new ElementPropertiesWidget(deti, this));
|
2017-11-27 19:37:39 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QGraphicsItemGroup::Type:
|
|
|
|
|
{
|
2019-02-20 20:36:56 +00:00
|
|
|
|
if (count_ > 1)
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
|
if(ElementTextItemGroup *group = dynamic_cast<ElementTextItemGroup *>(item))
|
2017-11-27 19:37:39 +00:00
|
|
|
|
{
|
|
|
|
|
//For element text item group, we open the element editor to edit it
|
|
|
|
|
//If we already edit an element, just update the editor with a new element
|
|
|
|
|
if(m_edited_qgi_type == Element::Type)
|
|
|
|
|
{
|
|
|
|
|
static_cast<ElementPropertiesWidget *>(editors().first())->setTextsGroup(group);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
m_edited_qgi_type = Element::Type;
|
|
|
|
|
addEditor(new ElementPropertiesWidget(group, this));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-06-19 08:12:17 +00:00
|
|
|
|
default:
|
|
|
|
|
m_edited_qgi_type = -1;
|
2015-05-25 10:22:00 +00:00
|
|
|
|
clear();
|
2015-05-07 22:15:00 +00:00
|
|
|
|
}
|
2015-05-27 07:22:50 +00:00
|
|
|
|
|
2019-02-20 20:36:56 +00:00
|
|
|
|
for (PropertiesEditorWidget *pew : editors()) {
|
2015-05-27 07:22:50 +00:00
|
|
|
|
pew->setLiveEdit(true);
|
2019-02-20 20:36:56 +00:00
|
|
|
|
}
|
2015-05-07 22:15:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief DiagramPropertiesEditorDockWidget::diagramWasDeleted
|
|
|
|
|
* Remove current editor and set m_diagram to nullptr.
|
|
|
|
|
*/
|
|
|
|
|
void DiagramPropertiesEditorDockWidget::diagramWasDeleted()
|
|
|
|
|
{
|
|
|
|
|
m_diagram = nullptr;
|
2016-10-19 16:39:50 +00:00
|
|
|
|
m_edited_qgi_type = -1;
|
2015-05-07 22:15:00 +00:00
|
|
|
|
clear();
|
|
|
|
|
}
|