QETDiagramEditor : clean some code

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3571 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-12-26 19:41:00 +00:00
parent f93b0817d6
commit a3525b466d
2 changed files with 245 additions and 258 deletions

View File

@@ -44,10 +44,12 @@
#include <QMessageBox> #include <QMessageBox>
/** /**
constructeur * @brief QETDiagramEditor::QETDiagramEditor
@param files Liste de fichiers a ouvrir * Constructor
@param parent le widget parent de la fenetre principale * @param files, list of files to open
* @param parent, parent widget
*/ */
QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) : QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) :
QETMainWindow(parent), QETMainWindow(parent),
@@ -59,10 +61,10 @@ QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) :
m_file_actions_group (this), m_file_actions_group (this),
open_dialog_dir (QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)) open_dialog_dir (QDesktopServices::storageLocation(QDesktopServices::DesktopLocation))
{ {
// mise en place de l'interface MDI au centre de l'application //Setup the mdi area at center of application
setCentralWidget(&workspace); setCentralWidget(&workspace);
// nomme l'objet afin qu'il soit reperable par les feuilles de style //Set object name to be retrieved by the stylesheets
workspace.setBackground(QBrush(Qt::NoBrush)); workspace.setBackground(QBrush(Qt::NoBrush));
workspace.setObjectName("mdiarea"); workspace.setObjectName("mdiarea");
@@ -70,16 +72,11 @@ QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) :
workspace.setTabsClosable(true); workspace.setTabsClosable(true);
#endif #endif
// mise en place du signalmapper //Set the signal mapper
connect(&windowMapper, SIGNAL(mapped(QWidget *)), this, SLOT(activateWidget(QWidget *))); connect(&windowMapper, SIGNAL(mapped(QWidget *)), this, SLOT(activateWidget(QWidget *)));
// titre de la fenetre
setWindowTitle(tr("QElectroTech", "window title")); setWindowTitle(tr("QElectroTech", "window title"));
// icone de la fenetre
setWindowIcon(QET::Icons::QETLogo); setWindowIcon(QET::Icons::QETLogo);
// barre de statut de la fenetre
statusBar() -> showMessage(tr("QElectroTech", "status bar message")); statusBar() -> showMessage(tr("QElectroTech", "status bar message"));
setUpElementsPanel(); setUpElementsPanel();
@@ -90,38 +87,28 @@ QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) :
tabifyDockWidget(qdw_undo, qdw_pa); tabifyDockWidget(qdw_undo, qdw_pa);
// la fenetre est maximisee par defaut //By default the windows is maximised
setMinimumSize(QSize(500, 350)); setMinimumSize(QSize(500, 350));
setWindowState(Qt::WindowMaximized); setWindowState(Qt::WindowMaximized);
// connexions signaux / slots pour une interface sensee connect (&workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(subWindowActivated(QMdiSubWindow*)));
connect (&workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(slot_updateWindowsMenu()));
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()));
connect (&undo_group, SIGNAL(cleanChanged(bool)), this, SLOT(activeUndoStackCleanChanged(bool))); connect (&undo_group, SIGNAL(cleanChanged(bool)), this, SLOT(activeUndoStackCleanChanged(bool)));
// lecture des parametres
readSettings(); readSettings();
// affichage
show(); show();
// si des chemins de fichiers valides sont passes en arguments //If valid file path is given as arguments
uint opened_projects = 0; uint opened_projects = 0;
if (files.count()) { if (files.count())
// alors on ouvre ces fichiers {
foreach(QString file, files) { //So we open this files
bool project_opening = openAndAddProject(file, false); foreach(QString file, files)
if (project_opening) { if (openAndAddProject(file, false))
++ opened_projects; ++ opened_projects;
} }
}
}
slot_updateActions(); slot_updateActions();
// si aucun schema n'a ete ouvert jusqu'a maintenant, on ouvre un nouveau schema
//if (!opened_projects) newProject();
} }
/** /**
@@ -1155,24 +1142,22 @@ void QETDiagramEditor::slot_setVisualisationMode() {
} }
/** /**
gere les actions * @brief QETDiagramEditor::slot_updateActions
* Manage actions
*/ */
void QETDiagramEditor::slot_updateActions() { void QETDiagramEditor::slot_updateActions()
{
DiagramView *dv = currentDiagram(); DiagramView *dv = currentDiagram();
ProjectView *pv = currentProject(); ProjectView *pv = currentProject();
bool opened_project = pv; bool opened_project = pv;
bool opened_diagram = dv; bool opened_diagram = dv;
bool editable_project = (pv && !pv -> project() -> isReadOnly()); bool editable_project = (pv && !pv -> project() -> isReadOnly());
bool editable_diagram = (dv && !dv -> diagram() -> isReadOnly());
// actions ayant juste besoin d'un document ouvert
close_file -> setEnabled(opened_project); close_file -> setEnabled(opened_project);
save_file -> setEnabled(editable_project && undo_group.activeStack()->count());
save_file_as -> setEnabled(opened_project); save_file_as -> setEnabled(opened_project);
prj_edit_prop -> setEnabled(opened_project); prj_edit_prop -> setEnabled(opened_project);
prj_add_diagram -> setEnabled(editable_project); prj_add_diagram -> setEnabled(editable_project);
//prj_add_diagram_foliolist -> setEnabled(editable_project);
prj_del_diagram -> setEnabled(editable_project); prj_del_diagram -> setEnabled(editable_project);
prj_clean -> setEnabled(editable_project); prj_clean -> setEnabled(editable_project);
prj_diagramList -> setEnabled(opened_project); prj_diagramList -> setEnabled(opened_project);
@@ -1183,10 +1168,10 @@ void QETDiagramEditor::slot_updateActions() {
prj_nomenclature -> setEnabled(editable_project); prj_nomenclature -> setEnabled(editable_project);
m_zoom_actions_group. setEnabled(opened_diagram); m_zoom_actions_group. setEnabled(opened_diagram);
m_select_actions_group. setEnabled(opened_diagram); m_select_actions_group. setEnabled(opened_diagram);
m_add_item_actions_group.setEnabled(editable_diagram); m_add_item_actions_group. setEnabled(editable_project);
m_row_column_actions_group.setEnabled(editable_diagram); m_row_column_actions_group.setEnabled(editable_project);
slot_updateUndoStack();
slot_updateModeActions(); slot_updateModeActions();
slot_updatePasteAction(); slot_updatePasteAction();
slot_updateComplexActions(); slot_updateComplexActions();
@@ -1196,14 +1181,18 @@ void QETDiagramEditor::slot_updateActions() {
* @brief QETDiagramEditor::slot_updateUndoStack * @brief QETDiagramEditor::slot_updateUndoStack
* Update the undo stack view * Update the undo stack view
*/ */
void QETDiagramEditor::slot_updateUndoStack() { void QETDiagramEditor::slot_updateUndoStack()
{
ProjectView *pv = currentProject(); ProjectView *pv = currentProject();
if (pv) { if (pv)
{
undo_group.setActiveStack(pv->project()->undoStack()); undo_group.setActiveStack(pv->project()->undoStack());
undo -> setEnabled (undo_group.canUndo());
redo -> setEnabled (undo_group.canRedo());
save_file -> setEnabled (undo_group.activeStack() -> count() && !pv -> project() -> isReadOnly()); save_file -> setEnabled (undo_group.activeStack() -> count() && !pv -> project() -> isReadOnly());
} }
else
{
save_file -> setDisabled(true);
}
} }
/** /**
@@ -1308,63 +1297,46 @@ void QETDiagramEditor::slot_updatePasteAction() {
} }
/** /**
Ajoute un projet dans l'espace de travail * @brief QETDiagramEditor::addProjectView
@param project_view Le projet a ajouter dans l'espace de travail * Add a new project view to workspace and
* build the connection between the projectview / project and this QETDiagramEditor.
* @param project_view, project view to add
*/ */
void QETDiagramEditor::addProjectView(ProjectView *project_view) { void QETDiagramEditor::addProjectView(ProjectView *project_view)
{
if (!project_view) return; if (!project_view) return;
// on maximise la nouvelle fenetre si la fenetre en cours est inexistante ou bien maximisee foreach(DiagramView *dv, project_view -> diagrams())
QWidget *current_window = workspace.activeSubWindow();
bool maximise = ((!current_window) || (current_window -> windowState() & Qt::WindowMaximized));
// ajoute la fenetre
QMdiSubWindow *sub_window = workspace.addSubWindow(project_view);
sub_window -> setWindowIcon(project_view -> windowIcon());
sub_window -> systemMenu() -> clear();
// lie les schemas du projet a l'editeur :
// quand on change de schemas a l'interieur d'un projet, on met a jour les menus
connect(project_view, SIGNAL(diagramActivated(DiagramView *)), this, SLOT(slot_updateWindowsMenu()));
connect(project_view, SIGNAL(diagramActivated(DiagramView *)), this, SLOT(slot_updateActions()));
//connect(project_view->project(), SIGNAL(projectModified(QETProject*,bool)), save_file, SLOT(setEnabled(bool)));
foreach(DiagramView *dv, project_view -> diagrams()) {
diagramWasAdded(dv); diagramWasAdded(dv);
}
// gere la fermeture du projet //Manage the close event of project
connect(project_view, SIGNAL(projectClosed(ProjectView*)), this, SLOT(projectWasClosed(ProjectView *))); connect(project_view, SIGNAL(projectClosed(ProjectView*)), this, SLOT(projectWasClosed(ProjectView *)));
//Manage the adding of diagram
// gere l'ajout et le retrait de schema du projet
connect(project_view, SIGNAL(diagramAdded(DiagramView *)), this, SLOT(diagramWasAdded(DiagramView *))); connect(project_view, SIGNAL(diagramAdded(DiagramView *)), this, SLOT(diagramWasAdded(DiagramView *)));
connect(project_view, SIGNAL(diagramAdded(DiagramView *)), this, SLOT(slot_updateActions()));
connect(project_view, SIGNAL(diagramRemoved(DiagramView *)), this, SLOT(slot_updateActions())); if (QETProject *project = project_view -> project())
if (QETProject *project = project_view -> project()) {
// on met aussi les menus a jour quand un projet passe en lecture seule ou non
connect(project, SIGNAL(readOnlyChanged(QETProject *, bool)), this, SLOT(slot_updateActions())); connect(project, SIGNAL(readOnlyChanged(QETProject *, bool)), this, SLOT(slot_updateActions()));
}
// gere les demandes consistant a retrouver un element dans le panel //Manage request for edit or find element and titleblock
connect(project_view, SIGNAL(findElementRequired(const ElementsLocation &)), this, SLOT(findElementInPanel(const ElementsLocation &))); connect(project_view, SIGNAL(findElementRequired(const ElementsLocation &)), this, SLOT(findElementInPanel(const ElementsLocation &)));
// gere les demandes pour l'edition d'un element
connect(project_view, SIGNAL(editElementRequired(const ElementsLocation &)), this, SLOT(editElementInEditor(const ElementsLocation &))); connect(project_view, SIGNAL(editElementRequired(const ElementsLocation &)), this, SLOT(editElementInEditor(const ElementsLocation &)));
connect(project_view, SIGNAL(editTitleBlockTemplate(const TitleBlockTemplateLocation &, bool)), QETApp::instance(), SLOT(openTitleBlockTemplate(TitleBlockTemplateLocation, bool)));
// handles requests to edit and/or duplicate an existing title block template
connect(
project_view, SIGNAL(editTitleBlockTemplate(const TitleBlockTemplateLocation &, bool)),
QETApp::instance(), SLOT(openTitleBlockTemplate(TitleBlockTemplateLocation, bool))
);
// display error messages sent by the project view // display error messages sent by the project view
connect(project_view, SIGNAL(errorEncountered(QString)), this, SLOT(showError(const QString &))); connect(project_view, SIGNAL(errorEncountered(QString)), this, SLOT(showError(const QString &)));
// affiche la fenetre //We maximise the new window if the current window is inexistent or maximized
QWidget *current_window = workspace.activeSubWindow();
bool maximise = ((!current_window) || (current_window -> windowState() & Qt::WindowMaximized));
//Add the new window
QMdiSubWindow *sub_window = workspace.addSubWindow(project_view);
sub_window -> setWindowIcon(project_view -> windowIcon());
sub_window -> systemMenu() -> clear();
//Display the new window
if (maximise) project_view -> showMaximized(); if (maximise) project_view -> showMaximized();
else project_view -> show(); else project_view -> show();
slot_updateActions();
} }
/** /**
@@ -1912,11 +1884,12 @@ void QETDiagramEditor::removeDiagramFromProject() {
} }
/** /**
Gere l'ajout d'un schema dans un projet * @brief QETDiagramEditor::diagramWasAdded
@param dv DiagramView concerne * Manage the adding of diagram view in a project
* @param dv, added diagram view
*/ */
void QETDiagramEditor::diagramWasAdded(DiagramView *dv) { void QETDiagramEditor::diagramWasAdded(DiagramView *dv)
// quand on change qqc a l'interieur d'un schema, on met a jour les menus {
connect(dv, SIGNAL(selectionChanged()), this, SLOT(slot_updateComplexActions())); connect(dv, SIGNAL(selectionChanged()), this, SLOT(slot_updateComplexActions()));
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions())); connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions()));
connect(dv, SIGNAL(itemAdded()), this, SLOT(addItemFinish())); connect(dv, SIGNAL(itemAdded()), this, SLOT(addItemFinish()));
@@ -2014,6 +1987,19 @@ void QETDiagramEditor::addItemFinish() {
m_add_item_actions_group.checkedAction()->setChecked(false); m_add_item_actions_group.checkedAction()->setChecked(false);
} }
/**
* @brief QETDiagramEditor::subWindowActivated
* Slot used to update menu and undo stack when subwindows of MDIarea was activated
* @param subWindows
*/
void QETDiagramEditor::subWindowActivated(QMdiSubWindow *subWindows)
{
Q_UNUSED(subWindows);
slot_updateActions();
slot_updateWindowsMenu();
}
/** /**
* @brief QETDiagramEditor::activeUndoStackCleanChanged * @brief QETDiagramEditor::activeUndoStackCleanChanged
* Enable the QAction save_file when @clean is set to false * Enable the QAction save_file when @clean is set to false

View File

@@ -158,6 +158,7 @@ class QETDiagramEditor : public QETMainWindow {
void showError(const QETResult &); void showError(const QETResult &);
void showError(const QString &); void showError(const QString &);
void addItemFinish(); void addItemFinish();
void subWindowActivated(QMdiSubWindow *subWindows);
private slots: private slots:
void activeUndoStackCleanChanged (bool clean); void activeUndoStackCleanChanged (bool clean);