[qet] [3990] Dock properties editor : when selection change dock try to stay in the same tab with the new selection (if possible) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
- To: qet@xxxxxxxxxxxxxxxxxxx
- Subject: [qet] [3990] Dock properties editor : when selection change dock try to stay in the same tab with the new selection (if possible)
- From: subversion@xxxxxxxxxxxxx
- Date: Mon, 25 May 2015 12:22:01 +0200
Revision: 3990
Author: blacksun
Date: 2015-05-25 12:22:00 +0200 (Mon, 25 May 2015)
Log Message:
-----------
Dock properties editor : when selection change dock try to stay in the same tab with the new selection (if possible)
Modified Paths:
--------------
trunk/sources/PropertiesEditor/propertieseditordockwidget.cpp
trunk/sources/PropertiesEditor/propertieseditordockwidget.h
trunk/sources/ui/diagrampropertieseditordockwidget.cpp
trunk/sources/ui/diagrampropertieseditordockwidget.h
trunk/sources/ui/elementinfowidget.cpp
trunk/sources/ui/elementinfowidget.h
trunk/sources/ui/elementpropertieswidget.cpp
trunk/sources/ui/elementpropertieswidget.h
trunk/sources/ui/linksingleelementwidget.cpp
trunk/sources/ui/linksingleelementwidget.h
trunk/sources/ui/masterpropertieswidget.cpp
trunk/sources/ui/masterpropertieswidget.h
Added Paths:
-----------
trunk/sources/ui/abstractelementpropertieseditorwidget.cpp
trunk/sources/ui/abstractelementpropertieseditorwidget.h
Modified: trunk/sources/PropertiesEditor/propertieseditordockwidget.cpp
===================================================================
--- trunk/sources/PropertiesEditor/propertieseditordockwidget.cpp 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/PropertiesEditor/propertieseditordockwidget.cpp 2015-05-25 10:22:00 UTC (rev 3990)
@@ -105,6 +105,14 @@
}
/**
+ * @brief PropertiesEditorDockWidget::editors
+ * @return all editor used in this dock
+ */
+QList<PropertiesEditorWidget *> PropertiesEditorDockWidget::editors() const {
+ return m_editor_list;
+}
+
+/**
* @brief PropertiesEditorDockWidget::removeEditor
* Remove @editor from this dock. The editor wasn't delete a the end of this method
* If the editor was the last on this widget, we disabled the button box
Modified: trunk/sources/PropertiesEditor/propertieseditordockwidget.h
===================================================================
--- trunk/sources/PropertiesEditor/propertieseditordockwidget.h 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/PropertiesEditor/propertieseditordockwidget.h 2015-05-25 10:22:00 UTC (rev 3990)
@@ -39,6 +39,7 @@
virtual void apply();
virtual void reset();
bool addEditor (PropertiesEditorWidget *editor, int index = 0);
+ QList<PropertiesEditorWidget *> editors() const;
bool removeEditor (PropertiesEditorWidget *editor);
void setDisabledButtonBox(bool b = true);
void setEnabledButtonBox (bool b = true);
Added: trunk/sources/ui/abstractelementpropertieseditorwidget.cpp
===================================================================
--- trunk/sources/ui/abstractelementpropertieseditorwidget.cpp (rev 0)
+++ trunk/sources/ui/abstractelementpropertieseditorwidget.cpp 2015-05-25 10:22:00 UTC (rev 3990)
@@ -0,0 +1,23 @@
+/*
+ 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 "abstractelementpropertieseditorwidget.h"
+
+AbstractElementPropertiesEditorWidget::AbstractElementPropertiesEditorWidget(QWidget *parent) :
+ PropertiesEditorWidget(parent),
+ m_element (nullptr)
+{}
Added: trunk/sources/ui/abstractelementpropertieseditorwidget.h
===================================================================
--- trunk/sources/ui/abstractelementpropertieseditorwidget.h (rev 0)
+++ trunk/sources/ui/abstractelementpropertieseditorwidget.h 2015-05-25 10:22:00 UTC (rev 3990)
@@ -0,0 +1,42 @@
+/*
+ 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/>.
+*/
+#ifndef ABSTRACTELEMENTPROPERTIESEDITORWIDGET_H
+#define ABSTRACTELEMENTPROPERTIESEDITORWIDGET_H
+
+#include "PropertiesEditor/propertieseditorwidget.h"
+
+class Element;
+
+/**
+ * @brief The AbstractElementPropertiesEditorWidget class
+ * This class provide common method for all widget used to edit some properties of an element
+ */
+class AbstractElementPropertiesEditorWidget : public PropertiesEditorWidget
+{
+ Q_OBJECT
+ public:
+ explicit AbstractElementPropertiesEditorWidget(QWidget *parent = 0);
+ virtual void setElement(Element *element) =0;
+
+ protected:
+ Element *m_element;
+
+
+};
+
+#endif // ABSTRACTELEMENTPROPERTIESEDITORWIDGET_H
Modified: trunk/sources/ui/diagrampropertieseditordockwidget.cpp
===================================================================
--- trunk/sources/ui/diagrampropertieseditordockwidget.cpp 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/diagrampropertieseditordockwidget.cpp 2015-05-25 10:22:00 UTC (rev 3990)
@@ -29,7 +29,8 @@
*/
DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget(QWidget *parent) :
PropertiesEditorDockWidget(parent),
- m_diagram(nullptr)
+ m_diagram(nullptr),
+ m_edited_qgi_type(UnknowQGIType)
{}
/**
@@ -43,7 +44,6 @@
void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram)
{
if (m_diagram == diagram) return;
- clear();
if (m_diagram)
{
@@ -59,7 +59,10 @@
selectionChanged();
}
else
+ {
m_diagram = nullptr;
+ clear();
+ }
}
/**
@@ -70,17 +73,37 @@
void DiagramPropertiesEditorDockWidget::selectionChanged()
{
if (!m_diagram) return;
- clear();
- if (m_diagram->selectedItems().size() == 1)
+ if (m_diagram->selectedItems().size() == 1) //We can open an editor only when there is one selected item
{
QGraphicsItem *item = m_diagram->selectedItems().first();
if (Element *elmt = dynamic_cast<Element*>(item))
+ {
+ if (m_edited_qgi_type == ElementQGIType && editors().size() == 1)
+ {
+ ElementPropertiesWidget *epw = dynamic_cast<ElementPropertiesWidget*>(editors().first());
+ if (epw) //In this case we only update each editor widget with the new element instead of create new widget.
+ {
+ epw->setElement(elmt);
+ return;
+ }
+ }
+ clear();
+ m_edited_qgi_type = ElementQGIType;
addEditor(new ElementPropertiesWidget(elmt, this));
+ }
else if (DiagramImageItem *image = dynamic_cast<DiagramImageItem *>(item))
+ {
+ clear();
+ m_edited_qgi_type = ImageQGIType;
addEditor(new ImagePropertiesWidget(image, this));
+ }
+ else
+ clear();
}
+ else
+ clear();
}
/**
Modified: trunk/sources/ui/diagrampropertieseditordockwidget.h
===================================================================
--- trunk/sources/ui/diagrampropertieseditordockwidget.h 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/diagrampropertieseditordockwidget.h 2015-05-25 10:22:00 UTC (rev 3990)
@@ -21,6 +21,7 @@
#include "PropertiesEditor/propertieseditordockwidget.h"
class Diagram;
+class QGraphicsItem;
class DiagramPropertiesEditorDockWidget : public PropertiesEditorDockWidget
{
@@ -36,7 +37,9 @@
void diagramWasDeleted();
private:
+ enum EditedQGIType {UnknowQGIType, ElementQGIType, ImageQGIType};
Diagram *m_diagram;
+ EditedQGIType m_edited_qgi_type;
};
#endif // DIAGRAMPROPERTIESEDITORDOCKWIDGET_H
Modified: trunk/sources/ui/elementinfowidget.cpp
===================================================================
--- trunk/sources/ui/elementinfowidget.cpp 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/elementinfowidget.cpp 2015-05-25 10:22:00 UTC (rev 3990)
@@ -30,15 +30,13 @@
* @param parent parent widget
*/
ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) :
- PropertiesEditorWidget(parent),
+ AbstractElementPropertiesEditorWidget(parent),
ui(new Ui::ElementInfoWidget),
- element_(elmt),
- elmt_info(elmt->elementInformations()),
m_first_activation (false)
{
ui->setupUi(this);
buildInterface();
- fillInfo();
+ setElement(elmt);
}
/**
@@ -52,6 +50,19 @@
}
/**
+ * @brief ElementInfoWidget::setElement
+ * Set @element to be the edited element
+ * @param element
+ */
+void ElementInfoWidget::setElement(Element *element)
+{
+ if (m_element == element) return;
+ m_element = element;
+ m_element_info = m_element->elementInformations();
+ fillInfo();
+}
+
+/**
* @brief ElementInfoWidget::apply
* Apply the new information with a new undo command (got with method associatedUndo)
* pushed to the stack of element project.
@@ -59,7 +70,7 @@
void ElementInfoWidget::apply()
{
if (QUndoCommand *undo = associatedUndo())
- element_ -> diagram() -> undoStack().push(undo);
+ m_element -> diagram() -> undoStack().push(undo);
}
/**
@@ -71,7 +82,7 @@
*/
QUndoCommand* ElementInfoWidget::associatedUndo() const {
DiagramContext new_info;
- DiagramContext old_info = element_ -> elementInformations();
+ DiagramContext old_info = m_element -> elementInformations();
foreach (ElementInfoPartWidget *eipw, eipw_list) {
//add value only if they're something to store
@@ -82,7 +93,7 @@
}
if (old_info != new_info) {
- return (new ChangeElementInformationCommand(element_, old_info, new_info));
+ return (new ChangeElementInformationCommand(m_element, old_info, new_info));
}
return nullptr;
}
@@ -122,19 +133,19 @@
/**
* @brief ElementInfoWidget::fillInfo
- * fill information fetch in elmt_info to the
+ * fill information fetch in m_element_info to the
* corresponding line edit
*/
void ElementInfoWidget::fillInfo() {
foreach (ElementInfoPartWidget *eipw, eipw_list) {
- eipw -> setText (elmt_info[eipw->key()].toString());
- eipw -> setShow (elmt_info.keyMustShow(eipw->key()));
+ eipw -> setText (m_element_info[eipw->key()].toString());
+ eipw -> setShow (m_element_info.keyMustShow(eipw->key()));
//If the current eipw is for label or comment and the text is empty
//we force the checkbox to ckecked
if (eipw -> key() == "label" || eipw -> key() == "comment") {
- if (elmt_info[eipw->key()].toString().isEmpty())
+ if (m_element_info[eipw->key()].toString().isEmpty())
eipw->setShow(true);
}
else //< for other eipw we hide the checkbox
Modified: trunk/sources/ui/elementinfowidget.h
===================================================================
--- trunk/sources/ui/elementinfowidget.h 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/elementinfowidget.h 2015-05-25 10:22:00 UTC (rev 3990)
@@ -20,7 +20,7 @@
#include <QWidget>
#include "diagramcontext.h"
-#include "PropertiesEditor/propertieseditorwidget.h"
+#include "abstractelementpropertieseditorwidget.h"
class Element;
class QUndoCommand;
@@ -35,7 +35,7 @@
* @brief The ElementInfoWidget class
* this class is a widget to edit an element informations.
*/
-class ElementInfoWidget : public PropertiesEditorWidget
+class ElementInfoWidget : public AbstractElementPropertiesEditorWidget
{
Q_OBJECT
@@ -44,6 +44,7 @@
explicit ElementInfoWidget(Element *elmt, QWidget *parent = 0);
~ElementInfoWidget();
+ void setElement(Element *element);
void apply();
QUndoCommand *associatedUndo () const;
QString title() const {return tr("Informations");}
@@ -61,8 +62,7 @@
//ATTRIBUTES
private:
Ui::ElementInfoWidget *ui;
- Element *element_;
- DiagramContext elmt_info;
+ DiagramContext m_element_info;
QList <ElementInfoPartWidget *> eipw_list;
bool m_first_activation;
};
Modified: trunk/sources/ui/elementpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/elementpropertieswidget.cpp 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/elementpropertieswidget.cpp 2015-05-25 10:22:00 UTC (rev 3990)
@@ -36,15 +36,43 @@
* @param parent
*/
ElementPropertiesWidget::ElementPropertiesWidget(Element *elmt, QWidget *parent) :
- PropertiesEditorWidget (parent),
- m_element (elmt),
+ AbstractElementPropertiesEditorWidget (parent),
m_diagram (elmt->diagram()),
- m_tab (nullptr)
+ m_tab (nullptr),
+ m_general_widget(nullptr)
{
buildGui();
+ setElement(elmt);
}
/**
+ * @brief ElementPropertiesWidget::setElement
+ * Set @element to be the edited element
+ * @param element
+ */
+void ElementPropertiesWidget::setElement(Element *element)
+{
+ if (m_element == element) return;
+ Element *previous_element = m_element;
+ m_element = element;
+
+ if (previous_element)
+ {
+ //If previous element is same type as new element we just call setElement for each editor
+ if(previous_element->linkType() == m_element->linkType())
+ {
+ foreach (AbstractElementPropertiesEditorWidget *aepew, m_list_editor)
+ {
+ aepew->setElement(m_element);
+ addGeneralWidget();
+ }
+ return;
+ }
+ }
+ updateUi();
+}
+
+/**
* @brief ElementPropertiesWidget::apply
* Apply the new properties by pushing an undo command
* to the parent project's undo stack of element
@@ -109,7 +137,27 @@
void ElementPropertiesWidget::buildGui()
{
m_tab = new QTabWidget(this);
+ QVBoxLayout *main_layout = new QVBoxLayout(this);
+ main_layout -> addWidget(m_tab);
+ setLayout(main_layout);
+}
+/**
+ * @brief ElementPropertiesWidget::updateUi
+ * Update the content of this widget
+ */
+void ElementPropertiesWidget::updateUi()
+{
+ //We keep the current title of the tab, to return to the same tab
+ //if possible, at the end of this method
+ QString tab_text;
+ tab_text = m_tab->tabText(m_tab->currentIndex());
+
+ //Purge the tab widget and delete all widget
+ m_tab->clear();
+ qDeleteAll(m_list_editor); m_list_editor.clear();
+ if(m_general_widget) delete m_general_widget; m_general_widget = nullptr;
+
//Add tab according to the element
switch (m_element -> linkType())
{
@@ -136,14 +184,39 @@
}
foreach (PropertiesEditorWidget *pew, m_list_editor) m_tab->addTab(pew, pew->title());
- m_tab -> addTab(generalWidget(), tr("Général"));
+ addGeneralWidget();
- QVBoxLayout *main_layout = new QVBoxLayout(this);
- main_layout -> addWidget(m_tab);
- setLayout(main_layout);
+ if (!tab_text.isEmpty())
+ {
+ for(int i=0 ; i<m_tab->count() ; ++i)
+ {
+ if (tab_text == m_tab->tabBar()->tabText(i))
+ {
+ m_tab->setCurrentIndex(i);
+ break;
+ }
+ }
+ }
}
/**
+ * @brief ElementPropertiesWidget::addGeneralWidget
+ * Add or update the general widget on this tab widget
+ */
+void ElementPropertiesWidget::addGeneralWidget()
+{
+ int index = m_tab->currentIndex();
+ if (m_general_widget)
+ {
+ m_tab->removeTab(m_tab->indexOf(m_general_widget));
+ delete m_general_widget;
+ }
+ m_general_widget = generalWidget();
+ m_tab -> addTab(m_general_widget, tr("Général"));
+ m_tab->setCurrentIndex(index);
+}
+
+/**
* @brief ElementPropertiesWidget::generalWidget
* @return build and return the "general" widget
*/
Modified: trunk/sources/ui/elementpropertieswidget.h
===================================================================
--- trunk/sources/ui/elementpropertieswidget.h 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/elementpropertieswidget.h 2015-05-25 10:22:00 UTC (rev 3990)
@@ -18,7 +18,7 @@
#ifndef ELEMENTPROPERTIESWIDGET_H
#define ELEMENTPROPERTIESWIDGET_H
-#include "PropertiesEditor/propertieseditorwidget.h"
+#include "abstractelementpropertieseditorwidget.h"
class Element;
class Diagram;
@@ -26,12 +26,13 @@
class ElementsLocation;
-class ElementPropertiesWidget : public PropertiesEditorWidget
+class ElementPropertiesWidget : public AbstractElementPropertiesEditorWidget
{
Q_OBJECT
public:
explicit ElementPropertiesWidget(Element *elmt, QWidget *parent = 0);
+ void setElement(Element *element);
void apply();
void reset();
@@ -41,6 +42,8 @@
private:
void buildGui();
+ void updateUi();
+ void addGeneralWidget();
QWidget *generalWidget();
signals:
@@ -50,10 +53,10 @@
void editElementRequired(const ElementsLocation &);
private:
- Element *m_element;
Diagram *m_diagram;
QTabWidget *m_tab;
- QList <PropertiesEditorWidget *> m_list_editor;
+ QList <AbstractElementPropertiesEditorWidget *> m_list_editor;
+ QWidget *m_general_widget;
};
#endif // ELEMENTPROPERTIESWIDGET_H
Modified: trunk/sources/ui/linksingleelementwidget.cpp
===================================================================
--- trunk/sources/ui/linksingleelementwidget.cpp 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/linksingleelementwidget.cpp 2015-05-25 10:22:00 UTC (rev 3990)
@@ -31,9 +31,8 @@
* the parent widget
*/
LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) :
- PropertiesEditorWidget(parent),
+ AbstractElementPropertiesEditorWidget(parent),
ui(new Ui::LinkSingleElementWidget),
- m_element(nullptr),
esw_(0),
unlink_widget(0),
unlink_(false),
Modified: trunk/sources/ui/linksingleelementwidget.h
===================================================================
--- trunk/sources/ui/linksingleelementwidget.h 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/linksingleelementwidget.h 2015-05-25 10:22:00 UTC (rev 3990)
@@ -18,9 +18,10 @@
#ifndef LINKSINGLEELEMENTWIDGET_H
#define LINKSINGLEELEMENTWIDGET_H
-#include "PropertiesEditor/propertieseditorwidget.h"
#include "element.h"
+#include "abstractelementpropertieseditorwidget.h"
+
class Diagram;
class QLineEdit;
class ElementSelectorWidget;
@@ -39,7 +40,7 @@
* If the element is already linked, the widget ask user to unlink.
* This widget embedded the diagram command for undo/redo the action
*/
-class LinkSingleElementWidget : public PropertiesEditorWidget
+class LinkSingleElementWidget : public AbstractElementPropertiesEditorWidget
{
Q_OBJECT
@@ -72,7 +73,6 @@
///Attributes
private:
Ui::LinkSingleElementWidget *ui;
- Element *m_element;
ElementSelectorWidget *esw_;
QList <Diagram *> diagram_list;
QWidget *unlink_widget;
Modified: trunk/sources/ui/masterpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/masterpropertieswidget.cpp 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/masterpropertieswidget.cpp 2015-05-25 10:22:00 UTC (rev 3990)
@@ -31,22 +31,15 @@
* @param parent
*/
MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
- PropertiesEditorWidget(parent),
+ AbstractElementPropertiesEditorWidget(parent),
ui(new Ui::MasterPropertiesWidget),
- m_element(elmt),
m_showed_element (nullptr),
m_project(nullptr)
{
- if(Q_LIKELY(elmt->diagram() && elmt->diagram()->project()))
- {
- m_project = elmt->diagram()->project();
- connect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
- }
-
ui->setupUi(this);
connect(ui->free_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
connect(ui->linked_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
- buildInterface();
+ setElement(elmt);
}
/**
@@ -68,6 +61,15 @@
{
if (m_element == element) return;
if (m_showed_element) {m_showed_element->setHighlighted(false); m_showed_element = nullptr;}
+ if (m_project) disconnect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
+
+ if(Q_LIKELY(element->diagram() && element->diagram()->project()))
+ {
+ m_project = element->diagram()->project();
+ connect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
+ }
+ else m_project = nullptr;
+
m_element = element;
buildInterface();
}
Modified: trunk/sources/ui/masterpropertieswidget.h
===================================================================
--- trunk/sources/ui/masterpropertieswidget.h 2015-05-25 05:41:33 UTC (rev 3989)
+++ trunk/sources/ui/masterpropertieswidget.h 2015-05-25 10:22:00 UTC (rev 3990)
@@ -20,7 +20,7 @@
#include <QWidget>
#include <QHash>
-#include "PropertiesEditor/propertieseditorwidget.h"
+#include "abstractelementpropertieseditorwidget.h"
class QListWidgetItem;
class Element;
@@ -38,7 +38,7 @@
* This class embenddedthe undo/redo command when apply new connection.
*/
-class MasterPropertiesWidget : public PropertiesEditorWidget
+class MasterPropertiesWidget : public AbstractElementPropertiesEditorWidget
{
Q_OBJECT
@@ -62,7 +62,6 @@
private:
Ui::MasterPropertiesWidget *ui;
- Element *m_element;
QHash <QListWidgetItem *, Element *> lwi_hash;
Element *m_showed_element;
QETProject *m_project;