Conductor autonumerotation: Remove one autonum per diagram and add global autonums for the project.

several diagram can share the same autonumerotation.
This is first step, need to be improved and readd some feature (disabled for first step).


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3239 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-07-31 10:02:33 +00:00
parent d1730f39bd
commit 6fce7010f8
23 changed files with 643 additions and 278 deletions

View File

@@ -0,0 +1,74 @@
/*
Copyright 2006-2014 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 "autonumselectorwidget.h"
#include "ui_autonumselectorwidget.h"
/**
* @brief AutonumSelectorWidget::AutonumSelectorWidget
* default constructor
* @param parent, parent widget
*/
AutonumSelectorWidget::AutonumSelectorWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::AutonumSelectorWidget)
{
ui->setupUi(this);
ui->m_edit_autonum_pb->setDisabled(true);
}
/**
* @brief AutonumSelectorWidget::AutonumSelectorWidget
* Constructor with texts to fill the combo box
* @param text, texts for fill the combo box
* @param parent, parent widget
*/
AutonumSelectorWidget::AutonumSelectorWidget(const QList <QString> &text, QWidget *parent) :
QWidget(parent),
ui(new Ui::AutonumSelectorWidget)
{
ui->setupUi(this);
ui -> m_available_autonum_cb -> addItems(text);
ui->m_edit_autonum_pb->setDisabled(true);
}
/**
* @brief AutonumSelectorWidget::~AutonumSelectorWidget
* Destructor
*/
AutonumSelectorWidget::~AutonumSelectorWidget()
{
delete ui;
}
/**
* @brief AutonumSelectorWidget::setCurrentItem
* Set the combo box current index by text.
* If text doesn't exist, set current index -1
* @param text, text of index
*/
void AutonumSelectorWidget::setCurrentItem(const QString &text) {
ui -> m_available_autonum_cb -> setCurrentIndex( ui -> m_available_autonum_cb -> findText(text));
}
/**
* @brief AutonumSelectorWidget::text
* @return the current displayed text
*/
QString AutonumSelectorWidget::text() const {
return ui -> m_available_autonum_cb -> currentText();
}

View File

@@ -0,0 +1,49 @@
/*
Copyright 2006-2014 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 AUTONUMSELECTORWIDGET_H
#define AUTONUMSELECTORWIDGET_H
#include <QWidget>
namespace Ui {
class AutonumSelectorWidget;
}
/**
* @brief The AutonumSelectorWidget class
* This widget show a combobox to select an autonum and a button to edit the autonum
* The combo box is empty and the button isn't linked with anything, it's the role of caller
* of this class to fill the combo box and edit the connection with the button.
*/
class AutonumSelectorWidget : public QWidget
{
Q_OBJECT
public:
explicit AutonumSelectorWidget(QWidget *parent = 0);
explicit AutonumSelectorWidget(const QList <QString> &text, QWidget *parent = 0);
~AutonumSelectorWidget();
void setCurrentItem (const QString &text);
QString text() const;
private:
Ui::AutonumSelectorWidget *ui;
};
#endif // AUTONUMSELECTORWIDGET_H

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AutonumSelectorWidget</class>
<widget class="QWidget" name="AutonumSelectorWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Autonumérotation :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_available_autonum_cb"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="m_edit_autonum_pb">
<property name="toolTip">
<string>éditer les numérotations</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../qelectrotech.qrc">
<normaloff>:/ico/16x16/configure.png</normaloff>:/ico/16x16/configure.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../qelectrotech.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -115,6 +115,10 @@ void ConductorPropertiesWidget::setReadOnly(const bool &ro) {
this->setDisabled(ro);
}
void ConductorPropertiesWidget::addAutonumWidget(QWidget *widget) {
ui->m_autonum_layout->addWidget(widget);
}
/**
* @brief ConductorPropertiesWidget::initWidget
*/

View File

