Refactor some properties dialog.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4027 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-06-23 20:40:05 +00:00
parent 55e013f3e0
commit 3c21364d5e
13 changed files with 112 additions and 317 deletions

View File

@@ -3,7 +3,8 @@ FORMS += \
HEADERS += \
$$PWD/propertieseditordockwidget.h \
$$PWD/propertieseditorwidget.h
$$PWD/propertieseditorwidget.h \
$$PWD/propertieseditordialog.h
SOURCES += \
$$PWD/propertieseditordockwidget.cpp \

View File

@@ -0,0 +1,80 @@
/*
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 PROPERTIESEDITORDIALOG_H
#define PROPERTIESEDITORDIALOG_H
#include <QDialog>
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <QAbstractButton>
/**
* @brief The PropertiesEditorDialog class
* Create a dialog to edit some properties of a thing.
* Only create a instance of this class and call exec, all is done for you in this class.
* The first argument (a template) must be a subclass of QWidget and provide the 3 methods bellow :
* QString::title()
* void::apply()
* void::reset()
* You can subclass the interface PropertiesEditorWidget who provide all this methods.
* This dialog take ownership of the editor, so the editor will be deleted by this dialog
*/
class PropertiesEditorDialog : public QDialog
{
Q_OBJECT
public:
template<typename T>
PropertiesEditorDialog(T editor, QWidget *parent = 0) :
QDialog (parent)
{
//Set dialog title
setWindowTitle(editor->title());
//Reparent the editor, to be deleted at the same time of this dialog
editor->setParent(this);
//Build the dialog
QVBoxLayout *vlayout = new QVBoxLayout(this);
vlayout->addWidget(editor);
QDialogButtonBox *button_box = new QDialogButtonBox (QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, this);
vlayout->addWidget(button_box);
//Setup connection between button box and the editor
connect(button_box, &QDialogButtonBox::clicked, [editor, button_box, this](QAbstractButton *button)
{
switch(button_box->buttonRole(button))
{
case QDialogButtonBox::RejectRole:
editor->reset();
this->reject();
break;
case QDialogButtonBox::ResetRole:
editor->reset();
break;
case QDialogButtonBox::ApplyRole:
editor->apply();
this->accept();
break;
default:
editor->reset();
this->reject();
}
});
}
};
#endif // PROPERTIESEDITORDIALOG_H

View File

