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,10 @@
FORMS += \
$$PWD/propertieseditordockwidget.ui
HEADERS += \
$$PWD/propertieseditordockwidget.h \
$$PWD/propertieseditorwidget.h
SOURCES += \
$$PWD/propertieseditordockwidget.cpp \
$$PWD/propertieseditorwidget.cpp

View File

@@ -0,0 +1,160 @@
/*
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 "propertieseditordockwidget.h"
#include "ui_propertieseditordockwidget.h"
#include "propertieseditorwidget.h"
#include <QAbstractButton>
/**
* @brief PropertiesEditorDockWidget::PropertiesEditorDockWidget
* Constructor
* @param parent : parent widget
*/
PropertiesEditorDockWidget::PropertiesEditorDockWidget(QWidget *parent) :
QDockWidget(parent),
ui(new Ui::PropertiesEditorDockWidget)
{
ui->setupUi(this);
ui->m_main_vlayout->setAlignment(ui->buttonBox, Qt::AlignBottom);
ui->buttonBox->setDisabled(true);
}
/**
* @brief PropertiesEditorDockWidget::~PropertiesEditorDockWidget
* Destructor
*/
PropertiesEditorDockWidget::~PropertiesEditorDockWidget()
{
clear();
delete ui;
}
/**
* @brief PropertiesEditorDockWidget::clear
* Remove all editor present in this dock and delete it.
* They also disabled the button box at the bottom of this dock
*/
void PropertiesEditorDockWidget::clear()
{
foreach (PropertiesEditorWidget *editor, m_editor_list)
{
m_editor_list.removeOne(editor);
ui->m_main_vlayout->removeWidget(editor);
editor->deleteLater();
}
m_editor_list.clear();
ui->buttonBox->setDisabled(true);
}
/**
* @brief PropertiesEditorDockWidget::apply
* Call the apply method for each editor present in this dock
*/
void PropertiesEditorDockWidget::apply()
{
foreach(PropertiesEditorWidget *editor, m_editor_list)
editor->apply();
}
/**
* @brief PropertiesEditorDockWidget::reset
* Call the reset method for each editor present in this widget
*/
void PropertiesEditorDockWidget::reset()
{
foreach(PropertiesEditorWidget *editor, m_editor_list)
editor->reset();
}
/**
* @brief PropertiesEditorDockWidget::addEditor
* Add an @editor in this dock at @index in the main vertical layout (note the button box
* are displayed at bottom of this layout by default)
* When an editor is added, we enable the button box
* @param editor : editor to add;
* @param index : index of editor in the layout
* @return true if was added (or already add) or false if can't be add (editor = nullptr)
*/
bool PropertiesEditorDockWidget::addEditor(PropertiesEditorWidget *editor, int index)
{
if (!editor) return false;
if (m_editor_list.contains(editor)) return true;
ui -> m_main_vlayout -> insertWidget(index, editor);
m_editor_list << editor;
setEnabledButtonBox(true);
return true;
}
/**
* @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
* @param editor : editor to remove
* @return true on success, else false
*/
bool PropertiesEditorDockWidget::removeEditor(PropertiesEditorWidget *editor)
{
bool result = m_editor_list.removeOne(editor);
if (result)
ui -> m_main_vlayout -> removeWidget(editor);
if (m_editor_list.isEmpty())
setDisabledButtonBox(true);
return result;
}
/**
* @brief PropertiesEditorDockWidget::setDisabledButtonBox
* Disabled the button box at bottom of dock
* @param b
*/
void PropertiesEditorDockWidget::setDisabledButtonBox(bool b) {
ui -> buttonBox -> setDisabled(b);
}
/**
* @brief PropertiesEditorDockWidget::setEnabledButtonBox
* Enabled button box at bottom of dock
* @param b
*/
void PropertiesEditorDockWidget::setEnabledButtonBox(bool b) {
ui -> buttonBox -> setEnabled(b);
}
/**
* @brief PropertiesEditorDockWidget::on_buttonBox_clicked
* Action when button box button is clciked.
* If button is ApplyRole : call the apply() method
* If button is ResetRole : call the reset() method
* @param button
*/
void PropertiesEditorDockWidget::on_buttonBox_clicked(QAbstractButton *button)
{
int answer = ui->buttonBox->buttonRole(button);
switch (answer)
{
case QDialogButtonBox::ApplyRole: apply(); break;
case QDialogButtonBox::ResetRole: reset(); break;
default: break;
}
}

View File

@@ -0,0 +1,57 @@
/*
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 SELECTIONPROPERTIESDOCKWIDGET_H
#define SELECTIONPROPERTIESDOCKWIDGET_H
#include <QDockWidget>
class PropertiesEditorWidget;
class QAbstractButton;
namespace Ui {
class PropertiesEditorDockWidget;
}
class PropertiesEditorDockWidget : public QDockWidget
{
Q_OBJECT
public:
explicit PropertiesEditorDockWidget(QWidget *parent = 0);
~PropertiesEditorDockWidget();
virtual void clear();
virtual void apply();
virtual void reset();
bool addEditor (PropertiesEditorWidget *editor, int index = 0);
bool removeEditor (PropertiesEditorWidget *editor);
void setDisabledButtonBox(bool b = true);
void setEnabledButtonBox (bool b = true);
private slots:
void on_buttonBox_clicked(QAbstractButton *button);
protected:
QList <PropertiesEditorWidget *> m_editor_list;
private:
Ui::PropertiesEditorDockWidget *ui;
};
#endif // SELECTIONPROPERTIESDOCKWIDGET_H

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PropertiesEditorDockWidget</class>
<widget class="QDockWidget" name="PropertiesEditorDockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Propriété de la séléction</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="m_main_vlayout">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::RestoreDefaults</set>
</property>
<property name="centerButtons">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,46 @@
/*
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();
}

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 PROPERTIESEDITORWIDGET_H
#define PROPERTIESEDITORWIDGET_H
#include <QWidget>
class QUndoCommand;
/**
* @brief The PropertiesEditorWidget class
* This class extend QWidget method for have common way
* to edit propertie.
*/
class PropertiesEditorWidget : public QWidget
{
Q_OBJECT
public:
explicit PropertiesEditorWidget(QWidget *parent = 0);
virtual void apply() {}
virtual void reset() {}
virtual QUndoCommand *associatedUndo () const;
virtual QString title() const;
};
#endif // PROPERTIESEDITORWIDGET_H