diff --git a/sources/borderinset.cpp b/sources/borderinset.cpp index 661a7c8d0..d82360485 100644 --- a/sources/borderinset.cpp +++ b/sources/borderinset.cpp @@ -30,21 +30,15 @@ BorderInset::BorderInset(QObject *parent) : QObject(parent) { // dimensions par defaut du schema importBorder(QETDiagramEditor::defaultBorderProperties()); + // contenu par defaut du cartouche + importInset(QETDiagramEditor::defaultInsetProperties()); + // hauteur du cartouche inset_height = 50.0; display_inset = true; display_border = true; updateRectangles(); - - bi_author = QETApp::settings().value("diagrameditor/defaultauthor").toString(); - bi_title = QETApp::settings().value("diagrameditor/defaulttitle").toString(); - bi_folio = QETApp::settings().value("diagrameditor/defaultfolio").toString(); - bi_filename = QETApp::settings().value("diagrameditor/defaultfilename").toString(); - QString settings_date = QETApp::settings().value("diagrameditor/defaultdate").toString(); - if (settings_date == "now") bi_date = QDate::currentDate(); - else if (settings_date.isEmpty() || settings_date == "null") bi_date = QDate(); - else bi_date = QDate::fromString(settings_date, "yyyyMMdd"); } /** @@ -135,6 +129,42 @@ void BorderInset::importBorder(const BorderProperties &bp) { displayRows(bp.display_rows); } +/** + @param di true pour afficher le cartouche, false sinon +*/ +void BorderInset::displayInset(bool di) { + bool change = (di != display_inset); + display_inset = di; + if (change) emit(displayChanged()); +} + +/** + @param dc true pour afficher les entetes des colonnes, false sinon +*/ +void BorderInset::displayColumns(bool dc) { + bool change = (dc != display_columns); + display_columns = dc; + if (change) emit(displayChanged()); +} + +/** + @param dr true pour afficher les entetes des lignes, false sinon +*/ +void BorderInset::displayRows(bool dr) { + bool change = (dr != display_rows); + display_rows = dr; + if (change) emit(displayChanged()); +} + +/** + @param db true pour afficher la bordure du schema, false sinon +*/ +void BorderInset::displayBorder(bool db) { + bool change = (db != display_border); + display_border = db; + if (change) emit(displayChanged()); +} + /** Methode recalculant les rectangles composant le cadre et le cartouche en fonction des attributs de taille diff --git a/sources/borderinset.h b/sources/borderinset.h index edb0b9040..93d3cb2d8 100644 --- a/sources/borderinset.h +++ b/sources/borderinset.h @@ -142,14 +142,10 @@ class BorderInset : public QObject { void importBorder(const BorderProperties &); // methodes d'acces en ecriture aux options - /// @param di true pour afficher le cartouche, false sinon - void displayInset (bool di) { display_inset = di; } - /// @param dc true pour afficher les entetes des colonnes, false sinon - void displayColumns (bool dc) { display_columns = dc; } - /// @param dr true pour afficher les entetes des lignes, false sinon - void displayRows (bool dr) { display_rows = dr; } - /// @param db true pour afficher la bordure du schema, false sinon - void displayBorder (bool db) { display_border = db; } + void displayInset(bool); + void displayColumns(bool); + void displayRows(bool); + void displayBorder(bool); private: void updateRectangles(); @@ -163,6 +159,10 @@ class BorderInset : public QObject { @param new_border Nouvelle bordure */ void borderChanged(QRectF old_border, QRectF new_border); + /** + Signal emise lorsque des options d'affichage change + */ + void displayChanged(); // attributs private: diff --git a/sources/borderpropertieswidget.cpp b/sources/borderpropertieswidget.cpp index cf1b23d4b..c25e7b695 100644 --- a/sources/borderpropertieswidget.cpp +++ b/sources/borderpropertieswidget.cpp @@ -43,10 +43,12 @@ BorderPropertiesWidget::~BorderPropertiesWidget() { @return the border properties edited and modified by */ const BorderProperties &BorderPropertiesWidget::borderProperties() { - border_.columns_count = columns_count -> value(); - border_.columns_width = columns_width -> value(); - border_.rows_count = rows_count -> value(); - border_.rows_height = rows_height -> value(); + border_.columns_count = columns_count -> value(); + border_.columns_width = columns_width -> value(); + border_.display_columns = display_columns -> isChecked(); + border_.rows_count = rows_count -> value(); + border_.rows_height = rows_height -> value(); + border_.display_rows = display_rows -> isChecked(); return(border_); } @@ -56,10 +58,12 @@ const BorderProperties &BorderPropertiesWidget::borderProperties() { */ void BorderPropertiesWidget::setEditedBorder(const BorderProperties &bp) { border_ = bp; - columns_count -> setValue(border_.columns_count); - columns_width -> setValue(border_.columns_width); - rows_count -> setValue(border_.rows_count); - rows_height -> setValue(border_.rows_height); + columns_count -> setValue(border_.columns_count); + columns_width -> setValue(border_.columns_width); + display_columns -> setChecked(border_.display_columns); + rows_count -> setValue(border_.rows_count); + rows_height -> setValue(border_.rows_height); + display_rows -> setChecked(border_.display_rows); } /** @@ -84,6 +88,8 @@ void BorderPropertiesWidget::build() { columns_width -> setPrefix(tr("\327")); columns_width -> setSuffix(tr("px")); + display_columns = new QCheckBox(tr("Afficher les en-têtes"), diagram_size_box); + // lignes : nombre et largeur QLabel *ds2 = new QLabel(tr("Lignes :")); @@ -96,13 +102,17 @@ void BorderPropertiesWidget::build() { rows_height -> setPrefix(tr("\327")); rows_height -> setSuffix(tr("px")); + display_rows = new QCheckBox(tr("Afficher les en-têtes"), diagram_size_box); + // layout diagram_size_box_layout -> addWidget(ds1, 0, 0); diagram_size_box_layout -> addWidget(columns_count, 0, 1); diagram_size_box_layout -> addWidget(columns_width, 0, 2); + diagram_size_box_layout -> addWidget(display_columns,0, 3); diagram_size_box_layout -> addWidget(ds2, 1, 0); diagram_size_box_layout -> addWidget(rows_count, 1, 1); diagram_size_box_layout -> addWidget(rows_height, 1, 2); + diagram_size_box_layout -> addWidget(display_rows, 1, 3); widget_layout -> addWidget(diagram_size_box); setLayout(widget_layout); diff --git a/sources/borderpropertieswidget.h b/sources/borderpropertieswidget.h index 5ed59be33..87c1834b8 100644 --- a/sources/borderpropertieswidget.h +++ b/sources/borderpropertieswidget.h @@ -19,6 +19,7 @@ #define BORDER_PROPERTIES_WIDGET_H #include #include "borderproperties.h" +class QCheckBox; class QSpinBox; /** Cette classe represente un widget permettant d'editer les dimensions et les @@ -48,7 +49,9 @@ class BorderPropertiesWidget : public QWidget { BorderProperties border_; ///< Proprietes editees QSpinBox *columns_count; ///< Widget d'edition du nombre de colonnes QSpinBox *columns_width; ///< Widget d'edition de la largeur des colonnes + QCheckBox *display_columns; ///< Case a cocher pour afficher ou non les entetes des colonnes QSpinBox *rows_count; ///< Widget d'edition du nombre de lignes QSpinBox *rows_height; ///< Widget d'edition de la hauteur des lignes + QCheckBox *display_rows; ///< Case a cocher pour afficher ou non les entetes des lignes }; #endif diff --git a/sources/configpages.cpp b/sources/configpages.cpp index c3669970f..02a9f6d9e 100644 --- a/sources/configpages.cpp +++ b/sources/configpages.cpp @@ -79,10 +79,12 @@ void NewDiagramPage::applyConf() { // dimensions des nouveaux schemas BorderProperties border = bpw -> borderProperties(); - settings.setValue("diagrameditor/defaultcols", border.columns_count); - settings.setValue("diagrameditor/defaultcolsize", border.columns_width); - settings.setValue("diagrameditor/defaultrows", border.rows_count); - settings.setValue("diagrameditor/defaultrowsize", border.rows_height); + settings.setValue("diagrameditor/defaultcols", border.columns_count); + settings.setValue("diagrameditor/defaultcolsize", border.columns_width); + settings.setValue("diagrameditor/defaultdisplaycols", border.display_columns); + settings.setValue("diagrameditor/defaultrows", border.rows_count); + settings.setValue("diagrameditor/defaultrowsize", border.rows_height); + settings.setValue("diagrameditor/defaultdisplayrows", border.display_rows); // proprietes du cartouche InsetProperties inset = ipw-> insetProperties(); diff --git a/sources/diagram.cpp b/sources/diagram.cpp index bffd0e606..55e3cfc52 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -253,6 +253,8 @@ QDomDocument Diagram::toXml(bool diagram) { racine.setAttribute("rowsize", border_and_inset.rowsHeight()); // attribut datant de la version 0.1 - laisse pour retrocompatibilite racine.setAttribute("height", border_and_inset.diagramHeight()); + racine.setAttribute("displaycols", border_and_inset.columnsAreDisplayed() ? "true" : "false"); + racine.setAttribute("displayrows", border_and_inset.rowsAreDisplayed() ? "true" : "false"); // type de conducteur par defaut QDomElement default_conductor = document.createElement("defaultconductor"); @@ -371,6 +373,10 @@ bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_in if (ok) border_and_inset.setDiagramHeight(height); } + // affichage des lignes et colonnes + border_and_inset.displayColumns(root.attribute("displaycols") != "false"); + border_and_inset.displayRows(root.attribute("displayrows") != "false"); + border_and_inset.adjustInsetToColumns(); // repere le permier element "defaultconductor" diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index 21f6c7811..21ef2d70f 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -536,15 +536,11 @@ void ChangeInsetCommand::redo() { @param dia Schema modifie @param parent QUndoCommand parent */ -ChangeBorderCommand::ChangeBorderCommand(Diagram *dia, QUndoCommand *parent) : +ChangeBorderCommand::ChangeBorderCommand(Diagram *dia, const BorderProperties &old_bp, const BorderProperties &new_bp, QUndoCommand *parent) : QUndoCommand(QObject::tr("modifier les dimensions du sch\351ma"), parent), diagram(dia), - columnsCountDifference(0), - rowsCountDifference(0), - columnsWidthDifference(0.0), - rowsHeightDifference(0.0), - headersHeightDifference(0.0), - headersWidthDifference(0.0) + old_properties(old_bp), + new_properties(new_bp) { } @@ -552,45 +548,14 @@ ChangeBorderCommand::ChangeBorderCommand(Diagram *dia, QUndoCommand *parent) : ChangeBorderCommand::~ChangeBorderCommand() { } -/** - Applique les changements au schema - @param coeff comme les changements s'expriment sous forme de nombres dont - il suffit d'inverser le signe pour les annuler, ces valeurs sont ici - multipliees par le coefficient passe en parametre avant d'etre appliquees. - Pour resumer : 1 pour refaire, -1 pour annuler. -*/ -void ChangeBorderCommand::applyChanges(int coeff) { - // reference vers l'objet border_and_inset du schema - BorderInset &border = diagram -> border_and_inset; - if (columnsCountDifference) { - border.setNbColumns(border.nbColumns() + (columnsCountDifference * coeff)); - } - if (rowsCountDifference) { - border.setNbRows(border.nbRows() + (rowsCountDifference * coeff)); - } - if (columnsWidthDifference) { - border.setColumnsWidth(border.columnsWidth() + (columnsWidthDifference * coeff)); - } - if (rowsHeightDifference) { - border.setRowsHeight(border.rowsHeight() + (rowsHeightDifference * coeff)); - } - if (headersHeightDifference) { - border.setColumnsHeaderHeight(border.columnsHeaderHeight() + (headersHeightDifference * coeff)); - } - if (headersWidthDifference) { - border.setRowsHeaderWidth(border.rowsHeaderWidth() + (headersWidthDifference * coeff)); - } - border.adjustInsetToColumns(); -} - /// Annule les changements apportes au schema void ChangeBorderCommand::undo() { - applyChanges(-1); + diagram -> border_and_inset.importBorder(old_properties); } /// Refait les changements apportes au schema void ChangeBorderCommand::redo() { - applyChanges(1); + diagram -> border_and_inset.importBorder(new_properties); } /** diff --git a/sources/diagramcommands.h b/sources/diagramcommands.h index ef3b51131..30af25dfa 100644 --- a/sources/diagramcommands.h +++ b/sources/diagramcommands.h @@ -22,7 +22,9 @@ #include "diagramcontent.h" #include "diagramtextitem.h" #include "conductor.h" +#include "borderproperties.h" #include "conductorproperties.h" +#include "insetproperties.h" #include /** Cette classe represente l'action d'ajouter un element au schema @@ -325,16 +327,12 @@ class ChangeInsetCommand : public QUndoCommand { }; /** - Cette classe represente l'action de modifier : - -le nombre de colonnes d'un schema - -la hauteur des colonnes - -la largeur des colonnes - -la hauteur des en-tetes des colonnes + Cette classe represente l'action de modifier les dimensions d'un schema */ class ChangeBorderCommand : public QUndoCommand { // constructeurs, destructeur public: - ChangeBorderCommand(Diagram *, QUndoCommand * = 0); + ChangeBorderCommand(Diagram *, const BorderProperties &, const BorderProperties &, QUndoCommand * = 0); virtual ~ChangeBorderCommand(); private: ChangeBorderCommand(const ChangeBorderCommand &); @@ -343,26 +341,16 @@ class ChangeBorderCommand : public QUndoCommand { public: virtual void undo(); virtual void redo(); - private: - virtual void applyChanges(int = 1); // attributs private: /// schema modifie Diagram *diagram; public: - /// nombre de colonnes ajoutees / enlevees - int columnsCountDifference; - /// nombre de lignes ajoutees / enlevees - int rowsCountDifference; - /// delta pour la largeur des colonnes - qreal columnsWidthDifference; - /// delta pour la hauteur des lignes - qreal rowsHeightDifference; - /// delta pour la hauteur des entetes des colonnes - qreal headersHeightDifference; - /// delta pour la largeur des entetes des lignes - qreal headersWidthDifference; + /// anciennes dimensions du schema + BorderProperties old_properties; + /// nouvelles dimensions du schema + BorderProperties new_properties; }; /** diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 940aabd79..7c6276786 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -58,6 +58,7 @@ DiagramView::DiagramView(QWidget *parent) : QGraphicsView(parent), is_adding_tex connect(scene, SIGNAL(selectionEmptinessChanged()), this, SIGNAL(selectionChanged())); connect(&(scene -> border_and_inset), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect())); + connect(&(scene -> border_and_inset), SIGNAL(displayChanged()), this, SLOT(adjustSceneRect())); connect(&(scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle())); } @@ -582,12 +583,7 @@ void DiagramView::dialogEditInfos() { // s'il y a des modifications aux dimensions du schema if (new_border != border) { - ChangeBorderCommand *cbc = new ChangeBorderCommand(scene); - cbc -> columnsCountDifference = new_border.columns_count - border.columns_count; - cbc -> columnsWidthDifference = new_border.columns_width - border.columns_width; - cbc -> rowsCountDifference = new_border.rows_count - border.rows_count; - cbc -> rowsHeightDifference = new_border.rows_height - border.rows_height; - scene -> undoStack().push(cbc); + scene -> undoStack().push(new ChangeBorderCommand(scene, border, new_border)); } } } @@ -603,36 +599,40 @@ bool DiagramView::hasSelectedItems() { Ajoute une colonne au schema. */ void DiagramView::addColumn() { - ChangeBorderCommand *cbc = new ChangeBorderCommand(scene); - cbc -> columnsCountDifference = 1; - scene -> undoStack().push(cbc); + BorderProperties old_bp = scene -> border_and_inset.exportBorder(); + BorderProperties new_bp = scene -> border_and_inset.exportBorder(); + new_bp.columns_count += 1; + scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp)); } /** Enleve une colonne au schema. */ void DiagramView::removeColumn() { - ChangeBorderCommand *cbc = new ChangeBorderCommand(scene); - cbc -> columnsCountDifference = -1; - scene -> undoStack().push(cbc); + BorderProperties old_bp = scene -> border_and_inset.exportBorder(); + BorderProperties new_bp = scene -> border_and_inset.exportBorder(); + new_bp.columns_count -= 1; + scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp)); } /** Agrandit le schema en hauteur */ void DiagramView::addRow() { - ChangeBorderCommand *cbc = new ChangeBorderCommand(scene); - cbc -> rowsCountDifference = 1; - scene -> undoStack().push(cbc); + BorderProperties old_bp = scene -> border_and_inset.exportBorder(); + BorderProperties new_bp = scene -> border_and_inset.exportBorder(); + new_bp.rows_count += 1; + scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp)); } /** Retrecit le schema en hauteur */ void DiagramView::removeRow() { - ChangeBorderCommand *cbc = new ChangeBorderCommand(scene); - cbc -> rowsCountDifference = -1; - scene -> undoStack().push(cbc); + BorderProperties old_bp = scene -> border_and_inset.exportBorder(); + BorderProperties new_bp = scene -> border_and_inset.exportBorder(); + new_bp.rows_count -= 1; + scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp)); } /** diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 00c8f43f3..15384f202 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1103,12 +1103,12 @@ BorderProperties QETDiagramEditor::defaultBorderProperties() { def.columns_count = settings.value("diagrameditor/defaultcols", 15).toInt(); def.columns_width = qRound(settings.value("diagrameditor/defaultcolsize", 50.0).toDouble()); def.columns_header_height = 20.0; - def.display_columns = true; + def.display_columns = settings.value("diagrameditor/defaultdisplaycols", true).toBool(); def.rows_count = settings.value("diagrameditor/defaultrows", 6).toInt(); def.rows_height = qRound(settings.value("diagrameditor/defaultrowsize", 80.0).toDouble()); def.rows_header_width = 20.0; - def.display_rows = true; + def.display_rows = settings.value("diagrameditor/defaultdisplayrows", true).toBool(); return(def); }