[qet] [2706] remove undo stack by diagram, and add single undo stack for project |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2706
Author: blacksun
Date: 2014-01-05 16:00:46 +0100 (Sun, 05 Jan 2014)
Log Message:
-----------
remove undo stack by diagram, and add single undo stack for project
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/diagram.h
trunk/sources/diagramview.cpp
trunk/sources/projectview.cpp
trunk/sources/qetdiagrameditor.cpp
trunk/sources/qetdiagrameditor.h
trunk/sources/qetproject.cpp
trunk/sources/qetproject.h
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2014-01-04 16:27:07 UTC (rev 2705)
+++ trunk/sources/diagram.cpp 2014-01-05 15:00:46 UTC (rev 2706)
@@ -53,7 +53,6 @@
read_only_(false),
diagram_qet_version_(-1)
{
- undo_stack_ = new QUndoStack();
qgi_manager_ = new QGIManager(this);
setBackgroundBrush(Qt::white);
conductor_setter_ = new QGraphicsLineItem(0, 0);
@@ -83,8 +82,8 @@
Destructeur
*/
Diagram::~Diagram() {
- // suppression de la liste des annulations - l'undo stack fait appel au qgimanager pour supprimer certains elements
- delete undo_stack_;
+ // clear undo stack to prevent errors, because contains pointers to this diagram and is elements.
+ undoStack().clear();
// suppression du QGIManager - tous les elements qu'il connait sont supprimes
delete qgi_manager_;
// remove of conductor setter
@@ -651,7 +650,6 @@
void Diagram::write() {
qDebug() << qPrintable(QString("Diagram::write() : saving changes from diagram \"%1\" [%2]").arg(title()).arg(QET::pointerString(this)));
write(toXml().documentElement());
- undoStack().setClean();
}
/**
@@ -828,7 +826,7 @@
*/
void Diagram::diagramTextChanged(DiagramTextItem *text_item, const QString &old_text, const QString &new_text) {
if (!text_item) return;
- undo_stack_ -> push(new ChangeDiagramTextCommand(text_item, old_text, new_text));
+ undoStack().push(new ChangeDiagramTextCommand(text_item, old_text, new_text));
}
/**
Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h 2014-01-04 16:27:07 UTC (rev 2705)
+++ trunk/sources/diagram.h 2014-01-05 15:00:46 UTC (rev 2706)
@@ -25,6 +25,7 @@
#include "exportproperties.h"
#include "qgimanager.h"
#include "numerotationcontext.h"
+#include "qetproject.h"
class Conductor;
class CustomElement;
@@ -86,7 +87,6 @@
bool draw_grid_;
bool use_border_;
QGIManager *qgi_manager_;
- QUndoStack *undo_stack_;
bool draw_terminals_;
bool draw_colored_conductors_;
QDomDocument xml_document_;
@@ -323,7 +323,7 @@
/// @return the diagram undo stack
inline QUndoStack &Diagram::undoStack() {
- return(*undo_stack_);
+ return *(project()->undoStack());
}
/// @return the diagram graphics item manager
Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp 2014-01-04 16:27:07 UTC (rev 2705)
+++ trunk/sources/diagramview.cpp 2014-01-05 15:00:46 UTC (rev 2706)
@@ -88,7 +88,6 @@
connect(&(scene -> border_and_titleblock), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect()));
connect(&(scene -> border_and_titleblock), SIGNAL(displayChanged()), this, SLOT(adjustSceneRect()));
connect(&(scene -> border_and_titleblock), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle()));
- connect(&(scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
connect(diagram, SIGNAL(editElementRequired(ElementsLocation)), this, SIGNAL(editElementRequired(ElementsLocation)));
connect(diagram, SIGNAL(findElementRequired(ElementsLocation)), this, SIGNAL(findElementRequired(ElementsLocation)));
@@ -772,19 +771,7 @@
Met a jour le titre du widget
*/
void DiagramView::updateWindowTitle() {
- QString view_title(title());
-
- // verifie si le document a ete modifie
- bool modified_diagram = !(scene -> undoStack().isClean());
-
- // specifie le titre du widget
- setWindowTitle(view_title + " [*]");
- setWindowModified(modified_diagram);
-
- // emet le signal titleChanged en ajoutant manuellement [*] si le schema a ete modifie
- QString emitted_title = view_title;
- if (modified_diagram) emitted_title += " [*]";
- emit(titleChanged(this, emitted_title));
+ emit(titleChanged(this, title()));
}
/**
Modified: trunk/sources/projectview.cpp
===================================================================
--- trunk/sources/projectview.cpp 2014-01-04 16:27:07 UTC (rev 2705)
+++ trunk/sources/projectview.cpp 2014-01-05 15:00:46 UTC (rev 2706)
@@ -176,9 +176,9 @@
// - or specify what is to be saved, i.e. they choose whether they wants to
// save/give up/remove diagrams considered as modified.
int user_input = tryClosingDiagrams();
- if (user_input == QDialogButtonBox::RejectRole) {
+ if (user_input == QMessageBox::Cancel) {
return(false); // the closing process was cancelled
- } else if (user_input == QDialogButtonBox::DestructiveRole) {
+ } else if (user_input == QMessageBox::Discard) {
return(true); // all modifications were discarded
}
@@ -222,55 +222,34 @@
}
/**
- Un projet comporte 0 a n schemas.
- Cette methode parcourt les schemas et demande a l'utilisateur s'il veut
- enregistrer les schemas modifies afin de les fermer. L'utilisateur peut
- refuser la fermeture d'un schema.
- Si un schema a ete ajoute sans jamais etre modifie, cette methode demande a
- l'utilisateur s'il souhaite l'enlever.
- @return true si tous les schemas peuvent etre fermes, false sinon
-*/
+ * @brief ProjectView::tryClosingDiagrams
+ * try to close this project, if diagram or project option are changed
+ * a dialog ask if user want to save the modification.
+ * @return the answer of dialog or discard if no change.
+ */
int ProjectView::tryClosingDiagrams() {
- if (!project_) return(QDialogButtonBox::DestructiveRole);
-
- bool project_modified = project_ -> projectOptionsWereModified();
- QList<Diagram *> modified_diagrams = getDiagrams(AllDiagrams | ModifiedDiagramsOnly);
- bool has_filepath = !project_ -> filePath().isEmpty();
- if (!project_modified && !modified_diagrams.count() && has_filepath) {
+ if (!project_) return(QMessageBox::Discard);
+
+ if (!project()->projectOptionsWereModified() &&
+ project()->undoStack()->isClean() &&
+ !project()->filePath().isEmpty()) {
// nothing was modified, and we have a filepath, i.e. everything was already
// saved, i.e we can close the project right now
- return(QDialogButtonBox::DestructiveRole);
+ return(QMessageBox::Discard);
}
-
- CloseDiagramsDialog close_dialog(modified_diagrams, this);
- if (!project_ -> title().isEmpty()) {
- close_dialog.setWindowTitle(
- QString(
- tr(
- "Fermer le projet \"%1\"",
- "project closing dialog title -- %1 is a project title"
- )
- ).arg(project_ -> title())
- );
+
+ int close_dialog = QMessageBox::question(this, project()->title(),
+ tr("Le projet \340 \351t\351 modifi\351.\n"
+ "Voulez-vous enregistrer les modifications ?"),
+ QMessageBox::Save | QMessageBox::Discard
+ | QMessageBox::Cancel,
+ QMessageBox::Save);
+
+ if (close_dialog == QMessageBox::Save) {
+ saveDiagrams(project()->diagrams());
}
- connect(&close_dialog, SIGNAL(showDiagram(Diagram*)), this, SLOT(showDiagram(Diagram*)));
- if (close_dialog.exec() == QDialog::Rejected) {
- return(QDialogButtonBox::RejectRole);
- }
- if (close_dialog.answer() == QDialogButtonBox::AcceptRole) {
- // save diagrams the user marked as to be saved
- QList<Diagram *> to_save = close_dialog.diagramsByAction(CloseDiagramsDialog::Save);
- saveDiagrams(to_save);
-
- // remove diagrams the user marked as to be removed
- QList<Diagram *> to_close = close_dialog.diagramsByAction(CloseDiagramsDialog::Remove);
- foreach (Diagram *diagram, to_close) {
- removeDiagram(diagram);
- }
- }
-
- return(close_dialog.answer());
+ return(close_dialog);
}
/**
@@ -558,7 +537,7 @@
@return a QETResult object reflecting the situation
*/
QETResult ProjectView::save() {
- return(doSave(AllDiagrams | ModifiedDiagramsOnly));
+ return(doSave(AllDiagrams));
}
/**
@@ -607,6 +586,7 @@
// write to file
QETResult result = project_ -> write();
updateWindowTitle();
+ if (options == AllDiagrams) project()->undoStack()->clear();
return(result);
}
Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp 2014-01-04 16:27:07 UTC (rev 2705)
+++ trunk/sources/qetdiagrameditor.cpp 2014-01-05 15:00:46 UTC (rev 2706)
@@ -119,7 +119,7 @@
// connexions signaux / slots pour une interface sensee
connect(&workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(slot_updateWindowsMenu()));
- connect(&workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(slot_updateActions()));
+ connect(&workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(slot_updateUndoStack()));
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slot_updatePasteAction()));
// lecture des parametres
@@ -1158,24 +1158,25 @@
prj_nomenclature -> setVisible(false);
#endif
- // affiche les actions correspondant au diagram view en cours
- if (dv) {
- if (can_update_actions) {
- undo_group.setActiveStack(&(dv -> diagram() -> undoStack()));
- undo -> setEnabled(undo_group.canUndo());
- redo -> setEnabled(undo_group.canRedo());
- }
- } else {
- undo -> setEnabled(false);
- redo -> setEnabled(false);
- }
-
slot_updateModeActions();
slot_updatePasteAction();
slot_updateComplexActions();
}
/**
+ * @brief QETDiagramEditor::slot_updateUndoStack
+ * Update the undo stack view
+ */
+void QETDiagramEditor::slot_updateUndoStack() {
+ ProjectView *pv = currentProject();
+ if (pv && can_update_actions) {
+ undo_group.setActiveStack(pv->project()->undoStack());
+ undo -> setEnabled(undo_group.canUndo());
+ redo -> setEnabled(undo_group.canRedo());
+ }
+}
+
+/**
gere les actions ayant des besoins precis pour etre active ou non
Cette methode ne fait rien si aucun document n'est ouvert
*/
@@ -1821,6 +1822,7 @@
void QETDiagramEditor::diagramWasRemoved(DiagramView *dv) {
Q_UNUSED(dv);
can_update_actions = true;
+ slot_updateUndoStack();
}
/**
Modified: trunk/sources/qetdiagrameditor.h
===================================================================
--- trunk/sources/qetdiagrameditor.h 2014-01-04 16:27:07 UTC (rev 2705)
+++ trunk/sources/qetdiagrameditor.h 2014-01-05 15:00:46 UTC (rev 2706)
@@ -111,6 +111,7 @@
void slot_setSelectionMode();
void slot_setVisualisationMode();
void slot_updateActions();
+ void slot_updateUndoStack();
void slot_updateModeActions();
void slot_updateComplexActions();
void slot_updatePasteAction();
Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp 2014-01-04 16:27:07 UTC (rev 2705)
+++ trunk/sources/qetproject.cpp 2014-01-05 15:00:46 UTC (rev 2706)
@@ -62,6 +62,9 @@
// une categorie dediee aux elements integres automatiquement
ensureIntegrationCategoryExists();
setupTitleBlockTemplatesCollection();
+
+ undo_stack_ = new QUndoStack();
+ connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool)));
}
/**
@@ -102,6 +105,9 @@
if (!project_file_info.isWritable()) {
setReadOnly(true);
}
+
+ undo_stack_ = new QUndoStack();
+ connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool)));
}
/**
@@ -123,6 +129,9 @@
readProjectXml();
setupTitleBlockTemplatesCollection();
+
+ undo_stack_ = new QUndoStack();
+ connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool)));
}
/**
@@ -145,6 +154,7 @@
delete diagram;
}
// qDebug() << diagrams_;
+ delete undo_stack_;
}
/**
Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h 2014-01-04 16:27:07 UTC (rev 2705)
+++ trunk/sources/qetproject.h 2014-01-05 15:00:46 UTC (rev 2706)
@@ -118,6 +118,7 @@
bool diagramsWereModified();
DiagramContext projectProperties();
void setProjectProperties(const DiagramContext &);
+ QUndoStack* undoStack() {return undo_stack_;}
public slots:
void componentWritten();
@@ -143,6 +144,7 @@
void updateDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
void removeDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
void usedTitleBlockTemplateChanged(const QString &);
+ void undoStackChanged (bool a) {if (!a) setModified(true);}
private:
void setupTitleBlockTemplatesCollection();
@@ -193,6 +195,8 @@
TitleBlockTemplatesProjectCollection titleblocks_;
/// project-wide variables that will be made available to child diagrams
DiagramContext project_properties_;
+ /// undo stack for this project
+ QUndoStack *undo_stack_;
};
Q_DECLARE_METATYPE(QETProject *)
#endif