Diagram editor : add dock widget for edit the current selection.

For the moment only work with element


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3943 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-05-07 22:15:00 +00:00
parent f022133de4
commit 7ef8cbc0db
18 changed files with 494 additions and 20 deletions

View File

@@ -0,0 +1,88 @@
/*
Copyright 2006-2015 The QElectroTech Team
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"
/**
* @brief DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget
* Constructor
* @param parent : parent widget
*/
DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget(QWidget *parent) :
PropertiesEditorDockWidget(parent),
m_diagram(nullptr)
{}
/**
* @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;
clear();
if (m_diagram)
{
disconnect(m_diagram, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
disconnect(m_diagram, SIGNAL(destroyed()), this, SLOT(diagramWasDeleted()));
}
if (diagram)
{
m_diagram = diagram;
connect(m_diagram, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
connect(m_diagram, SIGNAL(destroyed()), this, SLOT(diagramWasDeleted()));
selectionChanged();
}
else
m_diagram = nullptr;
}
/**
* @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;
clear();
if (m_diagram->selectedItems().size() == 1)
{
QGraphicsItem *item = m_diagram->selectedItems().first();
if (Element *elmt = dynamic_cast<Element*>(item))
addEditor(new ElementPropertiesWidget(elmt, this));
}
}
/**
* @brief DiagramPropertiesEditorDockWidget::diagramWasDeleted
* Remove current editor and set m_diagram to nullptr.
*/
void DiagramPropertiesEditorDockWidget::diagramWasDeleted()
{
m_diagram = nullptr;
clear();
}

View File

@@ -15,28 +15,28 @@
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROPERTIESEDITORWIDGET_H
#define PROPERTIESEDITORWIDGET_H
#ifndef DIAGRAMPROPERTIESEDITORDOCKWIDGET_H
#define DIAGRAMPROPERTIESEDITORDOCKWIDGET_H
#include <QWidget>
#include "PropertiesEditor/propertieseditordockwidget.h"
class QUndoCommand;
class Diagram;
/**
* @brief The PropertiesEditorWidget class
* This class extend QWidget method for have common way
* to edit propertie.
*/
class PropertiesEditorWidget : public QWidget
class DiagramPropertiesEditorDockWidget : public PropertiesEditorDockWidget
{
Q_OBJECT
public:
explicit PropertiesEditorWidget(QWidget *parent = 0);
virtual void apply() {}
virtual void reset() {}
virtual QUndoCommand *associatedUndo () const;
virtual QString title() const;
public:
DiagramPropertiesEditorDockWidget(QWidget *parent = nullptr);
void setDiagram(Diagram *diagram);
private slots:
void selectionChanged();
void diagramWasDeleted();
private:
Diagram *m_diagram;
};
#endif // PROPERTIESEDITORWIDGET_H
#endif // DIAGRAMPROPERTIESEDITORDOCKWIDGET_H

View File

@@ -20,7 +20,7 @@
#include <QWidget>
#include "diagramcontext.h"
#include "propertieseditorwidget.h"
#include "PropertiesEditor/propertieseditorwidget.h"
class Element;
class QUndoCommand;

View File

@@ -18,7 +18,7 @@
#ifndef ELEMENTPROPERTIESWIDGET_H
#define ELEMENTPROPERTIESWIDGET_H
#include "propertieseditorwidget.h"
#include "PropertiesEditor/propertieseditorwidget.h"
class Element;
class Diagram;

View File