@@ -40,6 +40,8 @@ class ConductorPropertiesWidget : public QWidget
ConductorProperties properties() const;
void setReadOnly(const bool &ro);
void addAutonumWidget (QWidget *widget);
private:
void initWidget();
void setConductorType(ConductorProperties::ConductorType type);

View File

@@ -57,7 +57,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Texte :</string>
<string>Texte par defaut :</string>
</property>
</widget>
</item>
@@ -83,6 +83,9 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="m_autonum_layout"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">

View File

@@ -20,6 +20,7 @@
#include "titleblockpropertieswidget.h"
#include "conductorpropertieswidget.h"
#include "diagramcommands.h"
#include "autonumselectorwidget.h"
/**
* @brief DiagramPropertiesDialog::DiagramPropertiesDialog
@@ -62,6 +63,11 @@ DiagramPropertiesDialog::DiagramPropertiesDialog(Diagram *diagram, QWidget *pare
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(conductors, this);
cpw -> setReadOnly(diagram_is_read_only);
//Conductor autonum
AutonumSelectorWidget *asw = new AutonumSelectorWidget(diagram -> project() -> conductorAutoNum().keys(), this);
asw -> setCurrentItem(diagram -> conductorsAutonumName());
cpw->addAutonumWidget(asw);
// Buttons
QDialogButtonBox boutons(diagram_is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(&boutons, SIGNAL(accepted()), this, SLOT(accept()));
@@ -70,7 +76,7 @@ DiagramPropertiesDialog::DiagramPropertiesDialog(Diagram *diagram, QWidget *pare
QGridLayout glayout(this);
glayout.addWidget(border_infos,0,0);
glayout.addWidget(titleblock_infos, 1, 0);
glayout.addWidget(cpw, 0, 1, 0 ,1, Qt::AlignTop);
glayout.addWidget(cpw, 0, 1, 0, 1, Qt::AlignTop);
glayout.addWidget(&boutons, 2, 1);
// if dialog is accepted
@@ -94,6 +100,11 @@ DiagramPropertiesDialog::DiagramPropertiesDialog(Diagram *diagram, QWidget *pare
/// TODO implement an undo command to allow the user to undo/redo this action
diagram -> defaultConductorProperties = new_conductors;
}
// Conductor autonum name
if (asw -> text() != diagram -> conductorsAutonumName()) {
diagram -> setConductorsAutonumName (asw -> text());
}
}
}

View File

@@ -18,7 +18,7 @@
#include "dialogautonum.h"
#include "ui_dialogautonum.h"
#include "conductorautonumerotation.h"
//#include "conductorautonumerotation.h"
#include "qetmessagebox.h"
#include "ui/selectautonumw.h"
@@ -34,7 +34,7 @@ DialogAutoNum::DialogAutoNum(Diagram *dg, QWidget *parent) :
{
ui -> setupUi(this);
ui -> configuration_layout -> addWidget (new SelectAutonumW(dg_ -> project() -> diagrams(), dg, ui -> configuration_tab));
ui -> configuration_layout -> addWidget (new SelectAutonumW());
dgselect_ = new diagramselection( dg_ -> project(), ui -> annotation_tab);
ui -> verticalLayout_Selection -> addWidget(dgselect_);
@@ -74,8 +74,8 @@ void DialogAutoNum::on_pushButton_delete_clicked() {
// if yes remove all
if( answer == QMessageBox::Yes) {
for(int i=0; i<listDiag.count(); i++){
ConductorAutoNumerotation can(listDiag.at(i));
can.removeNumOfDiagram();
/*ConductorAutoNumerotation can(listDiag.at(i));
can.removeNumOfDiagram();*/
}
}
}
@@ -107,8 +107,8 @@ void DialogAutoNum::on_pushButton_annotation_clicked(){
// if yes numerate all
if( answer == QMessageBox::Yes) {
foreach (Diagram *d, listDiag) {
ConductorAutoNumerotation can(d);
can.numerateDiagram();
/*ConductorAutoNumerotation can(d);
can.numerateDiagram();*/
}
}
}

View File