@@ -17,7 +17,8 @@
*/
#include "diagramimageitem.h"
#include "diagram.h"
#include "imagepropertiesdialog.h"
#include "PropertiesEditor/propertieseditordialog.h"
#include "imagepropertieswidget.h"
/**
* @brief DiagramImageItem::DiagramImageItem
@@ -85,7 +86,7 @@ void DiagramImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
void DiagramImageItem::editProperty()
{
if (diagram() -> isReadOnly()) return;
ImagePropertiesDialog dialog(this, QApplication::activeWindow());
PropertiesEditorDialog dialog(new ImagePropertiesWidget(this), QApplication::activeWindow());
dialog.exec();
}

View File

@@ -22,10 +22,11 @@
#include "elementtextitem.h"
#include "diagramcommands.h"
#include <QtDebug>
#include <elementpropertiesdialog.h>
#include "elementprovider.h"
#include "diagramposition.h"
#include "terminal.h"
#include "PropertiesEditor/propertieseditordialog.h"
#include "elementpropertieswidget.h"
/**
Constructeur pour un element sans scene ni parent
@@ -48,13 +49,14 @@ Element::Element(QGraphicsItem *parent) :
Element::~Element() {
}
void Element::editProperty() {
if (diagram())
if(!diagram()->isReadOnly()){
ElementPropertiesDialog epw (this, diagram()->views().first());
connect(&epw, SIGNAL(editElementRequired(ElementsLocation)), diagram(), SIGNAL(editElementRequired(ElementsLocation)));
connect(&epw, SIGNAL(findElementRequired(ElementsLocation)), diagram(), SIGNAL(findElementRequired(ElementsLocation)));
epw.exec();
void Element::editProperty()
{
if (diagram() && !diagram()->isReadOnly())
{
ElementPropertiesWidget *epw = new ElementPropertiesWidget(this);
PropertiesEditorDialog dialog(epw, QApplication::activeWindow());
connect(epw, &ElementPropertiesWidget::findEditClicked, &dialog, &QDialog::reject);
dialog.exec();
}
}

View File

@@ -20,6 +20,7 @@
#include "diagram.h"
#include "qet.h"
#include "shapegraphicsitempropertieswidget.h"
#include "PropertiesEditor/propertieseditordialog.h"
/**
@@ -359,24 +360,8 @@ void QetShapeItem::editProperty()
{
if (diagram() -> isReadOnly()) return;
//the dialog
QDialog property_dialog(diagram()->views().at(0));
property_dialog.setWindowTitle(tr("Éditer les propriétés d'une shape, Zone ", "window title"));
//the main layout
QVBoxLayout dialog_layout(&property_dialog);
ShapeGraphicsItemPropertiesWidget *sgipw = new ShapeGraphicsItemPropertiesWidget(this, &property_dialog);
dialog_layout.addWidget(sgipw);
//dialog button, box
QDialogButtonBox dbb(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog_layout.addWidget(&dbb);
connect(&dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept()));
connect(&dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject()));
if (property_dialog.exec() == QDialog::Accepted)
sgipw->apply();
else
sgipw->reset();
PropertiesEditorDialog ped(new ShapeGraphicsItemPropertiesWidget(this), diagram()->views().at(0));
ped.exec();
}
/**

View File

@@ -98,10 +98,7 @@ void DiagramPropertiesEditorDockWidget::selectionChanged()
clear();
m_edited_qgi_type = type_;
ElementPropertiesWidget *epw = new ElementPropertiesWidget(static_cast<Element*>(item), this);
connect (epw, &ElementPropertiesWidget::editElementRequired , m_diagram, &Diagram::editElementRequired);
connect (epw, &ElementPropertiesWidget::findElementRequired, m_diagram, &Diagram::findElementRequired);
addEditor(epw);
addEditor(new ElementPropertiesWidget(static_cast<Element*>(item), this));
break; }
case DiagramImageItem::Type: {

View File

@@ -1,90 +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 "elementpropertiesdialog.h"
#include "elementpropertieswidget.h"
#include <QDialogButtonBox>
#include <QVBoxLayout>
/**
* @brief ElementPropertiesDialog::ElementPropertiesDialog
* default constructor
* @param elmt
* @param parent
*/
ElementPropertiesDialog::ElementPropertiesDialog(Element *elmt, QWidget *parent) :
QDialog(parent),
element_ (elmt)
{
m_editor = new ElementPropertiesWidget(elmt, this);
connect(m_editor, SIGNAL(editElementRequired(ElementsLocation)), this , SLOT(editElement(ElementsLocation)));
connect(m_editor, SIGNAL(findElementRequired(ElementsLocation)), this, SLOT(findInPanel(ElementsLocation)));
dbb = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, Qt::Horizontal, this);
connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(standardButtonClicked(QAbstractButton*)));
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout -> addWidget(m_editor);
main_layout -> addWidget(dbb);
setLayout(main_layout);
}
/**
* @brief ElementPropertiesDialog::standardButtonClicked
* apply action when click in the dialog standard button box
* @param button
* the cliked button
*/
void ElementPropertiesDialog::standardButtonClicked(QAbstractButton *button) {
int answer = dbb -> buttonRole(button);
switch (answer) {
case QDialogButtonBox::ResetRole:
m_editor->reset();
break;
case QDialogButtonBox::ApplyRole:
m_editor->apply();
accept();
break;
default:
reject();
break;
}
}
/**
* @brief ElementPropertiesDialog::findInPanel
* Slot
*/
void ElementPropertiesDialog::findInPanel(const ElementsLocation &location)
{
emit findElementRequired(location);
reject();
}
/**
* @brief ElementPropertiesDialog::editElement
* Slot
*/
void ElementPropertiesDialog::editElement(const ElementsLocation &location)
{
emit findElementRequired(location);
emit editElementRequired(location);
reject();
}

View File