@@ -62,10 +62,15 @@ ElementSelectorWidget::~ElementSelectorWidget()
* @param elmt
*/
void ElementSelectorWidget::showElement(Element *elmt) {
if (showed_element) showed_element->setHighlighted(false);
if (showed_element)
{
disconnect(showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
showed_element->setHighlighted(false);
}
elmt->diagram()->showMe();
elmt->setHighlighted(true);
showed_element = elmt;
connect(showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
}
/**
@@ -224,6 +229,14 @@ void ElementSelectorWidget::showElementFromList(const int i) {
showElement(elements_list.at(i));
}
/**
* @brief ElementSelectorWidget::showedElementWasDeleted
* Set to nullptr the current showed element when he was deleted
*/
void ElementSelectorWidget::showedElementWasDeleted() {
showed_element = nullptr;
}
/**
* @brief ElementSelectorWidget::filter
* @return A stringlist with all available value

View File

@@ -55,8 +55,9 @@ class ElementSelectorWidget : public QWidget
void buildInterface();
private slots:
void setSelectedElement (const int i) {selected_element = elements_list.at(i);}
void showElementFromList (const int i);
void setSelectedElement (const int i) {selected_element = elements_list.at(i);}
void showElementFromList (const int i);
void showedElementWasDeleted ();
///Attributes

View File

@@ -18,7 +18,7 @@
#ifndef LINKSINGLEELEMENTWIDGET_H
#define LINKSINGLEELEMENTWIDGET_H
#include "propertieseditorwidget.h"
#include "PropertiesEditor/propertieseditorwidget.h"
#include "element.h"
class Diagram;

View File

@@ -33,7 +33,8 @@
MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
PropertiesEditorWidget(parent),
ui(new Ui::MasterPropertiesWidget),
element_(elmt)
element_(elmt),
m_showed_element (nullptr)
{
ui->setupUi(this);
buildInterface();
@@ -47,7 +48,8 @@ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
*/
MasterPropertiesWidget::~MasterPropertiesWidget()
{
foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false);
if (m_showed_element) m_showed_element->setHighlighted(false);
//foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false);
delete ui;
}
@@ -184,9 +186,24 @@ void MasterPropertiesWidget::on_unlink_button_clicked() {
* Show the element corresponding to the given QListWidgetItem
* @param lwi
*/
void MasterPropertiesWidget::showElementFromLWI(QListWidgetItem *lwi) {
foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false);
Element *elmt = lwi_hash[lwi];
elmt->diagram()->showMe();
elmt->setHighlighted(true);
void MasterPropertiesWidget::showElementFromLWI(QListWidgetItem *lwi)
{
if (m_showed_element)
{
disconnect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
m_showed_element -> setHighlighted(false);
}
m_showed_element = lwi_hash[lwi];
m_showed_element->diagram()->showMe();
m_showed_element->setHighlighted(true);
connect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
}
/**
* @brief MasterPropertiesWidget::showedElementWasDeleted
* Set to nullptr the current showed element when he was deleted
*/
void MasterPropertiesWidget::showedElementWasDeleted() {
m_showed_element = nullptr;
}

View File

@@ -20,7 +20,7 @@
#include <QWidget>
#include <QHash>
#include <propertieseditorwidget.h>
#include "PropertiesEditor/propertieseditorwidget.h"
class QListWidgetItem;
class Element;
@@ -53,14 +53,16 @@ class MasterPropertiesWidget : public PropertiesEditorWidget
void buildInterface();
private slots:
void on_link_button_clicked();
void on_unlink_button_clicked();
void showElementFromLWI(QListWidgetItem *lwi);
void on_link_button_clicked();
void on_unlink_button_clicked();
void showElementFromLWI(QListWidgetItem *lwi);
void showedElementWasDeleted ();
private:
Ui::MasterPropertiesWidget *ui;
Element *element_;
QHash <QListWidgetItem *, Element *> lwi_hash;
Element *m_showed_element;
};
#endif // MASTERPROPERTIESWIDGET_H

View File

@@ -1,46 +0,0 @@
/*
Copyright 2006-2015 The QElectroTech Team
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 "propertieseditorwidget.h"
#include <QUndoCommand>
/**
* @brief PropertiesEditorWidget::PropertiesEditorWidget
* Constructor
* @param parent : parent widget
*/
PropertiesEditorWidget::PropertiesEditorWidget(QWidget *parent) :
QWidget(parent)
{}
/**
* @brief PropertiesEditorWidget::associatedUndo
* By default, return a nullptr
* @return nullptr
*/
QUndoCommand *PropertiesEditorWidget::associatedUndo() const{
return nullptr;
}
/**
* @brief PropertiesEditorWidget::title
* @return the title of this editor
*/
QString PropertiesEditorWidget::title() const
{
return QString();
}