@@ -17,21 +17,27 @@
*/
#include "selectautonumw.h"
#include "ui_selectautonumw.h"
#include "diagram.h"
#include "numparteditorw.h"
#include <QMessageBox>
#include "qdebug.h"
/**
* Constructor
*/
SelectAutonumW::SelectAutonumW(const QList <Diagram *> &diagrams, Diagram *current_diagram ,QWidget *parent) :
SelectAutonumW::SelectAutonumW(QWidget *parent) :
QWidget(parent),
ui(new Ui::SelectAutonumW),
diagram_list(diagrams)
ui(new Ui::SelectAutonumW)
{
ui->setupUi(this);
setContext(NumerotationContext());
}
initDiagramChooser();
if (current_diagram) ui -> diagram_chooser -> setCurrentIndex (diagram_list.indexOf(current_diagram));
setCurrentContext();
SelectAutonumW::SelectAutonumW(const NumerotationContext &context, QWidget *parent) :
QWidget(parent),
ui(new Ui::SelectAutonumW)
{
ui->setupUi(this);
setContext(context);
}
/**
@@ -42,36 +48,32 @@ SelectAutonumW::~SelectAutonumW()
delete ui;
}
/**
* @brief SelectAutonumW::setDiagramChooser
* build the content of QComboBox @diagram_chooser.
*/
void SelectAutonumW::initDiagramChooser() {
for (int i=0; i<diagram_list.size(); ++i) {
QString diagram_title = diagram_list.at(i) -> title();
if (diagram_title.isEmpty()) diagram_title = (tr("Sch\351ma sans titre"));
ui -> diagram_chooser -> addItem(diagram_title);
}
}
/**
* @brief SelectAutonumW::setCurrentContext
* build the context of current diagram selected in the @diagram_chooser QcomboBox
*/
void SelectAutonumW::setCurrentContext() {
NumerotationContext nc = diagram_list.at(ui->diagram_chooser->currentIndex()) -> getNumerotation(Diagram::Conductors);
void SelectAutonumW::setContext(const NumerotationContext &context) {
m_context = context;
if (nc.size() == 0) { //@nc contain nothing, build a default numPartEditor
qDeleteAll(num_part_list_);
num_part_list_.clear();
if (m_context.size() == 0) { //@context contain nothing, build a default numPartEditor
on_add_button_clicked();
applyEnable(false);
return;
}
for (int i=0; i<nc.size(); ++i) { //build with the content of @nc
NumPartEditorW *part= new NumPartEditorW(nc, i, this);
connect (part, SIGNAL(changed()), this, SLOT(applyEnable()));
num_part_list_ << part;
ui -> editor_layout -> addWidget(part);
else {
for (int i=0; i<m_context.size(); ++i) { //build with the content of @context
NumPartEditorW *part= new NumPartEditorW(m_context, i, this);
connect (part, SIGNAL(changed()), this, SLOT(applyEnable()));
num_part_list_ << part;
ui -> editor_layout -> addWidget(part);
}
}
num_part_list_.size() == 1 ?
ui -> remove_button -> setDisabled(true):
ui -> remove_button -> setEnabled (true);
applyEnable(false);
}
@@ -95,6 +97,7 @@ void SelectAutonumW::on_add_button_clicked() {
connect (part, SIGNAL(changed()), this, SLOT(applyEnable()));
num_part_list_ << part;
ui -> editor_layout -> addWidget(part);
ui -> remove_button -> setEnabled(true);
}
/**
@@ -107,20 +110,13 @@ void SelectAutonumW::on_remove_button_clicked() {
NumPartEditorW *part = num_part_list_.takeLast();
disconnect(part, SIGNAL(changed()), this, SLOT(applyEnable()));
delete part;
if (num_part_list_.size() == 1) {
ui -> remove_button -> setDisabled(true);
}
}
applyEnable();
}
/**
* @brief SelectAutonumW::on_diagram_chooser_activated
* Action on diagram_chooser
*/
void SelectAutonumW::on_diagram_chooser_activated() {
foreach(NumPartEditorW *npew, num_part_list_) delete npew;
num_part_list_.clear();
setCurrentContext();
}
/**
* @brief SelectAutonumW::on_buttonBox_clicked
* Action on @buttonBox clicked
@@ -130,10 +126,9 @@ void SelectAutonumW::on_buttonBox_clicked(QAbstractButton *button) {
int answer = ui -> buttonBox -> buttonRole(button);
switch (answer) {
//reset the displayed context to default context of @diagram_chooser.
//Reset the curent context
case QDialogButtonBox::ResetRole:
on_diagram_chooser_activated();
applyEnable(false);
setContext(m_context);
break;
//help dialog
case QDialogButtonBox::HelpRole:
@@ -157,9 +152,8 @@ void SelectAutonumW::on_buttonBox_clicked(QAbstractButton *button) {
//apply the context in the diagram displayed by @diagram_chooser.
case QDialogButtonBox::ApplyRole:
NumerotationContext nc = toNumContext();
diagram_list.at(ui -> diagram_chooser -> currentIndex()) -> setNumerotation(Diagram::Conductors, nc);
applyEnable(false);
emit applyPressed();
break;
};
}

View File

@@ -19,8 +19,10 @@
#define SELECTAUTONUMW_H
#include <QWidget>
#include "diagram.h"
#include "ui/numparteditorw.h"
#include "numerotationcontext.h"
class NumPartEditorW;
class QAbstractButton;
namespace Ui {
class SelectAutonumW;
@@ -32,27 +34,28 @@ class SelectAutonumW : public QWidget
//METHODS
public:
explicit SelectAutonumW(const QList <Diagram *> &, Diagram * = 0, QWidget *parent = 0);
~SelectAutonumW();
private:
void initDiagramChooser();
void setCurrentContext ();
NumerotationContext toNumContext() const;
explicit SelectAutonumW(QWidget *parent = 0);
explicit SelectAutonumW(const NumerotationContext &context, QWidget *parent = 0);
~SelectAutonumW();
void setContext (const NumerotationContext &context);
NumerotationContext toNumContext() const;
signals:
void applyPressed();
//SLOT
private slots:
void on_add_button_clicked();
void on_remove_button_clicked();
void on_diagram_chooser_activated();
void on_buttonBox_clicked(QAbstractButton *);
void applyEnable (bool = true);
void on_add_button_clicked();
void on_remove_button_clicked();
void on_buttonBox_clicked(QAbstractButton *);
void applyEnable (bool = true);
//ATTRIBUTS
private:
Ui::SelectAutonumW *ui;
const QList <Diagram *> diagram_list;
QList <NumPartEditorW *> num_part_list_;
Ui::SelectAutonumW *ui;
QList <NumPartEditorW *> num_part_list_;
NumerotationContext m_context;
};
#endif // SELECTAUTONUMW_H

View File

@@ -13,84 +13,54 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Folio: </string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="diagram_chooser">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Choisir le folio&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="maxVisibleItems">
<number>5</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="remove_button">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Supprimer une variable de numérotation&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../qelectrotech.qrc">
<normaloff>:/ico/22x22/list-remove.png</normaloff>:/ico/22x22/list-remove.png</iconset>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="add_button">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Ajouter une variable de numérotation&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../qelectrotech.qrc">
<normaloff>:/ico/22x22/list-add.png</normaloff>:/ico/22x22/list-add.png</iconset>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="definition_groupe">
<property name="title">
<string>Définition</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="remove_button">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Supprimer une variable de numérotation&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../qelectrotech.qrc">
<normaloff>:/ico/22x22/list-remove.png</normaloff>:/ico/22x22/list-remove.png</iconset>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="add_button">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Ajouter une variable de numérotation&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../qelectrotech.qrc">
<normaloff>:/ico/22x22/list-add.png</normaloff>:/ico/22x22/list-add.png</iconset>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="editor_layout">
<property name="spacing">