@@ -1,57 +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/>.
*/
#ifndef ELEMENTPROPERTIESDIALOG_H
#define ELEMENTPROPERTIESDIALOG_H
#include <QDialog>
class Element;
class ElementsLocation;
class QAbstractButton;
class QDialogButtonBox;
class ElementPropertiesWidget;
/**
* @brief The ElementPropertiesDialog class
* Display the element properties widget in a QDialog
*/
class ElementPropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit ElementPropertiesDialog(Element *elmt, QWidget *parent = 0);
signals:
/// Signal emitted when users wish to locate an element from the diagram within elements collection
void findElementRequired(const ElementsLocation &);
/// Signal emitted when users wish to edit an element from the diagram
void editElementRequired(const ElementsLocation &);
public slots:
void standardButtonClicked (QAbstractButton *);
void findInPanel (const ElementsLocation &);
void editElement (const ElementsLocation &);
private:
Element *element_;
QDialogButtonBox *dbb;
ElementPropertiesWidget *m_editor;
};
#endif // ELEMENTPROPERTIESDIALOG_H

View File

@@ -124,8 +124,12 @@ bool ElementPropertiesWidget::setLiveEdit(bool live_edit)
*/
void ElementPropertiesWidget::findInPanel()
{
if (CustomElement *custom_element = qobject_cast<CustomElement *>(m_element))
emit findElementRequired(custom_element->location());
CustomElement *custom_element = qobject_cast<CustomElement *>(m_element);
if (custom_element && m_diagram)
{
m_diagram->findElementRequired(custom_element->location());
emit findEditClicked();
}
}
/**
@@ -134,10 +138,12 @@ void ElementPropertiesWidget::findInPanel()
*/
void ElementPropertiesWidget::editElement()
{
if (CustomElement *custom_element = qobject_cast<CustomElement *>(m_element))
CustomElement *custom_element = qobject_cast<CustomElement *>(m_element);
if (custom_element && m_diagram)
{
emit findElementRequired(custom_element->location());
emit editElementRequired(custom_element->location());
m_diagram->findElementRequired(custom_element->location());
m_diagram->editElementRequired(custom_element->location());
emit findEditClicked();
}
}

View File

@@ -48,10 +48,7 @@ class ElementPropertiesWidget : public AbstractElementPropertiesEditorWidget
QWidget *generalWidget();
signals:
/// Signal emitted when users wish to locate an element from the diagram within elements collection
void findElementRequired(const ElementsLocation &);
/// Signal emitted when users wish to edit an element from the diagram
void editElementRequired(const ElementsLocation &);
void findEditClicked();
private:
Diagram *m_diagram;

View File

@@ -1,29 +0,0 @@
#include "imagepropertiesdialog.h"
#include "ui_imagepropertiesdialog.h"
#include "imagepropertieswidget.h"
#include "diagramimageitem.h"
ImagePropertiesDialog::ImagePropertiesDialog(DiagramImageItem *image, QWidget *parent) :
QDialog(parent),
ui(new Ui::ImagePropertiesDialog)
{
ui->setupUi(this);
m_editor = new ImagePropertiesWidget(image, this);
ui->verticalLayout->insertWidget(0, m_editor);
}
ImagePropertiesDialog::~ImagePropertiesDialog() {
delete ui;
}
void ImagePropertiesDialog::setImageItem(DiagramImageItem *image) {
m_editor->setImageItem(image);
}
void ImagePropertiesDialog::on_buttonBox_accepted() {
m_editor->apply();
}
void ImagePropertiesDialog::on_buttonBox_rejected() {
m_editor->reset();
}

View File

@@ -1,31 +0,0 @@
#ifndef IMAGEPROPERTIESDIALOG_H
#define IMAGEPROPERTIESDIALOG_H
#include <QDialog>
class ImagePropertiesWidget;
class DiagramImageItem;
namespace Ui {
class ImagePropertiesDialog;
}
class ImagePropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit ImagePropertiesDialog(DiagramImageItem *image = nullptr, QWidget *parent = 0);
~ImagePropertiesDialog();
void setImageItem (DiagramImageItem *image);
private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
Ui::ImagePropertiesDialog *ui;
ImagePropertiesWidget *m_editor;
};
#endif // IMAGEPROPERTIESDIALOG_H

View File

@@ -1,67 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImagePropertiesDialog</class>
<widget class="QDialog" name="ImagePropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>194</width>
<height>52</height>
</rect>
</property>
<property name="windowTitle">
<string>Éditer les propriétés de image</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ImagePropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ImagePropertiesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>