mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
remove undo stack by diagram, and add single undo stack for project
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2706 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -53,7 +53,6 @@ Diagram::Diagram(QObject *parent) :
|
|||||||
read_only_(false),
|
read_only_(false),
|
||||||
diagram_qet_version_(-1)
|
diagram_qet_version_(-1)
|
||||||
{
|
{
|
||||||
undo_stack_ = new QUndoStack();
|
|
||||||
qgi_manager_ = new QGIManager(this);
|
qgi_manager_ = new QGIManager(this);
|
||||||
setBackgroundBrush(Qt::white);
|
setBackgroundBrush(Qt::white);
|
||||||
conductor_setter_ = new QGraphicsLineItem(0, 0);
|
conductor_setter_ = new QGraphicsLineItem(0, 0);
|
||||||
@@ -83,8 +82,8 @@ Diagram::Diagram(QObject *parent) :
|
|||||||
Destructeur
|
Destructeur
|
||||||
*/
|
*/
|
||||||
Diagram::~Diagram() {
|
Diagram::~Diagram() {
|
||||||
// suppression de la liste des annulations - l'undo stack fait appel au qgimanager pour supprimer certains elements
|
// clear undo stack to prevent errors, because contains pointers to this diagram and is elements.
|
||||||
delete undo_stack_;
|
undoStack().clear();
|
||||||
// suppression du QGIManager - tous les elements qu'il connait sont supprimes
|
// suppression du QGIManager - tous les elements qu'il connait sont supprimes
|
||||||
delete qgi_manager_;
|
delete qgi_manager_;
|
||||||
// remove of conductor setter
|
// remove of conductor setter
|
||||||
@@ -651,7 +650,6 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
void Diagram::write() {
|
void Diagram::write() {
|
||||||
qDebug() << qPrintable(QString("Diagram::write() : saving changes from diagram \"%1\" [%2]").arg(title()).arg(QET::pointerString(this)));
|
qDebug() << qPrintable(QString("Diagram::write() : saving changes from diagram \"%1\" [%2]").arg(title()).arg(QET::pointerString(this)));
|
||||||
write(toXml().documentElement());
|
write(toXml().documentElement());
|
||||||
undoStack().setClean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -828,7 +826,7 @@ void Diagram::titleChanged(const QString &title) {
|
|||||||
*/
|
*/
|
||||||
void Diagram::diagramTextChanged(DiagramTextItem *text_item, const QString &old_text, const QString &new_text) {
|
void Diagram::diagramTextChanged(DiagramTextItem *text_item, const QString &old_text, const QString &new_text) {
|
||||||
if (!text_item) return;
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "exportproperties.h"
|
#include "exportproperties.h"
|
||||||
#include "qgimanager.h"
|
#include "qgimanager.h"
|
||||||
#include "numerotationcontext.h"
|
#include "numerotationcontext.h"
|
||||||
|
#include "qetproject.h"
|
||||||
|
|
||||||
class Conductor;
|
class Conductor;
|
||||||
class CustomElement;
|
class CustomElement;
|
||||||
@@ -86,7 +87,6 @@ class Diagram : public QGraphicsScene {
|
|||||||
bool draw_grid_;
|
bool draw_grid_;
|
||||||
bool use_border_;
|
bool use_border_;
|
||||||
QGIManager *qgi_manager_;
|
QGIManager *qgi_manager_;
|
||||||
QUndoStack *undo_stack_;
|
|
||||||
bool draw_terminals_;
|
bool draw_terminals_;
|
||||||
bool draw_colored_conductors_;
|
bool draw_colored_conductors_;
|
||||||
QDomDocument xml_document_;
|
QDomDocument xml_document_;
|
||||||
@@ -323,7 +323,7 @@ inline Diagram::BorderOptions Diagram::borderOptions() {
|
|||||||
|
|
||||||
/// @return the diagram undo stack
|
/// @return the diagram undo stack
|
||||||
inline QUndoStack &Diagram::undoStack() {
|
inline QUndoStack &Diagram::undoStack() {
|
||||||
return(*undo_stack_);
|
return *(project()->undoStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return the diagram graphics item manager
|
/// @return the diagram graphics item manager
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(pare
|
|||||||
connect(&(scene -> border_and_titleblock), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect()));
|
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(displayChanged()), this, SLOT(adjustSceneRect()));
|
||||||
connect(&(scene -> border_and_titleblock), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle()));
|
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(editElementRequired(ElementsLocation)), this, SIGNAL(editElementRequired(ElementsLocation)));
|
||||||
connect(diagram, SIGNAL(findElementRequired(ElementsLocation)), this, SIGNAL(findElementRequired(ElementsLocation)));
|
connect(diagram, SIGNAL(findElementRequired(ElementsLocation)), this, SIGNAL(findElementRequired(ElementsLocation)));
|
||||||
|
|
||||||
@@ -772,19 +771,7 @@ void DiagramView::adjustSceneRect() {
|
|||||||
Met a jour le titre du widget
|
Met a jour le titre du widget
|
||||||
*/
|
*/
|
||||||
void DiagramView::updateWindowTitle() {
|
void DiagramView::updateWindowTitle() {
|
||||||
QString view_title(title());
|
emit(titleChanged(this, 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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -176,9 +176,9 @@ bool ProjectView::tryClosing() {
|
|||||||
// - or specify what is to be saved, i.e. they choose whether they wants to
|
// - or specify what is to be saved, i.e. they choose whether they wants to
|
||||||
// save/give up/remove diagrams considered as modified.
|
// save/give up/remove diagrams considered as modified.
|
||||||
int user_input = tryClosingDiagrams();
|
int user_input = tryClosingDiagrams();
|
||||||
if (user_input == QDialogButtonBox::RejectRole) {
|
if (user_input == QMessageBox::Cancel) {
|
||||||
return(false); // the closing process was cancelled
|
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
|
return(true); // all modifications were discarded
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,55 +222,34 @@ bool ProjectView::tryClosingElementEditors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Un projet comporte 0 a n schemas.
|
* @brief ProjectView::tryClosingDiagrams
|
||||||
Cette methode parcourt les schemas et demande a l'utilisateur s'il veut
|
* try to close this project, if diagram or project option are changed
|
||||||
enregistrer les schemas modifies afin de les fermer. L'utilisateur peut
|
* a dialog ask if user want to save the modification.
|
||||||
refuser la fermeture d'un schema.
|
* @return the answer of dialog or discard if no change.
|
||||||
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
|
|
||||||
*/
|
|
||||||
int ProjectView::tryClosingDiagrams() {
|
int ProjectView::tryClosingDiagrams() {
|
||||||
if (!project_) return(QDialogButtonBox::DestructiveRole);
|
if (!project_) return(QMessageBox::Discard);
|
||||||
|
|
||||||
bool project_modified = project_ -> projectOptionsWereModified();
|
if (!project()->projectOptionsWereModified() &&
|
||||||
QList<Diagram *> modified_diagrams = getDiagrams(AllDiagrams | ModifiedDiagramsOnly);
|
project()->undoStack()->isClean() &&
|
||||||
bool has_filepath = !project_ -> filePath().isEmpty();
|
!project()->filePath().isEmpty()) {
|
||||||
if (!project_modified && !modified_diagrams.count() && has_filepath) {
|
|
||||||
// nothing was modified, and we have a filepath, i.e. everything was already
|
// nothing was modified, and we have a filepath, i.e. everything was already
|
||||||
// saved, i.e we can close the project right now
|
// saved, i.e we can close the project right now
|
||||||
return(QDialogButtonBox::DestructiveRole);
|
return(QMessageBox::Discard);
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseDiagramsDialog close_dialog(modified_diagrams, this);
|
return(close_dialog);
|
||||||
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())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -558,7 +537,7 @@ void ProjectView::exportProject() {
|
|||||||
@return a QETResult object reflecting the situation
|
@return a QETResult object reflecting the situation
|
||||||
*/
|
*/
|
||||||
QETResult ProjectView::save() {
|
QETResult ProjectView::save() {
|
||||||
return(doSave(AllDiagrams | ModifiedDiagramsOnly));
|
return(doSave(AllDiagrams));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -607,6 +586,7 @@ QETResult ProjectView::doSave(ProjectSaveOptions options) {
|
|||||||
// write to file
|
// write to file
|
||||||
QETResult result = project_ -> write();
|
QETResult result = project_ -> write();
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
|
if (options == AllDiagrams) project()->undoStack()->clear();
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) :
|
|||||||
|
|
||||||
// connexions signaux / slots pour une interface sensee
|
// connexions signaux / slots pour une interface sensee
|
||||||
connect(&workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(slot_updateWindowsMenu()));
|
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()));
|
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slot_updatePasteAction()));
|
||||||
|
|
||||||
// lecture des parametres
|
// lecture des parametres
|
||||||
@@ -1158,23 +1158,24 @@ void QETDiagramEditor::slot_updateActions() {
|
|||||||
prj_nomenclature -> setVisible(false);
|
prj_nomenclature -> setVisible(false);
|
||||||
#endif
|
#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_updateModeActions();
|
||||||
slot_updatePasteAction();
|
slot_updatePasteAction();
|
||||||
slot_updateComplexActions();
|
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
|
gere les actions ayant des besoins precis pour etre active ou non
|
||||||
Cette methode ne fait rien si aucun document n'est ouvert
|
Cette methode ne fait rien si aucun document n'est ouvert
|
||||||
@@ -1821,6 +1822,7 @@ void QETDiagramEditor::diagramIsAboutToBeRemoved(DiagramView *dv) {
|
|||||||
void QETDiagramEditor::diagramWasRemoved(DiagramView *dv) {
|
void QETDiagramEditor::diagramWasRemoved(DiagramView *dv) {
|
||||||
Q_UNUSED(dv);
|
Q_UNUSED(dv);
|
||||||
can_update_actions = true;
|
can_update_actions = true;
|
||||||
|
slot_updateUndoStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ class QETDiagramEditor : public QETMainWindow {
|
|||||||
void slot_setSelectionMode();
|
void slot_setSelectionMode();
|
||||||
void slot_setVisualisationMode();
|
void slot_setVisualisationMode();
|
||||||
void slot_updateActions();
|
void slot_updateActions();
|
||||||
|
void slot_updateUndoStack();
|
||||||
void slot_updateModeActions();
|
void slot_updateModeActions();
|
||||||
void slot_updateComplexActions();
|
void slot_updateComplexActions();
|
||||||
void slot_updatePasteAction();
|
void slot_updatePasteAction();
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ QETProject::QETProject(int diagrams, QObject *parent) :
|
|||||||
// une categorie dediee aux elements integres automatiquement
|
// une categorie dediee aux elements integres automatiquement
|
||||||
ensureIntegrationCategoryExists();
|
ensureIntegrationCategoryExists();
|
||||||
setupTitleBlockTemplatesCollection();
|
setupTitleBlockTemplatesCollection();
|
||||||
|
|
||||||
|
undo_stack_ = new QUndoStack();
|
||||||
|
connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,6 +105,9 @@ QETProject::QETProject(const QString &path, QObject *parent) :
|
|||||||
if (!project_file_info.isWritable()) {
|
if (!project_file_info.isWritable()) {
|
||||||
setReadOnly(true);
|
setReadOnly(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undo_stack_ = new QUndoStack();
|
||||||
|
connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,6 +129,9 @@ QETProject::QETProject(const QDomElement &xml_element, QObject *parent) :
|
|||||||
readProjectXml();
|
readProjectXml();
|
||||||
|
|
||||||
setupTitleBlockTemplatesCollection();
|
setupTitleBlockTemplatesCollection();
|
||||||
|
|
||||||
|
undo_stack_ = new QUndoStack();
|
||||||
|
connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(undoStackChanged(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,6 +154,7 @@ QETProject::~QETProject() {
|
|||||||
delete diagram;
|
delete diagram;
|
||||||
}
|
}
|
||||||
// qDebug() << diagrams_;
|
// qDebug() << diagrams_;
|
||||||
|
delete undo_stack_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ class QETProject : public QObject {
|
|||||||
bool diagramsWereModified();
|
bool diagramsWereModified();
|
||||||
DiagramContext projectProperties();
|
DiagramContext projectProperties();
|
||||||
void setProjectProperties(const DiagramContext &);
|
void setProjectProperties(const DiagramContext &);
|
||||||
|
QUndoStack* undoStack() {return undo_stack_;}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void componentWritten();
|
void componentWritten();
|
||||||
@@ -143,6 +144,7 @@ class QETProject : public QObject {
|
|||||||
void updateDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
|
void updateDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
|
||||||
void removeDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
|
void removeDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
|
||||||
void usedTitleBlockTemplateChanged(const QString &);
|
void usedTitleBlockTemplateChanged(const QString &);
|
||||||
|
void undoStackChanged (bool a) {if (!a) setModified(true);}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupTitleBlockTemplatesCollection();
|
void setupTitleBlockTemplatesCollection();
|
||||||
@@ -193,6 +195,8 @@ class QETProject : public QObject {
|
|||||||
TitleBlockTemplatesProjectCollection titleblocks_;
|
TitleBlockTemplatesProjectCollection titleblocks_;
|
||||||
/// project-wide variables that will be made available to child diagrams
|
/// project-wide variables that will be made available to child diagrams
|
||||||
DiagramContext project_properties_;
|
DiagramContext project_properties_;
|
||||||
|
/// undo stack for this project
|
||||||
|
QUndoStack *undo_stack_;
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(QETProject *)
|
Q_DECLARE_METATYPE(QETProject *)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user