Dock properties editor : when selection change dock try to stay in the same tab with the new selection (if possible)

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3990 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-05-25 10:22:00 +00:00
parent 175029dc2d
commit db173a1c39
14 changed files with 234 additions and 47 deletions

View File

@@ -104,6 +104,14 @@ bool PropertiesEditorDockWidget::addEditor(PropertiesEditorWidget *editor, int i
return true;
}
/**
* @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

View File

@@ -39,6 +39,7 @@ class PropertiesEditorDockWidget : public QDockWidget
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);

View File

@@ -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)
{}

View File

@@ -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

View File

@@ -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 @@ DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget(QWidget *pa
void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram)
{
if (m_diagram == diagram) return;
clear();
if (m_diagram)
{
@@ -59,7 +59,10 @@ void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram)
selectionChanged();
}
else
{
m_diagram = nullptr;
clear();
}
}
/**
@@ -70,17 +73,37 @@ void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram)
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();
}
/**

View File

@@ -21,6 +21,7 @@
#include "PropertiesEditor/propertieseditordockwidget.h"
class Diagram;
class QGraphicsItem;
class DiagramPropertiesEditorDockWidget : public PropertiesEditorDockWidget
{
@@ -36,7 +37,9 @@ class DiagramPropertiesEditorDockWidget : public PropertiesEditorDockWidget
void diagramWasDeleted();
private:
enum EditedQGIType {UnknowQGIType, ElementQGIType, ImageQGIType};
Diagram *m_diagram;
EditedQGIType m_edited_qgi_type;
};
#endif // DIAGRAMPROPERTIESEDITORDOCKWIDGET_H

View File

@@ -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);
}
/**
@@ -51,6 +49,19 @@ ElementInfoWidget::~ElementInfoWidget()
delete ui;
}
/**
* @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)
@@ -59,7 +70,7 @@ ElementInfoWidget::~ElementInfoWidget()
void ElementInfoWidget::apply()
{
if (QUndoCommand *undo = associatedUndo())
element_ -> diagram() -> undoStack().push(undo);
m_element -> diagram() -> undoStack().push(undo);
}
/**
@@ -71,7 +82,7 @@ void ElementInfoWidget::apply()
*/
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 @@ QUndoCommand* ElementInfoWidget::associatedUndo() const {
}
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 @@ void ElementInfoWidget::buildInterface() {
/**
* @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

View File

@@ -20,7 +20,7 @@
#include <QWidget>
#include "diagramcontext.h"
#include "PropertiesEditor/propertieseditorwidget.h"
#include "abstractelementpropertieseditorwidget.h"
class Element;
class QUndoCommand;
@@ -35,7 +35,7 @@ namespace Ui {
* @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 @@ class ElementInfoWidget : public PropertiesEditorWidget
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 @@ class ElementInfoWidget : public PropertiesEditorWidget
//ATTRIBUTES
private:
Ui::ElementInfoWidget *ui;
Element *element_;
DiagramContext elmt_info;
DiagramContext m_element_info;
QList <ElementInfoPartWidget *> eipw_list;
bool m_first_activation;
};

View File

@@ -36,12 +36,40 @@
* @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();
}
/**
@@ -109,6 +137,26 @@ void ElementPropertiesWidget::editElement()
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,11 +184,36 @@ void ElementPropertiesWidget::buildGui()
}
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);
}
/**

View File

@@ -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 QTabWidget;
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 @@ class ElementPropertiesWidget : public PropertiesEditorWidget
private:
void buildGui();
void updateUi();
void addGeneralWidget();
QWidget *generalWidget();
signals:
@@ -50,10 +53,10 @@ class ElementPropertiesWidget : public PropertiesEditorWidget
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

View File

@@ -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),

View File

@@ -18,8 +18,9 @@
#ifndef LINKSINGLEELEMENTWIDGET_H
#define LINKSINGLEELEMENTWIDGET_H
#include "PropertiesEditor/propertieseditorwidget.h"
#include "element.h"
#include "abstractelementpropertieseditorwidget.h"
class Diagram;
class QLineEdit;
@@ -39,7 +40,7 @@ namespace Ui {
* 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 @@ class LinkSingleElementWidget : public PropertiesEditorWidget
///Attributes
private:
Ui::LinkSingleElementWidget *ui;
Element *m_element;
ElementSelectorWidget *esw_;
QList <Diagram *> diagram_list;
QWidget *unlink_widget;

View File

@@ -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 @@ void MasterPropertiesWidget::setElement(Element *element)
{
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();
}

View File

@@ -20,7 +20,7 @@
#include <QWidget>
#include <QHash>
#include "PropertiesEditor/propertieseditorwidget.h"
#include "abstractelementpropertieseditorwidget.h"
class QListWidgetItem;
class Element;
@@ -38,7 +38,7 @@ namespace Ui {
* This class embenddedthe undo/redo command when apply new connection.
*/
class MasterPropertiesWidget : public PropertiesEditorWidget
class MasterPropertiesWidget : public AbstractElementPropertiesEditorWidget
{
Q_OBJECT
@@ -62,7 +62,6 @@ class MasterPropertiesWidget : public PropertiesEditorWidget
private:
Ui::MasterPropertiesWidget *ui;
Element *m_element;
QHash <QListWidgetItem *, Element *> lwi_hash;
Element *m_showed_element;
QETProject *m_project;