2007-12-01 10:47:15 +00:00
/*
2019-01-13 16:56:12 +00:00
Copyright 2006 - 2019 The QElectroTech Team
2007-12-01 10:47:15 +00:00
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/>.
*/
2007-09-21 12:35:28 +00:00
# include "qetdiagrameditor.h"
2007-09-21 13:22:18 +00:00
# include "qetapp.h"
2013-02-12 18:37:08 +00:00
# include "diagramcontent.h"
2007-01-29 00:41:12 +00:00
# include "diagramview.h"
2007-09-25 23:24:36 +00:00
# include "diagram.h"
2013-11-14 10:11:22 +00:00
# include "qetgraphicsitem/element.h"
2007-02-26 22:42:46 +00:00
# include "elementspanelwidget.h"
2007-10-14 10:09:46 +00:00
# include "conductorpropertieswidget.h"
2009-04-03 19:30:25 +00:00
# include "qetproject.h"
# include "projectview.h"
2008-07-30 11:51:27 +00:00
# include "recentfiles.h"
2009-05-01 14:41:33 +00:00
# include "qeticons.h"
2009-07-08 09:41:20 +00:00
# include "qetelementeditor.h"
2009-08-09 16:02:14 +00:00
# include "qetmessagebox.h"
2012-07-13 07:21:19 +00:00
# include "qetresult.h"
2012-02-06 21:21:43 +00:00
# include "genericpanel.h"
2013-04-11 09:35:10 +00:00
# include "nomenclature.h"
2014-02-08 18:17:10 +00:00
# include "diagramfoliolist.h"
2014-09-24 09:38:16 +00:00
# include "qetshapeitem.h"
2014-10-26 11:57:38 +00:00
# include "reportproperties.h"
2015-05-07 22:15:00 +00:00
# include "diagrampropertieseditordockwidget.h"
2015-11-07 12:28:43 +00:00
# include "diagrameventaddshape.h"
2015-11-12 17:01:08 +00:00
# include "diagrameventaddimage.h"
2015-11-12 17:29:48 +00:00
# include "diagrameventaddtext.h"
2015-12-08 16:52:10 +00:00
# include "elementscollectionwidget.h"
2016-07-13 14:57:27 +00:00
# include "autonumberingdockwidget.h"
2017-08-03 17:36:08 +00:00
# include "dynamicelementtextitem.h"
# include "conductortextitem.h"
2017-12-05 20:51:54 +00:00
# include "undocommand/rotateselectioncommand.h"
# include "rotatetextscommand.h"
2017-12-05 21:41:29 +00:00
# include "diagramcommands.h"
2018-04-04 15:07:52 +00:00
# include "dialogwaiting.h"
2018-05-18 21:46:36 +00:00
# include "addelementtextcommand.h"
2013-04-11 09:35:10 +00:00
2013-01-03 17:26:08 +00:00
# include <QMessageBox>
2015-03-02 20:14:56 +00:00
# include <QStandardPaths>
2019-03-16 10:50:30 +00:00
# include <KAutoSaveFile>
2013-01-03 17:26:08 +00:00
2015-12-08 16:52:10 +00:00
# include "elementscollectionmodel.h"
2014-12-26 19:41:00 +00:00
2006-10-27 15:47:22 +00:00
/**
2014-12-26 19:41:00 +00:00
* @ brief QETDiagramEditor : : QETDiagramEditor
* Constructor
* @ param files , list of files to open
* @ param parent , parent widget
2006-10-27 15:47:22 +00:00
*/
2009-04-03 19:30:25 +00:00
QETDiagramEditor : : QETDiagramEditor ( const QStringList & files , QWidget * parent ) :
2012-02-13 22:12:37 +00:00
QETMainWindow ( parent ) ,
2018-06-20 18:03:39 +00:00
m_row_column_actions_group ( this ) ,
m_selection_actions_group ( this ) ,
2014-10-19 11:25:03 +00:00
m_add_item_actions_group ( this ) ,
m_zoom_actions_group ( this ) ,
m_select_actions_group ( this ) ,
m_file_actions_group ( this ) ,
2015-03-02 20:14:56 +00:00
open_dialog_dir ( QStandardPaths : : writableLocation ( QStandardPaths : : DesktopLocation ) )
2009-04-03 19:30:25 +00:00
{
2016-07-13 14:57:27 +00:00
activeSubWindowIndex = 0 ;
2018-09-25 16:05:24 +00:00
QSplitter * splitter_ = new QSplitter ( this ) ;
splitter_ - > setChildrenCollapsible ( false ) ;
splitter_ - > setOrientation ( Qt : : Vertical ) ;
splitter_ - > addWidget ( & m_workspace ) ;
splitter_ - > addWidget ( & m_search_and_replace_widget ) ;
m_search_and_replace_widget . setHidden ( true ) ;
m_search_and_replace_widget . setEditor ( this ) ;
setCentralWidget ( splitter_ ) ;
2009-05-24 17:46:44 +00:00
2014-12-26 19:41:00 +00:00
//Set object name to be retrieved by the stylesheets
2018-06-20 18:03:39 +00:00
m_workspace . setBackground ( QBrush ( Qt : : NoBrush ) ) ;
m_workspace . setObjectName ( " mdiarea " ) ;
m_workspace . setTabsClosable ( true ) ;
2012-07-08 13:32:38 +00:00
2014-12-26 19:41:00 +00:00
//Set the signal mapper
2009-04-03 19:30:25 +00:00
connect ( & windowMapper , SIGNAL ( mapped ( QWidget * ) ) , this , SLOT ( activateWidget ( QWidget * ) ) ) ;
2006-10-27 15:47:22 +00:00
2014-12-26 19:41:00 +00:00
setWindowTitle ( tr ( " QElectroTech " , " window title " ) ) ;
2009-05-01 14:41:33 +00:00
setWindowIcon ( QET : : Icons : : QETLogo ) ;
2009-04-03 19:30:25 +00:00
statusBar ( ) - > showMessage ( tr ( " QElectroTech " , " status bar message " ) ) ;
2006-10-27 15:47:22 +00:00
2014-10-26 11:57:38 +00:00
setUpElementsPanel ( ) ;
2015-12-08 16:52:10 +00:00
setUpElementsCollectionWidget ( ) ;
2014-10-26 11:57:38 +00:00
setUpUndoStack ( ) ;
2015-05-07 22:15:00 +00:00
setUpSelectionPropertiesEditor ( ) ;
2016-07-13 14:57:27 +00:00
setUpAutonumberingWidget ( ) ;
2015-12-08 16:52:10 +00:00
2014-10-26 11:57:38 +00:00
setUpActions ( ) ;
setUpToolBar ( ) ;
setUpMenu ( ) ;
2014-11-28 18:14:33 +00:00
tabifyDockWidget ( qdw_undo , qdw_pa ) ;
2006-10-27 15:47:22 +00:00
2014-12-26 19:41:00 +00:00
//By default the windows is maximised
2007-11-12 15:21:14 +00:00
setMinimumSize ( QSize ( 500 , 350 ) ) ;
2006-10-27 15:47:22 +00:00
setWindowState ( Qt : : WindowMaximized ) ;
2018-06-20 18:03:39 +00:00
connect ( & m_workspace , SIGNAL ( subWindowActivated ( QMdiSubWindow * ) ) , this , SLOT ( subWindowActivated ( QMdiSubWindow * ) ) ) ;
2014-12-10 17:00:08 +00:00
connect ( QApplication : : clipboard ( ) , SIGNAL ( dataChanged ( ) ) , this , SLOT ( slot_updatePasteAction ( ) ) ) ;
2016-06-07 12:55:05 +00:00
2007-11-12 15:21:14 +00:00
readSettings ( ) ;
2007-09-22 13:27:14 +00:00
show ( ) ;
2008-08-23 12:54:16 +00:00
2014-12-26 19:41:00 +00:00
//If valid file path is given as arguments
2009-04-03 19:30:25 +00:00
uint opened_projects = 0 ;
2014-12-26 19:41:00 +00:00
if ( files . count ( ) )
{
//So we open this files
2017-02-05 16:18:50 +00:00
foreach ( QString file , files )
2018-04-04 15:07:52 +00:00
if ( openAndAddProject ( file ) )
2009-04-03 19:30:25 +00:00
+ + opened_projects ;
2008-08-23 12:54:16 +00:00
}
2014-10-26 11:57:38 +00:00
slot_updateActions ( ) ;
2006-10-27 15:47:22 +00:00
}
2007-04-12 03:13:13 +00:00
/**
Destructeur
*/
2007-09-21 12:35:28 +00:00
QETDiagramEditor : : ~ QETDiagramEditor ( ) {
2007-04-12 03:13:13 +00:00
}
2006-10-27 15:47:22 +00:00
/**
2014-10-26 11:57:38 +00:00
* @ brief QETDiagramEditor : : setUpElementsPanel
* Setup the element panel and element panel widget
*/
void QETDiagramEditor : : setUpElementsPanel ( ) {
//Add the element panel as a QDockWidget
2016-08-21 20:50:52 +00:00
qdw_pa = new QDockWidget ( tr ( " Projets " , " dock title " ) , this ) ;
2014-10-26 11:57:38 +00:00
2016-08-21 20:32:05 +00:00
qdw_pa - > setObjectName ( " projects panel " ) ;
2014-10-26 11:57:38 +00:00
qdw_pa - > setAllowedAreas ( Qt : : LeftDockWidgetArea | Qt : : RightDockWidgetArea ) ;
qdw_pa - > setFeatures ( QDockWidget : : AllDockWidgetFeatures ) ;
qdw_pa - > setMinimumWidth ( 160 ) ;
qdw_pa - > setWidget ( pa = new ElementsPanelWidget ( qdw_pa ) ) ;
2014-11-28 18:14:33 +00:00
addDockWidget ( Qt : : LeftDockWidgetArea , qdw_pa ) ;
2014-10-26 11:57:38 +00:00
connect ( pa , SIGNAL ( requestForProject ( QETProject * ) ) , this , SLOT ( activateProject ( QETProject * ) ) ) ;
connect ( pa , SIGNAL ( requestForProjectClosing ( QETProject * ) ) , this , SLOT ( closeProject ( QETProject * ) ) ) ;
connect ( pa , SIGNAL ( requestForProjectPropertiesEdition ( QETProject * ) ) , this , SLOT ( editProjectProperties ( QETProject * ) ) ) ;
connect ( pa , SIGNAL ( requestForNewDiagram ( QETProject * ) ) , this , SLOT ( addDiagramToProject ( QETProject * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagram ( Diagram * ) ) , this , SLOT ( activateDiagram ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramPropertiesEdition ( Diagram * ) ) , this , SLOT ( editDiagramProperties ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramDeletion ( Diagram * ) ) , this , SLOT ( removeDiagram ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramMoveUp ( Diagram * ) ) , this , SLOT ( moveDiagramUp ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramMoveDown ( Diagram * ) ) , this , SLOT ( moveDiagramDown ( Diagram * ) ) ) ;
2015-03-04 06:00:25 +00:00
connect ( pa , SIGNAL ( requestForDiagramMoveUpTop ( Diagram * ) ) , this , SLOT ( moveDiagramUpTop ( Diagram * ) ) ) ;
2014-12-14 17:01:11 +00:00
connect ( pa , SIGNAL ( requestForDiagramMoveUpx10 ( Diagram * ) ) , this , SLOT ( moveDiagramUpx10 ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramMoveDownx10 ( Diagram * ) ) , this , SLOT ( moveDiagramDownx10 ( Diagram * ) ) ) ;
2006-10-27 15:47:22 +00:00
}
2015-12-08 16:52:10 +00:00
/**
* @ brief QETDiagramEditor : : setUpElementsCollectionWidget
* Set up the dock widget of element collection
*/
void QETDiagramEditor : : setUpElementsCollectionWidget ( )
{
2016-08-21 20:50:52 +00:00
m_qdw_elmt_collection = new QDockWidget ( tr ( " Collections " ) , this ) ;
2015-12-08 16:52:10 +00:00
m_qdw_elmt_collection - > setObjectName ( " elements_collection_widget " ) ;
m_qdw_elmt_collection - > setAllowedAreas ( Qt : : LeftDockWidgetArea | Qt : : RightDockWidgetArea ) ;
m_qdw_elmt_collection - > setFeatures ( QDockWidget : : AllDockWidgetFeatures ) ;
m_element_collection_widget = new ElementsCollectionWidget ( m_qdw_elmt_collection ) ;
m_qdw_elmt_collection - > setWidget ( m_element_collection_widget ) ;
m_element_collection_widget - > expandFirstItems ( ) ;
addDockWidget ( Qt : : RightDockWidgetArea , m_qdw_elmt_collection ) ;
}
2006-10-27 15:47:22 +00:00
/**
2014-10-26 11:57:38 +00:00
* @ brief QETDiagramEditor : : setUpUndoStack
* Setup the undostack and undo stack widget
*/
void QETDiagramEditor : : setUpUndoStack ( ) {
2018-07-30 15:24:29 +00:00
QUndoView * undo_view = new QUndoView ( & undo_group , this ) ;
2014-10-26 11:57:38 +00:00
undo_view - > setEmptyLabel ( tr ( " Aucune modification " ) ) ;
2015-03-02 20:14:56 +00:00
undo_view - > setStatusTip ( tr ( " Cliquez sur une action pour revenir en arrière dans l'édition de votre schéma " , " Status tip " ) ) ;
2015-06-21 15:29:09 +00:00
undo_view - > setWhatsThis ( tr ( " Ce panneau liste les différentes actions effectuées sur le folio courant. Cliquer sur une action permet de revenir à l'état du schéma juste après son application. " , " \" What's this \" tip " ) ) ;
2014-10-26 11:57:38 +00:00
qdw_undo = new QDockWidget ( tr ( " Annulations " , " dock title " ) , this ) ;
qdw_undo - > setObjectName ( " diagram_undo " ) ;
qdw_undo - > setAllowedAreas ( Qt : : LeftDockWidgetArea | Qt : : RightDockWidgetArea ) ;
qdw_undo - > setFeatures ( QDockWidget : : AllDockWidgetFeatures ) ;
qdw_undo - > setMinimumWidth ( 160 ) ;
qdw_undo - > setWidget ( undo_view ) ;
2014-11-28 18:14:33 +00:00
addDockWidget ( Qt : : LeftDockWidgetArea , qdw_undo ) ;
2014-10-26 11:57:38 +00:00
}
2015-05-07 22:15:00 +00:00
/**
* @ brief QETDiagramEditor : : setUpSelectionPropertiesEditor
* Setup the dock for edit the current selection
*/
void QETDiagramEditor : : setUpSelectionPropertiesEditor ( )
{
m_selection_properties_editor = new DiagramPropertiesEditorDockWidget ( this ) ;
m_selection_properties_editor - > setObjectName ( " diagram_properties_editor_dock_widget " ) ;
addDockWidget ( Qt : : RightDockWidgetArea , m_selection_properties_editor ) ;
}
2016-07-13 14:57:27 +00:00
/**
* @ brief QETDiagramEditor : : setUpAutonumberingWidget
* Setup the dock for AutoNumbering Selection
*/
void QETDiagramEditor : : setUpAutonumberingWidget ( )
{
m_autonumbering_dock = new AutoNumberingDockWidget ( this ) ;
m_autonumbering_dock - > setAllowedAreas ( Qt : : LeftDockWidgetArea | Qt : : RightDockWidgetArea ) ;
m_autonumbering_dock - > setFeatures ( QDockWidget : : AllDockWidgetFeatures ) ;
addDockWidget ( Qt : : RightDockWidgetArea , m_autonumbering_dock ) ;
}
2014-10-26 11:57:38 +00:00
/**
* @ brief QETDiagramEditor : : setUpActions
* Set up all Qaction
*/
2015-06-25 18:23:47 +00:00
void QETDiagramEditor : : setUpActions ( )
{
2018-06-20 18:03:39 +00:00
//Export to another file type (jpeg, dxf etc...)
m_export_diagram = new QAction ( QET : : Icons : : DocumentExport , tr ( " E&xporter " ) , this ) ;
m_export_diagram - > setShortcut ( QKeySequence ( tr ( " Ctrl+Shift+X " ) ) ) ;
m_export_diagram - > setStatusTip ( tr ( " Exporte le folio courant dans un autre format " , " status bar tip " ) ) ;
connect ( m_export_diagram , & QAction : : triggered , [ this ] ( ) {
ProjectView * current_project = currentProjectView ( ) ;
if ( current_project ) {
current_project - > exportProject ( ) ;
}
} ) ;
//Print
m_print = new QAction ( QET : : Icons : : DocumentPrint , tr ( " Imprimer " ) , this ) ;
m_print - > setShortcut ( QKeySequence ( QKeySequence : : Print ) ) ;
m_print - > setStatusTip ( tr ( " Imprime un ou plusieurs folios du projet courant " , " status bar tip " ) ) ;
connect ( m_print , & QAction : : triggered , [ this ] ( ) {
ProjectView * current_project = currentProjectView ( ) ;
if ( current_project ) {
current_project - > printProject ( ) ;
}
} ) ;
//Quit editor
m_quit_editor = new QAction ( QET : : Icons : : ApplicationExit , tr ( " &Quitter " ) , this ) ;
m_quit_editor - > setShortcut ( QKeySequence ( tr ( " Ctrl+Q " ) ) ) ;
m_quit_editor - > setStatusTip ( tr ( " Ferme l'application QElectroTech " , " status bar tip " ) ) ;
connect ( m_quit_editor , & QAction : : triggered , this , & QETDiagramEditor : : close ) ;
2014-10-26 11:57:38 +00:00
2018-06-20 18:03:39 +00:00
//Undo
2007-09-29 12:54:01 +00:00
undo = undo_group . createUndoAction ( this , tr ( " Annuler " ) ) ;
2018-06-20 18:03:39 +00:00
undo - > setIcon ( QET : : Icons : : EditUndo ) ;
undo - > setShortcut ( QKeySequence : : Undo ) ;
undo - > setStatusTip ( tr ( " Annule l'action précédente " , " status bar tip " ) ) ;
//Redo
2007-09-29 12:54:01 +00:00
redo = undo_group . createRedoAction ( this , tr ( " Refaire " ) ) ;
2018-06-20 18:03:39 +00:00
redo - > setIcon ( QET : : Icons : : EditRedo ) ;
redo - > setShortcut ( QKeySequence : : Redo ) ;
redo - > setStatusTip ( tr ( " Restaure l'action annulée " , " status bar tip " ) ) ;
2015-09-19 13:27:06 +00:00
2018-06-20 18:03:39 +00:00
//cut copy past
2017-08-03 17:36:08 +00:00
m_cut = new QAction ( QET : : Icons : : EditCut , tr ( " Co&uper " ) , this ) ;
m_copy = new QAction ( QET : : Icons : : EditCopy , tr ( " Cop&ier " ) , this ) ;
2018-06-20 18:03:39 +00:00
m_paste = new QAction ( QET : : Icons : : EditPaste , tr ( " C&oller " ) , this ) ;
2015-09-19 13:27:06 +00:00
2017-08-03 17:36:08 +00:00
m_cut - > setShortcut ( QKeySequence : : Cut ) ;
m_copy - > setShortcut ( QKeySequence : : Copy ) ;
2018-06-20 18:03:39 +00:00
m_paste - > setShortcut ( QKeySequence : : Paste ) ;
2015-09-19 13:27:06 +00:00
2017-08-03 17:36:08 +00:00
m_cut - > setStatusTip ( tr ( " Transfère les éléments sélectionnés dans le presse-papier " , " status bar tip " ) ) ;
m_copy - > setStatusTip ( tr ( " Copie les éléments sélectionnés dans le presse-papier " , " status bar tip " ) ) ;
2018-06-20 18:03:39 +00:00
m_paste - > setStatusTip ( tr ( " Place les éléments du presse-papier sur le folio " , " status bar tip " ) ) ;
2015-09-19 13:27:06 +00:00
2018-06-20 18:03:39 +00:00
connect ( m_cut , & QAction : : triggered , [ this ] ( ) {
if ( currentDiagramView ( ) )
currentDiagramView ( ) - > cut ( ) ;
} ) ;
connect ( m_copy , & QAction : : triggered , [ this ] ( ) {
if ( currentDiagramView ( ) )
currentDiagramView ( ) - > copy ( ) ;
} ) ;
connect ( m_paste , & QAction : : triggered , [ this ] ( ) {
if ( currentDiagramView ( ) )
currentDiagramView ( ) - > paste ( ) ;
} ) ;
2015-01-11 11:10:57 +00:00
2018-06-20 18:03:39 +00:00
//Reset conductor path
m_conductor_reset = new QAction ( QET : : Icons : : ConductorSettings , tr ( " Réinitialiser les conducteurs " ) , this ) ;
m_conductor_reset - > setShortcut ( QKeySequence ( tr ( " Ctrl+K " ) ) ) ;
m_conductor_reset - > setStatusTip ( tr ( " Recalcule les chemins des conducteurs sans tenir compte des modifications " , " status bar tip " ) ) ;
connect ( m_conductor_reset , & QAction : : triggered , [ this ] ( ) {
if ( DiagramView * dv = currentDiagramView ( ) )
dv - > resetConductors ( ) ;
} ) ;
//AutoConductor
2015-03-02 20:14:56 +00:00
m_auto_conductor = new QAction ( QET : : Icons : : Autoconnect , tr ( " Création automatique de conducteur(s) " , " Tool tip of auto conductor " ) , this ) ;
2018-06-20 18:03:39 +00:00
m_auto_conductor - > setStatusTip ( tr ( " Utiliser la création automatique de conducteur(s) quand cela est possible " , " Status tip of auto conductor " ) ) ;
m_auto_conductor - > setCheckable ( true ) ;
connect ( m_auto_conductor , & QAction : : triggered , [ this ] ( bool ac ) {
if ( ProjectView * pv = currentProjectView ( ) )
pv - > project ( ) - > setAutoConductor ( ac ) ;
} ) ;
2015-01-11 11:10:57 +00:00
2018-06-20 18:03:39 +00:00
//Switch background color
2015-06-21 15:29:09 +00:00
m_grey_background = new QAction ( QET : : Icons : : DiagramBg , tr ( " Couleur de fond blanc/gris " , " Tool tip of white/grey background button " ) , this ) ;
m_grey_background - > setStatusTip ( tr ( " Affiche la couleur de fond du folio en blanc ou en gris " , " Status tip of white/grey background button " ) ) ;
m_grey_background - > setCheckable ( true ) ;
2015-06-25 18:23:47 +00:00
connect ( m_grey_background , & QAction : : triggered , [ this ] ( bool checked ) {
Diagram : : background_color = checked ? Qt : : darkGray : Qt : : white ;
2018-04-12 16:24:44 +00:00
if ( this - > currentDiagramView ( ) & & this - > currentDiagramView ( ) - > diagram ( ) )
this - > currentDiagramView ( ) - > diagram ( ) - > update ( ) ;
2015-06-25 18:23:47 +00:00
} ) ;
2015-06-21 11:00:08 +00:00
2018-06-20 18:03:39 +00:00
//Draw or not the background grid
2016-08-19 11:33:23 +00:00
m_draw_grid = new QAction ( QET : : Icons : : Grid , tr ( " Afficher la grille " ) , this ) ;
2016-08-18 16:30:24 +00:00
m_draw_grid - > setStatusTip ( tr ( " Affiche ou masque la grille des folios " ) ) ;
m_draw_grid - > setCheckable ( true ) ;
m_draw_grid - > setChecked ( true ) ;
connect ( m_draw_grid , & QAction : : triggered , [ this ] ( bool checked ) {
2017-02-05 16:18:50 +00:00
foreach ( ProjectView * prjv , this - > openedProjects ( ) )
foreach ( Diagram * d , prjv - > project ( ) - > diagrams ( ) ) {
2016-08-18 16:30:24 +00:00
d - > setDisplayGrid ( checked ) ;
d - > update ( ) ;
}
} ) ;
2018-06-20 18:03:39 +00:00
//Edit current diagram properties
m_edit_diagram_properties = new QAction ( QET : : Icons : : DialogInformation , tr ( " Propriétés du folio " ) , this ) ;
m_edit_diagram_properties - > setShortcut ( QKeySequence ( tr ( " Ctrl+L " ) ) ) ;
m_edit_diagram_properties - > setStatusTip ( tr ( " Édite les propriétés du folio (dimensions, informations du cartouche, propriétés des conducteurs...) " , " status bar tip " ) ) ;
connect ( m_edit_diagram_properties , & QAction : : triggered , [ this ] ( ) {
if ( ProjectView * project_view = currentProjectView ( ) )
{
activateProject ( project_view ) ;
project_view - > editCurrentDiagramProperties ( ) ;
}
} ) ;
//Edit current project properties
2018-12-04 22:33:11 +00:00
m_project_edit_properties = new QAction ( QET : : Icons : : ProjectProperties , tr ( " Propriétés du projet " ) , this ) ;
2018-06-20 18:03:39 +00:00
connect ( m_project_edit_properties , & QAction : : triggered , [ this ] ( ) {
editProjectProperties ( currentProjectView ( ) ) ;
} ) ;
//Add new folio to current project
m_project_add_diagram = new QAction ( QET : : Icons : : DiagramAdd , tr ( " Ajouter un folio " ) , this ) ;
m_project_add_diagram - > setShortcut ( QKeySequence ( tr ( " Ctrl+T " ) ) ) ;
connect ( m_project_add_diagram , & QAction : : triggered , [ this ] ( ) {
if ( ProjectView * current_project = currentProjectView ( ) ) {
current_project - > addNewDiagram ( ) ;
}
} ) ;
//Remove current folio from current project
m_remove_diagram_from_project = new QAction ( QET : : Icons : : DiagramDelete , tr ( " Supprimer le folio " ) , this ) ;
connect ( m_remove_diagram_from_project , & QAction : : triggered , this , & QETDiagramEditor : : removeDiagramFromProject ) ;
//Clean the current project
m_clean_project = new QAction ( QET : : Icons : : EditClear , tr ( " Nettoyer le projet " ) , this ) ;
connect ( m_clean_project , & QAction : : triggered , [ this ] ( ) {
if ( ProjectView * current_project = currentProjectView ( ) ) {
if ( current_project - > cleanProject ( ) ) {
pa - > reloadAndFilter ( ) ;
}
}
} ) ;
//Add folio list to current project
2018-12-04 22:33:11 +00:00
m_project_folio_list = new QAction ( QET : : Icons : : TableOfContent , tr ( " Ajouter un sommaire " ) , this ) ;
2018-06-20 18:03:39 +00:00
connect ( m_project_folio_list , & QAction : : triggered , [ this ] ( ) {
if ( ProjectView * current_project = currentProjectView ( ) ) {
current_project - > addNewDiagramFolioList ( ) ;
}
} ) ;
//Export nomenclature to CSV
m_project_nomenclature = new QAction ( QET : : Icons : : DocumentSpreadsheet , tr ( " Exporter une nomenclature " ) , this ) ;
connect ( m_project_nomenclature , & QAction : : triggered , [ this ] ( ) {
nomenclature nomencl ( currentProjectView ( ) - > project ( ) , this ) ;
nomencl . saveToCSVFile ( ) ;
} ) ;
//Lauch the plugin of terminal generator
2018-12-04 22:33:11 +00:00
m_project_terminalBloc = new QAction ( QET : : Icons : : TerminalStrip , tr ( " Lancer le plugin de création de borniers " ) , this ) ;
2018-06-20 18:03:39 +00:00
connect ( m_project_terminalBloc , & QAction : : triggered , this , & QETDiagramEditor : : generateTerminalBlock ) ;
//MDI view style
m_tabbed_view_mode = new QAction ( tr ( " en utilisant des onglets " ) , this ) ;
m_tabbed_view_mode - > setStatusTip ( tr ( " Présente les différents projets ouverts des onglets " , " status bar tip " ) ) ;
m_tabbed_view_mode - > setCheckable ( true ) ;
connect ( m_tabbed_view_mode , & QAction : : triggered , this , & QETDiagramEditor : : setTabbedMode ) ;
m_windowed_view_mode = new QAction ( tr ( " en utilisant des fenêtres " ) , this ) ;
m_windowed_view_mode - > setStatusTip ( tr ( " Présente les différents projets ouverts dans des sous-fenêtres " , " status bar tip " ) ) ;
m_windowed_view_mode - > setCheckable ( true ) ;
connect ( m_windowed_view_mode , & QAction : : triggered , this , & QETDiagramEditor : : setWindowedMode ) ;
m_group_view_mode = new QActionGroup ( this ) ;
m_group_view_mode - > addAction ( m_windowed_view_mode ) ;
m_group_view_mode - > addAction ( m_tabbed_view_mode ) ;
m_group_view_mode - > setExclusive ( true ) ;
m_tile_window = new QAction ( tr ( " &Mosaïque " ) , this ) ;
m_tile_window - > setStatusTip ( tr ( " Dispose les fenêtres en mosaïque " , " status bar tip " ) ) ;
connect ( m_tile_window , & QAction : : triggered , & m_workspace , & QMdiArea : : tileSubWindows ) ;
m_cascade_window = new QAction ( tr ( " &Cascade " ) , this ) ;
m_cascade_window - > setStatusTip ( tr ( " Dispose les fenêtres en cascade " , " status bar tip " ) ) ;
connect ( m_cascade_window , & QAction : : triggered , & m_workspace , & QMdiArea : : cascadeSubWindows ) ;
//Switch selection/view mode
m_mode_selection = new QAction ( QET : : Icons : : PartSelect , tr ( " Mode Selection " ) , this ) ;
m_mode_selection - > setStatusTip ( tr ( " Permet de sélectionner les éléments " , " status bar tip " ) ) ;
m_mode_selection - > setCheckable ( true ) ;
m_mode_selection - > setChecked ( true ) ;
connect ( m_mode_selection , & QAction : : triggered , [ this ] ( ) {
if ( ProjectView * pv = currentProjectView ( ) ) {
for ( DiagramView * dv : pv - > diagram_views ( ) ) {
dv - > setSelectionMode ( ) ;
}
}
} ) ;
m_mode_visualise = new QAction ( QET : : Icons : : ViewMove , tr ( " Mode Visualisation " ) , this ) ;
m_mode_visualise - > setStatusTip ( tr ( " Permet de visualiser le folio sans pouvoir le modifier " , " status bar tip " ) ) ;
m_mode_visualise - > setCheckable ( true ) ;
connect ( m_mode_visualise , & QAction : : triggered , [ this ] ( ) {
if ( ProjectView * pv = currentProjectView ( ) ) {
for ( DiagramView * dv : pv - > diagram_views ( ) ) {
dv - > setVisualisationMode ( ) ;
}
}
} ) ;
grp_visu_sel = new QActionGroup ( this ) ;
grp_visu_sel - > addAction ( m_mode_selection ) ;
grp_visu_sel - > addAction ( m_mode_visualise ) ;
grp_visu_sel - > setExclusive ( true ) ;
//Navigate next/previous project
m_next_window = new QAction ( tr ( " Projet suivant " ) , this ) ;
m_next_window - > setShortcut ( QKeySequence : : NextChild ) ;
m_next_window - > setStatusTip ( tr ( " Active le projet suivant " , " status bar tip " ) ) ;
connect ( m_next_window , & QAction : : triggered , & m_workspace , & QMdiArea : : activateNextSubWindow ) ;
m_previous_window = new QAction ( tr ( " Projet précédent " ) , this ) ;
m_previous_window - > setShortcut ( QKeySequence : : PreviousChild ) ;
m_previous_window - > setStatusTip ( tr ( " Active le projet précédent " , " status bar tip " ) ) ;
connect ( m_previous_window , & QAction : : triggered , & m_workspace , & QMdiArea : : activatePreviousSubWindow ) ;
2014-10-26 11:57:38 +00:00
2015-09-19 13:27:06 +00:00
//Files action
2018-06-20 18:03:39 +00:00
QAction * new_file = m_file_actions_group . addAction ( QET : : Icons : : ProjectNew , tr ( " &Nouveau " ) ) ;
QAction * open_file = m_file_actions_group . addAction ( QET : : Icons : : DocumentOpen , tr ( " &Ouvrir " ) ) ;
m_save_file = m_file_actions_group . addAction ( QET : : Icons : : DocumentSave , tr ( " &Enregistrer " ) ) ;
m_save_file_as = m_file_actions_group . addAction ( QET : : Icons : : DocumentSaveAs , tr ( " Enregistrer sous " ) ) ;
m_close_file = m_file_actions_group . addAction ( QET : : Icons : : ProjectClose , tr ( " &Fermer " ) ) ;
new_file - > setShortcut ( QKeySequence : : New ) ;
open_file - > setShortcut ( QKeySequence : : Open ) ;
m_close_file - > setShortcut ( QKeySequence : : Close ) ;
m_save_file - > setShortcut ( QKeySequence : : Save ) ;
new_file - > setStatusTip ( tr ( " Crée un nouveau projet " , " status bar tip " ) ) ;
open_file - > setStatusTip ( tr ( " Ouvre un projet existant " , " status bar tip " ) ) ;
m_close_file - > setStatusTip ( tr ( " Ferme le projet courant " , " status bar tip " ) ) ;
m_save_file - > setStatusTip ( tr ( " Enregistre le projet courant et tous ses folios " , " status bar tip " ) ) ;
m_save_file_as - > setStatusTip ( tr ( " Enregistre le projet courant avec un autre nom de fichier " , " status bar tip " ) ) ;
connect ( m_save_file_as , & QAction : : triggered , this , & QETDiagramEditor : : saveAs ) ;
connect ( m_save_file , & QAction : : triggered , this , & QETDiagramEditor : : save ) ;
connect ( new_file , & QAction : : triggered , this , & QETDiagramEditor : : newProject ) ;
connect ( open_file , & QAction : : triggered , this , & QETDiagramEditor : : openProject ) ;
connect ( m_close_file , & QAction : : triggered , [ this ] ( ) {
if ( ProjectView * project_view = currentProjectView ( ) ) {
closeProject ( project_view ) ;
}
} ) ;
//Rows and Columns
2014-06-07 21:03:49 +00:00
QAction * add_column = m_row_column_actions_group . addAction ( QET : : Icons : : EditTableInsertColumnRight , tr ( " Ajouter une colonne " ) ) ;
QAction * remove_column = m_row_column_actions_group . addAction ( QET : : Icons : : EditTableDeleteColumn , tr ( " Enlever une colonne " ) ) ;
2016-08-23 00:10:33 +00:00
QAction * add_row = m_row_column_actions_group . addAction ( QET : : Icons : : EditTableInsertRowUnder , tr ( " Ajouter une ligne " , " Add row " ) ) ;
QAction * remove_row = m_row_column_actions_group . addAction ( QET : : Icons : : EditTableDeleteRow , tr ( " Enlever une ligne " , " Remove row " ) ) ;
2014-06-07 21:03:49 +00:00
2015-09-19 13:27:06 +00:00
add_column - > setStatusTip ( tr ( " Ajoute une colonne au folio " , " status bar tip " ) ) ;
remove_column - > setStatusTip ( tr ( " Enlève une colonne au folio " , " status bar tip " ) ) ;
add_row - > setStatusTip ( tr ( " Agrandit le folio en hauteur " , " status bar tip " ) ) ;
remove_row - > setStatusTip ( tr ( " Rétrécit le folio en hauteur " , " status bar tip " ) ) ;
add_column - > setData ( " add_column " ) ;
remove_column - > setData ( " remove_column " ) ;
add_row - > setData ( " add_row " ) ;
remove_row - > setData ( " remove_row " ) ;
2014-06-07 21:03:49 +00:00
2015-09-19 13:27:06 +00:00
connect ( & m_row_column_actions_group , & QActionGroup : : triggered , this , & QETDiagramEditor : : rowColumnGroupTriggered ) ;
2014-06-07 21:03:49 +00:00
2015-09-19 13:27:06 +00:00
//Selections Actions (related to a selected item)
2018-12-04 22:33:11 +00:00
m_delete_selection = m_selection_actions_group . addAction ( QET : : Icons : : EditDelete , tr ( " Supprimer " ) ) ;
m_rotate_selection = m_selection_actions_group . addAction ( QET : : Icons : : TransformRotate , tr ( " Pivoter " ) ) ;
m_rotate_texts = m_selection_actions_group . addAction ( QET : : Icons : : ObjectRotateRight , tr ( " Orienter les textes " ) ) ;
m_find_element = m_selection_actions_group . addAction ( QET : : Icons : : ZoomDraw , tr ( " Retrouver dans le panel " ) ) ;
m_edit_selection = m_selection_actions_group . addAction ( QET : : Icons : : ElementEdit , tr ( " Éditer l'item sélectionné " ) ) ;
m_group_selected_texts = m_selection_actions_group . addAction ( QET : : Icons : : textGroup , tr ( " Grouper les textes sélectionnés " ) ) ;
2017-08-03 17:36:08 +00:00
2018-06-20 18:03:39 +00:00
m_delete_selection - > setShortcut ( QKeySequence : : Delete ) ;
m_rotate_selection - > setShortcut ( QKeySequence ( tr ( " Space " ) ) ) ;
m_rotate_texts - > setShortcut ( QKeySequence ( tr ( " Ctrl+Space " ) ) ) ;
m_edit_selection - > setShortcut ( QKeySequence ( tr ( " Ctrl+E " ) ) ) ;
2017-08-03 17:36:08 +00:00
2018-06-20 18:03:39 +00:00
m_delete_selection - > setStatusTip ( tr ( " Enlève les éléments sélectionnés du folio " , " status bar tip " ) ) ;
m_rotate_selection - > setStatusTip ( tr ( " Pivote les éléments et textes sélectionnés " , " status bar tip " ) ) ;
m_rotate_texts - > setStatusTip ( tr ( " Pivote les textes sélectionnés à un angle précis " , " status bar tip " ) ) ;
m_find_element - > setStatusTip ( tr ( " Retrouve l'élément sélectionné dans le panel " , " status bar tip " ) ) ;
2017-08-03 17:36:08 +00:00
2018-06-20 18:03:39 +00:00
m_delete_selection - > setData ( " delete_selection " ) ;
m_rotate_selection - > setData ( " rotate_selection " ) ;
m_rotate_texts - > setData ( " rotate_selected_text " ) ;
m_find_element - > setData ( " find_selected_element " ) ;
m_edit_selection - > setData ( " edit_selected_element " ) ;
m_group_selected_texts - > setData ( " group_selected_texts " ) ;
2014-06-07 21:03:49 +00:00
2015-09-19 13:27:06 +00:00
connect ( & m_selection_actions_group , & QActionGroup : : triggered , this , & QETDiagramEditor : : selectionGroupTriggered ) ;
2014-06-07 21:03:49 +00:00
2015-09-19 13:27:06 +00:00
//Select Action
2018-12-04 22:33:11 +00:00
QAction * select_all = m_select_actions_group . addAction ( QET : : Icons : : EditSelectAll , tr ( " Tout sélectionner " ) ) ;
QAction * select_nothing = m_select_actions_group . addAction ( QET : : Icons : : EditSelectNone , tr ( " Désélectionner tout " ) ) ;
QAction * select_invert = m_select_actions_group . addAction ( QET : : Icons : : EditSelectInvert , tr ( " Inverser la sélection " ) ) ;
2014-06-07 21:03:49 +00:00
2018-06-20 18:03:39 +00:00
select_all - > setShortcut ( QKeySequence : : SelectAll ) ;
select_nothing - > setShortcut ( QKeySequence : : Deselect ) ;
select_invert - > setShortcut ( QKeySequence ( tr ( " Ctrl+I " ) ) ) ;
2014-06-07 21:03:49 +00:00
2018-06-20 18:03:39 +00:00
select_all - > setStatusTip ( tr ( " Sélectionne tous les éléments du folio " , " status bar tip " ) ) ;
select_nothing - > setStatusTip ( tr ( " Désélectionne tous les éléments du folio " , " status bar tip " ) ) ;
select_invert - > setStatusTip ( tr ( " Désélectionne les éléments sélectionnés et sélectionne les éléments non sélectionnés " , " status bar tip " ) ) ;
2014-06-07 21:03:49 +00:00
2018-06-20 18:03:39 +00:00
select_all - > setData ( " select_all " ) ;
select_nothing - > setData ( " deselect " ) ;
select_invert - > setData ( " invert_selection " ) ;
2014-06-07 21:03:49 +00:00
2015-09-19 13:27:06 +00:00
connect ( & m_select_actions_group , & QActionGroup : : triggered , this , & QETDiagramEditor : : selectGroupTriggered ) ;
//Zoom actions
QAction * zoom_in = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomIn , tr ( " Zoom avant " ) ) ;
QAction * zoom_out = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomOut , tr ( " Zoom arrière " ) ) ;
QAction * zoom_content = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomDraw , tr ( " Zoom sur le contenu " ) ) ;
QAction * zoom_fit = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomFitBest , tr ( " Zoom adapté " ) ) ;
QAction * zoom_reset = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomOriginal , tr ( " Pas de zoom " ) ) ;
2014-06-07 21:03:49 +00:00
m_zoom_action_toolBar < < zoom_content < < zoom_fit < < zoom_reset ;
2018-06-20 18:03:39 +00:00
zoom_in - > setShortcut ( QKeySequence : : ZoomIn ) ;
zoom_out - > setShortcut ( QKeySequence : : ZoomOut ) ;
zoom_content - > setShortcut ( QKeySequence ( tr ( " Ctrl+8 " ) ) ) ;
zoom_fit - > setShortcut ( QKeySequence ( tr ( " Ctrl+9 " ) ) ) ;
zoom_reset - > setShortcut ( QKeySequence ( tr ( " Ctrl+0 " ) ) ) ;
2014-06-07 21:03:49 +00:00
2018-06-20 18:03:39 +00:00
zoom_in - > setStatusTip ( tr ( " Agrandit le folio " , " status bar tip " ) ) ;
zoom_out - > setStatusTip ( tr ( " Rétrécit le folio " , " status bar tip " ) ) ;
zoom_content - > setStatusTip ( tr ( " Adapte le zoom de façon à afficher tout le contenu du folio indépendamment du cadre " ) ) ;
zoom_fit - > setStatusTip ( tr ( " Adapte le zoom exactement sur le cadre du folio " , " status bar tip " ) ) ;
zoom_reset - > setStatusTip ( tr ( " Restaure le zoom par défaut " , " status bar tip " ) ) ;
2014-06-07 21:03:49 +00:00
2015-09-19 13:27:06 +00:00
zoom_in - > setData ( " zoom_in " ) ;
zoom_out - > setData ( " zoom_out " ) ;
zoom_content - > setData ( " zoom_content " ) ;
zoom_fit - > setData ( " zoom_fit " ) ;
zoom_reset - > setData ( " zoom_reset " ) ;
connect ( & m_zoom_actions_group , & QActionGroup : : triggered , this , & QETDiagramEditor : : zoomGroupTriggered ) ;
//Adding action (add text, image, shape...)
QAction * add_text = m_add_item_actions_group . addAction ( QET : : Icons : : PartTextField , tr ( " Ajouter un champ de texte " ) ) ;
QAction * add_image = m_add_item_actions_group . addAction ( QET : : Icons : : adding_image , tr ( " Ajouter une image " ) ) ;
2016-08-23 00:10:33 +00:00
QAction * add_line = m_add_item_actions_group . addAction ( QET : : Icons : : PartLine , tr ( " Ajouter une ligne " , " Draw line " ) ) ;
2015-09-19 13:27:06 +00:00
QAction * add_rectangle = m_add_item_actions_group . addAction ( QET : : Icons : : PartRectangle , tr ( " Ajouter un rectangle " ) ) ;
QAction * add_ellipse = m_add_item_actions_group . addAction ( QET : : Icons : : PartEllipse , tr ( " Ajouter une ellipse " ) ) ;
QAction * add_polyline = m_add_item_actions_group . addAction ( QET : : Icons : : PartPolygon , tr ( " Ajouter une polyligne " ) ) ;
2019-05-18 19:35:57 +00:00
add_text - > setStatusTip ( tr ( " Ajoute un champ de texte sur le folio actuel " ) ) ;
add_image - > setStatusTip ( tr ( " Ajoute une image sur le folio actuel " ) ) ;
add_line - > setStatusTip ( tr ( " Ajoute une ligne sur le folio actuel " ) ) ;
add_rectangle - > setStatusTip ( tr ( " Ajoute un rectangle sur le folio actuel " ) ) ;
add_ellipse - > setStatusTip ( tr ( " Ajoute une ellipse sur le folio actuel " ) ) ;
add_polyline - > setStatusTip ( tr ( " Ajoute une polyligne sur le folio actuel " ) ) ;
2015-09-19 13:27:06 +00:00
add_text - > setData ( " text " ) ;
add_image - > setData ( " image " ) ;
add_line - > setData ( " line " ) ;
add_rectangle - > setData ( " rectangle " ) ;
add_ellipse - > setData ( " ellipse " ) ;
add_polyline - > setData ( " polyline " ) ;
2019-05-16 17:38:13 +00:00
2018-06-20 18:03:39 +00:00
for ( QAction * action : m_add_item_actions_group . actions ( ) ) {
action - > setCheckable ( true ) ;
}
2015-09-19 13:27:06 +00:00
connect ( & m_add_item_actions_group , & QActionGroup : : triggered , this , & QETDiagramEditor : : addItemGroupTriggered ) ;
2018-06-17 18:21:56 +00:00
//Depth action
2018-06-20 18:03:39 +00:00
m_depth_action_group = QET : : depthActionGroup ( this ) ;
2018-06-17 18:21:56 +00:00
m_depth_action_group - > setDisabled ( true ) ;
connect ( m_depth_action_group , & QActionGroup : : triggered , [ this ] ( QAction * action ) {
this - > currentDiagramView ( ) - > diagram ( ) - > changeZValue ( action - > data ( ) . value < QET : : DepthOption > ( ) ) ;
} ) ;
2018-09-25 16:05:24 +00:00
2018-12-04 22:33:11 +00:00
m_find = new QAction ( tr ( " Chercher/remplacer " ) , this ) ;
2018-09-25 16:05:24 +00:00
m_find - > setShortcut ( QKeySequence : : Find ) ;
connect ( m_find , & QAction : : triggered , [ this ] ( ) {
this - > m_search_and_replace_widget . setHidden ( ! m_search_and_replace_widget . isHidden ( ) ) ;
} ) ;
2009-04-03 19:30:25 +00:00
}
/**
2014-10-26 11:57:38 +00:00
* @ brief QETDiagramEditor : : setUpToolBar
*/
2018-06-17 18:21:56 +00:00
void QETDiagramEditor : : setUpToolBar ( )
{
main_tool_bar = new QToolBar ( tr ( " Outils " ) , this ) ;
main_tool_bar - > setObjectName ( " toolbar " ) ;
view_tool_bar = new QToolBar ( tr ( " Affichage " ) , this ) ;
view_tool_bar - > setObjectName ( " display " ) ;
diagram_tool_bar = new QToolBar ( tr ( " Schéma " ) , this ) ;
diagram_tool_bar - > setObjectName ( " diagram " ) ;
main_tool_bar - > addActions ( m_file_actions_group . actions ( ) ) ;
2018-06-20 18:03:39 +00:00
main_tool_bar - > addAction ( m_print ) ;
2018-06-17 18:21:56 +00:00
main_tool_bar - > addSeparator ( ) ;
main_tool_bar - > addAction ( undo ) ;
main_tool_bar - > addAction ( redo ) ;
main_tool_bar - > addSeparator ( ) ;
main_tool_bar - > addAction ( m_cut ) ;
main_tool_bar - > addAction ( m_copy ) ;
2018-06-20 18:03:39 +00:00
main_tool_bar - > addAction ( m_paste ) ;
2018-06-17 18:21:56 +00:00
main_tool_bar - > addSeparator ( ) ;
main_tool_bar - > addAction ( m_delete_selection ) ;
main_tool_bar - > addAction ( m_rotate_selection ) ;
2014-10-26 11:57:38 +00:00
// Modes selection / visualisation et zoom
2018-06-20 18:03:39 +00:00
view_tool_bar - > addAction ( m_mode_selection ) ;
view_tool_bar - > addAction ( m_mode_visualise ) ;
2018-06-17 18:21:56 +00:00
view_tool_bar - > addSeparator ( ) ;
view_tool_bar - > addAction ( m_draw_grid ) ;
view_tool_bar - > addAction ( m_grey_background ) ;
view_tool_bar - > addSeparator ( ) ;
view_tool_bar - > addActions ( m_zoom_action_toolBar ) ;
2018-06-20 18:03:39 +00:00
diagram_tool_bar - > addAction ( m_edit_diagram_properties ) ;
2018-06-17 18:21:56 +00:00
diagram_tool_bar - > addAction ( m_conductor_reset ) ;
diagram_tool_bar - > addAction ( m_auto_conductor ) ;
m_add_item_tool_bar = new QToolBar ( tr ( " Ajouter " ) , this ) ;
m_add_item_tool_bar - > setObjectName ( " adding " ) ;
m_add_item_tool_bar - > addActions ( m_add_item_actions_group . actions ( ) ) ;
m_depth_tool_bar = new QToolBar ( tr ( " Profondeur " , " toolbar title " ) ) ;
m_depth_tool_bar - > setObjectName ( " diagram_depth_toolbar " ) ;
m_depth_tool_bar - > addActions ( m_depth_action_group - > actions ( ) ) ;
addToolBar ( Qt : : TopToolBarArea , main_tool_bar ) ;
addToolBar ( Qt : : TopToolBarArea , view_tool_bar ) ;
addToolBar ( Qt : : TopToolBarArea , diagram_tool_bar ) ;
addToolBar ( Qt : : TopToolBarArea , m_add_item_tool_bar ) ;
addToolBar ( Qt : : TopToolBarArea , m_depth_tool_bar ) ;
2006-10-27 15:47:22 +00:00
}
/**
2014-10-26 11:57:38 +00:00
* @ brief QETDiagramEditor : : setUpMenu
*/
void QETDiagramEditor : : setUpMenu ( ) {
2012-02-13 22:12:37 +00:00
QMenu * menu_fichier = new QMenu ( tr ( " &Fichier " ) ) ;
2015-03-02 20:14:56 +00:00
QMenu * menu_edition = new QMenu ( tr ( " &Édition " ) ) ;
2012-02-13 22:12:37 +00:00
QMenu * menu_project = new QMenu ( tr ( " &Projet " ) ) ;
QMenu * menu_affichage = new QMenu ( tr ( " Afficha&ge " ) ) ;
//QMenu *menu_outils = new QMenu(tr("O&utils"));
2015-03-02 20:14:56 +00:00
windows_menu = new QMenu ( tr ( " Fe&nêtres " ) ) ;
2014-10-26 11:57:38 +00:00
2012-02-13 22:12:37 +00:00
insertMenu ( settings_menu_ , menu_fichier ) ;
insertMenu ( settings_menu_ , menu_edition ) ;
insertMenu ( settings_menu_ , menu_project ) ;
insertMenu ( settings_menu_ , menu_affichage ) ;
insertMenu ( help_menu_ , windows_menu ) ;
2014-10-26 11:57:38 +00:00
2014-06-07 21:03:49 +00:00
// File menu
2015-03-02 20:14:56 +00:00
QMenu * recentfile = menu_fichier - > addMenu ( QET : : Icons : : DocumentOpenRecent , tr ( " &Récemment ouverts " ) ) ;
2014-05-05 17:32:10 +00:00
recentfile - > addActions ( QETApp : : projectsRecentFiles ( ) - > menu ( ) - > actions ( ) ) ;
2008-07-30 11:51:27 +00:00
connect ( QETApp : : projectsRecentFiles ( ) , SIGNAL ( fileOpeningRequested ( const QString & ) ) , this , SLOT ( openRecentFile ( const QString & ) ) ) ;
2014-06-07 21:03:49 +00:00
menu_fichier - > addActions ( m_file_actions_group . actions ( ) ) ;
2006-10-27 15:47:22 +00:00
menu_fichier - > addSeparator ( ) ;
2007-09-29 12:54:01 +00:00
//menu_fichier -> addAction(import_diagram);
2018-06-20 18:03:39 +00:00
menu_fichier - > addAction ( m_export_diagram ) ;
2007-09-22 13:27:14 +00:00
//menu_fichier -> addSeparator();
2018-06-20 18:03:39 +00:00
menu_fichier - > addAction ( m_print ) ;
2006-10-27 15:47:22 +00:00
menu_fichier - > addSeparator ( ) ;
2018-06-20 18:03:39 +00:00
menu_fichier - > addAction ( m_quit_editor ) ;
2014-10-26 11:57:38 +00:00
2006-10-27 15:47:22 +00:00
// menu Edition
2007-09-29 12:54:01 +00:00
menu_edition - > addAction ( undo ) ;
menu_edition - > addAction ( redo ) ;
2006-10-27 15:47:22 +00:00
menu_edition - > addSeparator ( ) ;
2017-08-03 17:36:08 +00:00
menu_edition - > addAction ( m_cut ) ;
menu_edition - > addAction ( m_copy ) ;
2018-06-20 18:03:39 +00:00
menu_edition - > addAction ( m_paste ) ;
2006-10-27 15:47:22 +00:00
menu_edition - > addSeparator ( ) ;
2014-06-07 21:03:49 +00:00
menu_edition - > addActions ( m_select_actions_group . actions ( ) ) ;
2006-10-27 15:47:22 +00:00
menu_edition - > addSeparator ( ) ;
2014-06-07 21:03:49 +00:00
menu_edition - > addActions ( m_selection_actions_group . actions ( ) ) ;
2006-11-19 18:40:03 +00:00
menu_edition - > addSeparator ( ) ;
2017-08-03 17:36:08 +00:00
menu_edition - > addAction ( m_conductor_reset ) ;
2007-10-03 13:11:47 +00:00
menu_edition - > addSeparator ( ) ;
2018-06-20 18:03:39 +00:00
menu_edition - > addAction ( m_edit_diagram_properties ) ;
2014-06-07 21:03:49 +00:00
menu_edition - > addActions ( m_row_column_actions_group . actions ( ) ) ;
2018-06-17 18:21:56 +00:00
menu_edition - > addSeparator ( ) ;
menu_edition - > addActions ( m_depth_action_group - > actions ( ) ) ;
2018-09-25 16:05:24 +00:00
menu_edition - > addSeparator ( ) ;
menu_edition - > addAction ( m_find ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
// menu Projet
2018-06-20 18:03:39 +00:00
menu_project - > addAction ( m_project_edit_properties ) ;
menu_project - > addAction ( m_project_add_diagram ) ;
menu_project - > addAction ( m_remove_diagram_from_project ) ;
menu_project - > addAction ( m_clean_project ) ;
2013-04-11 09:35:10 +00:00
menu_project - > addSeparator ( ) ;
2018-06-20 18:03:39 +00:00
menu_project - > addAction ( m_project_folio_list ) ;
menu_project - > addAction ( m_project_nomenclature ) ;
menu_project - > addAction ( m_project_terminalBloc ) ;
2014-10-26 11:57:38 +00:00
2018-06-17 18:21:56 +00:00
main_tool_bar - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non la barre d'outils principale " ) ) ;
view_tool_bar - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non la barre d'outils Affichage " ) ) ;
diagram_tool_bar - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non la barre d'outils Schéma " ) ) ;
2016-08-30 21:42:35 +00:00
qdw_pa - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non le panel d'appareils " ) ) ;
qdw_undo - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non la liste des modifications " ) ) ;
2014-10-26 11:57:38 +00:00
2006-10-27 15:47:22 +00:00
// menu Affichage
2018-12-04 22:33:11 +00:00
QMenu * projects_view_mode = menu_affichage - > addMenu ( QET : : Icons : : ConfigureToolbars , tr ( " Afficher les projets " ) ) ;
2009-04-03 19:30:25 +00:00
projects_view_mode - > setTearOffEnabled ( true ) ;
2018-06-20 18:03:39 +00:00
projects_view_mode - > addAction ( m_windowed_view_mode ) ;
projects_view_mode - > addAction ( m_tabbed_view_mode ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
menu_affichage - > addSeparator ( ) ;
2018-06-20 18:03:39 +00:00
menu_affichage - > addAction ( m_mode_selection ) ;
menu_affichage - > addAction ( m_mode_visualise ) ;
2006-10-27 15:47:22 +00:00
menu_affichage - > addSeparator ( ) ;
2016-08-18 16:30:24 +00:00
menu_affichage - > addAction ( m_draw_grid ) ;
2015-06-25 18:23:47 +00:00
menu_affichage - > addAction ( m_grey_background ) ;
menu_affichage - > addSeparator ( ) ;
2014-06-07 21:03:49 +00:00
menu_affichage - > addActions ( m_zoom_actions_group . actions ( ) ) ;
2013-08-24 15:18:45 +00:00
2007-01-29 00:41:12 +00:00
// menu Fenetres
2007-09-29 12:54:01 +00:00
slot_updateWindowsMenu ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
2014-10-26 11:57:38 +00:00
Permet de quitter l ' application lors de la fermeture de la fenetre principale
@ param qce Le QCloseEvent correspondant a l ' evenement de fermeture
2006-10-27 15:47:22 +00:00
*/
2014-10-26 11:57:38 +00:00
void QETDiagramEditor : : closeEvent ( QCloseEvent * qce ) {
// quitte directement s'il n'y a aucun projet ouvert
bool can_quit = true ;
if ( openedProjects ( ) . count ( ) ) {
// s'assure que la fenetre soit visible s'il y a des projets a fermer
if ( ! isVisible ( ) | | isMinimized ( ) ) {
if ( isMaximized ( ) ) showMaximized ( ) ;
else showNormal ( ) ;
}
// sinon demande la permission de fermer chaque projet
2017-02-05 16:18:50 +00:00
foreach ( ProjectView * project , openedProjects ( ) ) {
2014-10-26 11:57:38 +00:00
if ( ! closeProject ( project ) ) {
can_quit = false ;
qce - > ignore ( ) ;
break ;
}
}
}
if ( can_quit ) {
writeSettings ( ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
qce - > accept ( ) ;
}
}
2013-03-27 21:20:53 +00:00
2014-10-26 11:57:38 +00:00
/**
2017-05-01 16:22:34 +00:00
* @ brief QETDiagramEditor : : event
* Reimplemented to :
* - Load elements collection when WindowActivate .
* @ param e
* @ return
*/
bool QETDiagramEditor : : event ( QEvent * e )
{
if ( m_first_show & & e - > type ( ) = = QEvent : : WindowActivate )
{
m_first_show = false ;
QTimer : : singleShot ( 250 , m_element_collection_widget , SLOT ( reload ( ) ) ) ;
}
2014-10-26 11:57:38 +00:00
return ( QETMainWindow : : event ( e ) ) ;
2006-10-27 15:47:22 +00:00
}
/**
2014-12-12 13:27:13 +00:00
* @ brief QETDiagramEditor : : save
* Ask the current active project to save
*/
2012-07-13 07:21:19 +00:00
void QETDiagramEditor : : save ( ) {
2018-03-24 14:35:32 +00:00
if ( ProjectView * project_view = currentProjectView ( ) ) {
2014-10-26 11:57:38 +00:00
QETResult saved = project_view - > save ( ) ;
2014-12-12 13:27:13 +00:00
2014-10-26 11:57:38 +00:00
if ( saved . isOk ( ) ) {
2017-01-10 14:56:34 +00:00
//save_file -> setDisabled(true);
2009-04-03 19:30:25 +00:00
QETApp : : projectsRecentFiles ( ) - > fileWasOpened ( project_view - > project ( ) - > filePath ( ) ) ;
2014-12-12 13:27:13 +00:00
2014-11-24 02:51:08 +00:00
QString title = ( project_view - > project ( ) - > title ( ) ) ;
if ( title . isEmpty ( ) ) title = " QElectroTech " ;
QString filePath = ( project_view - > project ( ) - > filePath ( ) ) ;
2015-03-02 20:14:56 +00:00
statusBar ( ) - > showMessage ( tr ( " Projet %1 enregistré dans le repertoire: %2. " ) . arg ( title ) . arg ( filePath ) , 2000 ) ;
2016-06-30 09:12:25 +00:00
m_element_collection_widget - > highlightUnusedElement ( ) ;
2014-12-12 13:27:13 +00:00
}
else {
2014-10-26 11:57:38 +00:00
showError ( saved ) ;
2009-04-03 19:30:25 +00:00
}
}
2006-10-27 15:47:22 +00:00
}
/**
2014-12-12 13:27:13 +00:00
* @ brief QETDiagramEditor : : saveAs
* Ask the current active project to save as
*/
2012-07-13 07:21:19 +00:00
void QETDiagramEditor : : saveAs ( ) {
2018-03-24 14:35:32 +00:00
if ( ProjectView * project_view = currentProjectView ( ) ) {
2012-07-13 07:21:19 +00:00
QETResult save_file = project_view - > saveAs ( ) ;
if ( save_file . isOk ( ) ) {
2009-04-03 19:30:25 +00:00
QETApp : : projectsRecentFiles ( ) - > fileWasOpened ( project_view - > project ( ) - > filePath ( ) ) ;
2014-12-12 13:27:13 +00:00
2014-11-24 02:51:08 +00:00
QString title = ( project_view - > project ( ) - > title ( ) ) ;
if ( title . isEmpty ( ) ) title = " QElectroTech " ;
QString filePath = ( project_view - > project ( ) - > filePath ( ) ) ;
2015-03-02 20:14:56 +00:00
statusBar ( ) - > showMessage ( tr ( " Projet %1 enregistré dans le repertoire: %2. " ) . arg ( title ) . arg ( filePath ) , 2000 ) ;
2016-06-30 09:12:25 +00:00
m_element_collection_widget - > highlightUnusedElement ( ) ;
2014-12-12 13:27:13 +00:00
}
else {
2012-07-13 07:21:19 +00:00
showError ( save_file ) ;
2008-08-23 18:17:00 +00:00
}
}
2006-10-27 15:47:22 +00:00
}
2009-04-03 19:30:25 +00:00
/**
2014-04-11 09:51:21 +00:00
* @ brief QETDiagramEditor : : newProject
* Create an empty project
* @ return
*/
2009-04-03 19:30:25 +00:00
bool QETDiagramEditor : : newProject ( ) {
2014-04-11 09:51:21 +00:00
// create new project without diagram
2019-03-16 10:50:30 +00:00
QETProject * new_project = new QETProject ( this ) ;
2009-04-03 19:30:25 +00:00
2014-04-11 09:51:21 +00:00
// Set default properties for new diagram
2014-10-26 11:57:38 +00:00
new_project - > setDefaultBorderProperties ( BorderProperties : : defaultProperties ( ) ) ;
new_project - > setDefaultConductorProperties ( ConductorProperties : : defaultProperties ( ) ) ;
new_project - > setDefaultTitleBlockProperties ( TitleBlockProperties : : defaultProperties ( ) ) ;
new_project - > setDefaultReportProperties ( ReportProperties : : defaultProperties ( ) ) ;
new_project - > setDefaultXRefProperties ( XRefProperties : : defaultProperties ( ) ) ;
2009-04-03 19:30:25 +00:00
2014-02-11 05:10:16 +00:00
// add new diagram
2014-02-08 23:54:15 +00:00
new_project - > addNewDiagram ( ) ;
2009-04-03 19:30:25 +00:00
return ( addProject ( new_project ) ) ;
2006-10-27 15:47:22 +00:00
}
2008-07-30 11:51:27 +00:00
/**
Slot utilise pour ouvrir un fichier recent .
Transfere filepath au slot openAndAddDiagram seulement si cet editeur est
actif
@ param filepath Fichier a ouvrir
@ see openAndAddDiagram
*/
bool QETDiagramEditor : : openRecentFile ( const QString & filepath ) {
2013-01-03 21:53:26 +00:00
// small hack to prevent all diagram editors from trying to topen the required
// recent file at the same time
2008-07-30 11:51:27 +00:00
if ( qApp - > activeWindow ( ) ! = this ) return ( false ) ;
2009-04-03 19:30:25 +00:00
return ( openAndAddProject ( filepath ) ) ;
2008-07-30 11:51:27 +00:00
}
2006-10-27 15:47:22 +00:00
/**
Cette fonction demande un nom de fichier a ouvrir a l ' utilisateur
@ return true si l ' ouverture a reussi , false sinon
*/
2009-04-03 19:30:25 +00:00
bool QETDiagramEditor : : openProject ( ) {
// demande un chemin de fichier a ouvrir a l'utilisateur
QString filepath = QFileDialog : : getOpenFileName (
2006-10-27 15:47:22 +00:00
this ,
tr ( " Ouvrir un fichier " ) ,
2007-10-21 12:53:57 +00:00
open_dialog_dir . absolutePath ( ) ,
2015-06-21 15:29:09 +00:00
tr ( " Projets QElectroTech (*.qet);;Fichiers XML (*.xml);;Tous les fichiers (*) " )
2006-10-27 15:47:22 +00:00
) ;
2009-04-03 19:30:25 +00:00
if ( filepath . isEmpty ( ) ) return ( false ) ;
// retient le dossier contenant le dernier projet ouvert
open_dialog_dir = QDir ( filepath ) ;
2008-07-17 19:25:57 +00:00
2009-04-03 19:30:25 +00:00
// ouvre le fichier
return ( openAndAddProject ( filepath ) ) ;
}
/**
Ferme un projet
@ param project_view Projet a fermer
@ return true si la fermeture du projet a reussi , false sinon
Note : cette methode renvoie true si project est nul
*/
bool QETDiagramEditor : : closeProject ( ProjectView * project_view ) {
if ( project_view ) {
activateProject ( project_view ) ;
2015-05-07 22:15:00 +00:00
if ( QMdiSubWindow * sub_window = subWindowForWidget ( project_view ) ) {
2009-04-03 19:30:25 +00:00
return ( sub_window - > close ( ) ) ;
}
}
return ( true ) ;
}
/**
Ferme un projet
@ param project projet a fermer
@ return true si la fermeture du fichier a reussi , false sinon
Note : cette methode renvoie true si project est nul
*/
bool QETDiagramEditor : : closeProject ( QETProject * project ) {
if ( ProjectView * project_view = findProject ( project ) ) {
return ( closeProject ( project_view ) ) ;
}
return ( true ) ;
2008-07-17 19:25:57 +00:00
}
2009-04-03 19:30:25 +00:00
/**
Ouvre un projet depuis un fichier et l ' ajoute a cet editeur
@ param filepath Chemin du projet a ouvrir
@ param interactive true pour afficher des messages a l ' utilisateur , false sinon
2008-07-17 19:25:57 +00:00
@ return true si l ' ouverture a reussi , false sinon
*/
2018-04-04 15:07:52 +00:00
bool QETDiagramEditor : : openAndAddProject ( const QString & filepath , bool interactive )
{
2009-04-03 19:30:25 +00:00
if ( filepath . isEmpty ( ) ) return ( false ) ;
2006-10-27 15:47:22 +00:00
2009-04-03 19:30:25 +00:00
QFileInfo filepath_info ( filepath ) ;
2018-04-04 15:07:52 +00:00
//Check if project is not open in another editor
if ( QETDiagramEditor * diagram_editor = QETApp : : diagramEditorForFile ( filepath ) )
{
if ( diagram_editor = = this )
{
if ( ProjectView * project_view = viewForFile ( filepath ) )
{
2009-04-03 19:30:25 +00:00
activateWidget ( project_view ) ;
2008-07-20 11:37:31 +00:00
show ( ) ;
activateWindow ( ) ;
}
2006-10-27 15:47:22 +00:00
return ( false ) ;
2018-04-04 15:07:52 +00:00
}
else
{
//Ask to the other editor to display the file
2009-04-03 19:30:25 +00:00
return ( diagram_editor - > openAndAddProject ( filepath ) ) ;
2006-10-27 15:47:22 +00:00
}
}
2018-04-04 15:07:52 +00:00
// check the file exists
if ( ! filepath_info . exists ( ) )
{
if ( interactive )
{
2015-03-02 20:14:56 +00:00
QET : : QetMessageBox : : critical (
2013-01-03 21:53:26 +00:00
this ,
tr ( " Impossible d'ouvrir le fichier " , " message box title " ) ,
QString (
tr ( " Il semblerait que le fichier %1 que vous essayez d'ouvrir "
" n'existe pas ou plus. " )
) . arg ( filepath )
) ;
}
2013-01-04 14:11:03 +00:00
return ( false ) ;
2013-01-03 21:53:26 +00:00
}
2018-04-04 15:07:52 +00:00
//Check if file readable
if ( ! filepath_info . isReadable ( ) )
{
2009-04-03 19:30:25 +00:00
if ( interactive ) {
2015-03-02 20:14:56 +00:00
QET : : QetMessageBox : : critical (
2009-04-03 19:30:25 +00:00
this ,
2013-01-03 21:53:26 +00:00
tr ( " Impossible d'ouvrir le fichier " , " message box title " ) ,
2009-04-03 19:30:25 +00:00
tr ( " Il semblerait que le fichier que vous essayez d'ouvrir ne "
" soit pas accessible en lecture. Il est donc impossible de "
2015-03-02 20:14:56 +00:00
" l'ouvrir. Veuillez vérifier les permissions du fichier. " )
2009-04-03 19:30:25 +00:00
) ;
}
return ( false ) ;
}
2018-04-04 15:07:52 +00:00
//Check if file is read only
if ( ! filepath_info . isWritable ( ) )
{
2009-04-03 19:30:25 +00:00
if ( interactive ) {
2015-03-02 20:14:56 +00:00
QET : : QetMessageBox : : warning (
2009-04-03 19:30:25 +00:00
this ,
2013-01-03 21:53:26 +00:00
tr ( " Ouverture du projet en lecture seule " , " message box title " ) ,
2009-04-03 19:30:25 +00:00
tr ( " Il semblerait que le projet que vous essayez d'ouvrir ne "
2015-03-02 20:14:56 +00:00
" soit pas accessible en écriture. Il sera donc ouvert en "
2009-04-03 19:30:25 +00:00
" lecture seule. " )
) ;
}
}
2018-04-04 15:07:52 +00:00
//Create the project
DialogWaiting : : instance ( this ) ;
2018-07-30 15:24:29 +00:00
QETProject * project = new QETProject ( filepath ) ;
2018-04-04 15:07:52 +00:00
if ( project - > state ( ) ! = QETProject : : Ok )
{
if ( interactive & & project - > state ( ) ! = QETProject : : FileOpenDiscard )
{
2015-03-02 20:14:56 +00:00
QET : : QetMessageBox : : warning (
2009-04-03 19:30:25 +00:00
this ,
2015-03-02 20:14:56 +00:00
tr ( " Échec de l'ouverture du projet " , " message box title " ) ,
2009-04-03 19:30:25 +00:00
QString (
tr (
" Il semblerait que le fichier %1 ne soit pas un fichier "
2015-03-02 20:14:56 +00:00
" projet QElectroTech. Il ne peut donc être ouvert. " ,
2009-04-03 19:30:25 +00:00
" message box content "
)
) . arg ( filepath )
) ;
2006-10-27 15:47:22 +00:00
}
2011-08-26 19:06:35 +00:00
delete project ;
2018-04-04 15:07:52 +00:00
DialogWaiting : : dropInstance ( ) ;
2006-10-27 15:47:22 +00:00
return ( false ) ;
}
2013-04-11 09:35:10 +00:00
2009-04-03 19:30:25 +00:00
QETApp : : projectsRecentFiles ( ) - > fileWasOpened ( filepath ) ;
2018-04-04 15:07:52 +00:00
addProject ( project ) ;
DialogWaiting : : dropInstance ( ) ;
return true ;
2006-10-27 15:47:22 +00:00
}
/**
2014-02-08 23:54:15 +00:00
Ajoute un projetmoveDiagramUp (
2009-04-03 19:30:25 +00:00
@ param project projet a ajouter
2011-03-15 20:06:40 +00:00
@ param update_panel Whether the elements panel should be warned this
project has been added . Defaults to true .
2006-10-27 15:47:22 +00:00
*/
2011-03-15 20:06:40 +00:00
bool QETDiagramEditor : : addProject ( QETProject * project , bool update_panel ) {
2009-04-03 19:30:25 +00:00
// enregistre le projet
QETApp : : registerProject ( project ) ;
// cree un ProjectView pour visualiser le projet
2018-07-30 15:24:29 +00:00
ProjectView * project_view = new ProjectView ( project ) ;
2009-04-03 19:30:25 +00:00
addProjectView ( project_view ) ;
2014-11-27 18:46:30 +00:00
undo_group . addStack ( project - > undoStack ( ) ) ;
2015-12-16 17:16:15 +00:00
m_element_collection_widget - > addProject ( project ) ;
2009-04-03 19:30:25 +00:00
// met a jour le panel d'elements
2011-03-15 20:06:40 +00:00
if ( update_panel ) {
pa - > elementsPanel ( ) . projectWasOpened ( project ) ;
2018-04-12 16:24:44 +00:00
if ( currentDiagramView ( ) ! = nullptr )
2016-07-13 14:57:27 +00:00
m_autonumbering_dock - > setProject ( project , project_view ) ;
2011-03-15 20:06:40 +00:00
}
2009-04-03 19:30:25 +00:00
return ( true ) ;
}
/**
@ return la liste des projets ouverts dans cette fenetre
*/
QList < ProjectView * > QETDiagramEditor : : openedProjects ( ) const {
QList < ProjectView * > result ;
2018-06-20 18:03:39 +00:00
QList < QMdiSubWindow * > window_list ( m_workspace . subWindowList ( ) ) ;
2017-02-05 16:18:50 +00:00
foreach ( QMdiSubWindow * window , window_list ) {
2018-07-30 15:24:29 +00:00
if ( ProjectView * project_view = qobject_cast < ProjectView * > ( window - > widget ( ) ) ) {
2009-04-03 19:30:25 +00:00
result < < project_view ;
}
}
return ( result ) ;
}
/**
@ return Le projet actuellement edite ( = qui a le focus dans l ' interface
MDI ) ou 0 s ' il n ' y en a pas
*/
2018-03-24 14:35:32 +00:00
ProjectView * QETDiagramEditor : : currentProjectView ( ) const {
2018-06-20 18:03:39 +00:00
QMdiSubWindow * current_window = m_workspace . activeSubWindow ( ) ;
2017-08-05 02:06:59 +00:00
if ( ! current_window ) return ( nullptr ) ;
2009-04-03 19:30:25 +00:00
QWidget * current_widget = current_window - > widget ( ) ;
2017-08-05 02:06:59 +00:00
if ( ! current_widget ) return ( nullptr ) ;
2009-04-03 19:30:25 +00:00
2018-07-30 15:24:29 +00:00
if ( ProjectView * project_view = qobject_cast < ProjectView * > ( current_widget ) ) {
2009-04-03 19:30:25 +00:00
return ( project_view ) ;
}
2017-08-05 02:06:59 +00:00
return ( nullptr ) ;
2006-10-27 15:47:22 +00:00
}
2018-09-25 16:05:24 +00:00
/**
* @ brief QETDiagramEditor : : currentProject
* @ return the current edited project .
* This function can return nullptr .
*/
QETProject * QETDiagramEditor : : currentProject ( ) const
{
ProjectView * view = currentProjectView ( ) ;
if ( view ) {
return view - > project ( ) ;
}
else {
return nullptr ;
}
}
2006-10-27 15:47:22 +00:00
/**
2009-04-03 19:30:25 +00:00
@ return Le schema actuellement edite ( = l ' onglet ouvert dans le projet
courant ) ou 0 s ' il n ' y en a pas
2006-10-27 15:47:22 +00:00
*/
2018-04-12 16:24:44 +00:00
DiagramView * QETDiagramEditor : : currentDiagramView ( ) const {
2018-03-24 14:35:32 +00:00
if ( ProjectView * project_view = currentProjectView ( ) ) {
2009-04-03 19:30:25 +00:00
return ( project_view - > currentDiagram ( ) ) ;
}
2017-08-05 02:06:59 +00:00
return ( nullptr ) ;
2009-04-03 19:30:25 +00:00
}
2013-02-12 18:37:08 +00:00
/**
@ return the selected element in the current diagram view , or 0 if :
* no diagram is being viewed in this editor .
* no element is selected
* more than one element is selected
*/
2017-12-05 20:51:54 +00:00
Element * QETDiagramEditor : : currentElement ( ) const
{
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2017-12-05 20:51:54 +00:00
if ( ! dv )
return ( nullptr ) ;
2013-02-12 18:37:08 +00:00
2018-04-12 16:24:44 +00:00
QList < Element * > selected_elements = DiagramContent ( dv - > diagram ( ) ) . m_elements ;
2017-12-05 20:51:54 +00:00
if ( selected_elements . count ( ) ! = 1 )
return ( nullptr ) ;
2013-02-12 18:37:08 +00:00
return ( selected_elements . first ( ) ) ;
}
2009-04-03 19:30:25 +00:00
/**
Cette methode permet de retrouver le projet contenant un schema donne .
@ param diagram_view Schema dont il faut retrouver
@ return la vue sur le projet contenant ce schema ou 0 s ' il n ' y en a pas
*/
ProjectView * QETDiagramEditor : : findProject ( DiagramView * diagram_view ) const {
2017-02-05 16:18:50 +00:00
foreach ( ProjectView * project_view , openedProjects ( ) ) {
2017-02-18 13:30:38 +00:00
if ( project_view - > diagram_views ( ) . contains ( diagram_view ) ) {
2009-04-03 19:30:25 +00:00
return ( project_view ) ;
}
}
2017-08-05 02:06:59 +00:00
return ( nullptr ) ;
2009-04-03 19:30:25 +00:00
}
/**
Cette methode permet de retrouver le projet contenant un schema donne .
@ param diagram Schema dont il faut retrouver
@ return la vue sur le projet contenant ce schema ou 0 s ' il n ' y en a pas
*/
ProjectView * QETDiagramEditor : : findProject ( Diagram * diagram ) const {
2017-02-05 16:18:50 +00:00
foreach ( ProjectView * project_view , openedProjects ( ) ) {
2017-02-18 13:30:38 +00:00
foreach ( DiagramView * diagram_view , project_view - > diagram_views ( ) ) {
2009-04-03 19:30:25 +00:00
if ( diagram_view - > diagram ( ) = = diagram ) {
return ( project_view ) ;
}
}
}
2017-08-05 02:06:59 +00:00
return ( nullptr ) ;
2009-04-03 19:30:25 +00:00
}
/**
@ param project Projet dont il faut trouver la vue
@ return la vue du projet passe en parametre
*/
ProjectView * QETDiagramEditor : : findProject ( QETProject * project ) const {
2017-02-05 16:18:50 +00:00
foreach ( ProjectView * opened_project , openedProjects ( ) ) {
2009-04-03 19:30:25 +00:00
if ( opened_project - > project ( ) = = project ) {
return ( opened_project ) ;
}
}
2017-08-05 02:06:59 +00:00
return ( nullptr ) ;
2009-04-03 19:30:25 +00:00
}
/**
@ param filepath Chemin de fichier d ' un projet
@ return le ProjectView correspondant au chemin passe en parametre , ou 0 si
celui - ci n ' a pas ete trouve
*/
ProjectView * QETDiagramEditor : : findProject ( const QString & filepath ) const {
2017-02-05 16:18:50 +00:00
foreach ( ProjectView * opened_project , openedProjects ( ) ) {
2009-04-03 19:30:25 +00:00
if ( QETProject * project = opened_project - > project ( ) ) {
if ( project - > filePath ( ) = = filepath ) {
return ( opened_project ) ;
}
}
}
2017-08-05 02:06:59 +00:00
return ( nullptr ) ;
2009-04-03 19:30:25 +00:00
}
/**
@ param widget Widget a rechercher dans la zone MDI
@ return La sous - fenetre accueillant le widget passe en parametre , ou 0 si
celui - ci n ' a pas ete trouve .
*/
QMdiSubWindow * QETDiagramEditor : : subWindowForWidget ( QWidget * widget ) const {
2018-06-20 18:03:39 +00:00
foreach ( QMdiSubWindow * sub_window , m_workspace . subWindowList ( ) ) {
2009-04-03 19:30:25 +00:00
if ( sub_window - > widget ( ) = = widget ) {
return ( sub_window ) ;
}
}
2017-08-05 02:06:59 +00:00
return ( nullptr ) ;
2009-04-03 19:30:25 +00:00
}
/**
@ param widget Widget a activer
*/
void QETDiagramEditor : : activateWidget ( QWidget * widget ) {
QMdiSubWindow * sub_window = subWindowForWidget ( widget ) ;
if ( sub_window ) {
2018-06-20 18:03:39 +00:00
m_workspace . setActiveSubWindow ( sub_window ) ;
2009-04-03 19:30:25 +00:00
}
}
2015-09-19 13:27:06 +00:00
void QETDiagramEditor : : zoomGroupTriggered ( QAction * action )
{
QString value = action - > data ( ) . toString ( ) ;
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2006-10-27 15:47:22 +00:00
2015-09-19 13:27:06 +00:00
if ( ! dv | | value . isEmpty ( ) ) return ;
2006-10-27 15:47:22 +00:00
2015-09-19 13:27:06 +00:00
if ( value = = " zoom_in " )
2015-11-18 09:51:53 +00:00
dv - > zoom ( 1.15 ) ;
2015-09-19 13:27:06 +00:00
else if ( value = = " zoom_out " )
2015-11-18 09:51:53 +00:00
dv - > zoom ( 0.85 ) ;
2015-09-19 13:27:06 +00:00
else if ( value = = " zoom_content " )
dv - > zoomContent ( ) ;
else if ( value = = " zoom_fit " )
dv - > zoomFit ( ) ;
else if ( value = = " zoom_reset " )
dv - > zoomReset ( ) ;
2006-10-27 15:47:22 +00:00
}
2012-08-12 11:46:42 +00:00
/**
2015-09-19 13:27:06 +00:00
* @ brief QETDiagramEditor : : selectGroupTriggered
* This slot is called when selection need to change .
* @ param action : Action that describes what to do .
*/
void QETDiagramEditor : : selectGroupTriggered ( QAction * action )
{
QString value = action - > data ( ) . toString ( ) ;
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2012-08-12 11:46:42 +00:00
2015-09-19 13:27:06 +00:00
if ( ! dv | | value . isEmpty ( ) ) return ;
2006-10-27 15:47:22 +00:00
2015-09-19 13:27:06 +00:00
if ( value = = " select_all " )
dv - > selectAll ( ) ;
else if ( value = = " deselect " )
dv - > selectNothing ( ) ;
else if ( value = = " invert_selection " )
dv - > selectInvert ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
2015-09-19 13:27:06 +00:00
* @ brief QETDiagramEditor : : addItemGroupTriggered
* This slot is called when an item must be added to the curent diagram ,
* this slot use the DVEventInterface to add item
* @ param action : Action that describe the item to add .
*/
void QETDiagramEditor : : addItemGroupTriggered ( QAction * action )
{
QString value = action - > data ( ) . toString ( ) ;
2015-11-07 12:28:43 +00:00
2018-04-12 16:24:44 +00:00
if ( Q_UNLIKELY ( ! currentDiagramView ( ) | | ! currentDiagramView ( ) - > diagram ( ) | | value . isEmpty ( ) ) ) return ;
2015-11-07 12:28:43 +00:00
2018-04-12 16:24:44 +00:00
Diagram * d = currentDiagramView ( ) - > diagram ( ) ;
2015-11-07 12:28:43 +00:00
DiagramEventInterface * diagram_event = nullptr ;
if ( value = = " line " )
diagram_event = new DiagramEventAddShape ( d , QetShapeItem : : Line ) ;
else if ( value = = " rectangle " )
diagram_event = new DiagramEventAddShape ( d , QetShapeItem : : Rectangle ) ;
else if ( value = = " ellipse " )
diagram_event = new DiagramEventAddShape ( d , QetShapeItem : : Ellipse ) ;
2019-05-16 17:38:13 +00:00
else if ( value = = " polyline " )
2019-05-17 21:22:10 +00:00
{
2015-11-07 12:28:43 +00:00
diagram_event = new DiagramEventAddShape ( d , QetShapeItem : : Polygon ) ;
2019-05-18 10:49:01 +00:00
statusBar ( ) - > showMessage ( tr ( " Double-click pour terminer la forme, Click droit pour annuler le dernier point " ) ) ;
2019-05-17 21:22:10 +00:00
connect ( diagram_event , & DiagramEventInterface : : destroyed , [ this ] ( ) {
statusBar ( ) - > clearMessage ( ) ;
} ) ;
}
2015-11-12 17:01:08 +00:00
else if ( value = = " image " )
{
2018-07-30 15:24:29 +00:00
DiagramEventAddImage * deai = new DiagramEventAddImage ( d ) ;
2015-11-12 17:01:08 +00:00
if ( deai - > isNull ( ) )
{
delete deai ;
action - > setChecked ( false ) ;
return ;
}
else
diagram_event = deai ;
}
2015-11-12 17:29:48 +00:00
else if ( value = = " text " )
diagram_event = new DiagramEventAddText ( d ) ;
2015-11-07 12:28:43 +00:00
if ( diagram_event )
{
d - > setEventInterface ( diagram_event ) ;
2019-01-14 18:25:43 +00:00
connect ( diagram_event , & DiagramEventInterface : : destroyed , [ action ] ( ) { action - > setChecked ( false ) ; } ) ;
2015-09-19 13:27:06 +00:00
}
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
2015-09-19 13:27:06 +00:00
* @ brief QETDiagramEditor : : selectionGroupTriggered
* This slot is called when an action should be made on the current selection
* @ param action : Action that describe the action to do .
*/
void QETDiagramEditor : : selectionGroupTriggered ( QAction * action )
{
QString value = action - > data ( ) . toString ( ) ;
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2017-12-05 21:41:29 +00:00
Diagram * diagram = dv - > diagram ( ) ;
DiagramContent dc ( diagram ) ;
2015-09-19 13:27:06 +00:00
if ( ! dv | | value . isEmpty ( ) ) return ;
if ( value = = " delete_selection " )
2017-12-05 21:41:29 +00:00
{
diagram - > clearSelection ( ) ;
diagram - > undoStack ( ) . push ( new DeleteQGraphicsItemCommand ( diagram , dc ) ) ;
dv - > adjustSceneRect ( ) ;
}
2015-09-19 13:27:06 +00:00
else if ( value = = " rotate_selection " )
2017-12-05 20:51:54 +00:00
{
2018-07-30 15:24:29 +00:00
RotateSelectionCommand * c = new RotateSelectionCommand ( diagram ) ;
2017-12-05 20:51:54 +00:00
if ( c - > isValid ( ) )
2017-12-05 21:41:29 +00:00
diagram - > undoStack ( ) . push ( c ) ;
2017-12-05 20:51:54 +00:00
}
2015-09-19 13:27:06 +00:00
else if ( value = = " rotate_selected_text " )
2017-12-05 21:41:29 +00:00
diagram - > undoStack ( ) . push ( new RotateTextsCommand ( diagram ) ) ;
2018-08-23 19:41:58 +00:00
else if ( value = = " find_selected_element " & & currentElement ( ) )
findElementInPanel ( currentElement ( ) - > location ( ) ) ;
2015-09-19 13:27:06 +00:00
else if ( value = = " edit_selected_element " )
dv - > editSelection ( ) ;
2018-05-18 21:46:36 +00:00
else if ( value = = " group_selected_texts " )
{
QList < DynamicElementTextItem * > deti_list = dc . m_element_texts . toList ( ) ;
if ( deti_list . size ( ) < = 1 )
return ;
diagram - > undoStack ( ) . push ( new AddTextsGroupCommand ( deti_list . first ( ) - > parentElement ( ) , tr ( " Groupe " ) , deti_list ) ) ;
}
2006-10-27 15:47:22 +00:00
}
2015-09-19 13:27:06 +00:00
void QETDiagramEditor : : rowColumnGroupTriggered ( QAction * action )
{
QString value = action - > data ( ) . toString ( ) ;
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2015-09-19 13:27:06 +00:00
2018-04-04 11:02:40 +00:00
if ( ! dv | | value . isEmpty ( ) | | dv - > diagram ( ) - > isReadOnly ( ) ) return ;
2015-09-19 13:27:06 +00:00
2018-04-04 11:02:40 +00:00
Diagram * d = dv - > diagram ( ) ;
BorderProperties old_bp = d - > border_and_titleblock . exportBorder ( ) ;
BorderProperties new_bp = d - > border_and_titleblock . exportBorder ( ) ;
2015-09-19 13:27:06 +00:00
if ( value = = " add_column " )
2018-04-04 11:02:40 +00:00
new_bp . columns_count + = 1 ;
2015-09-19 13:27:06 +00:00
else if ( value = = " remove_column " )
2018-04-04 11:02:40 +00:00
new_bp . columns_count - = 1 ;
2015-09-19 13:27:06 +00:00
else if ( value = = " add_row " )
2018-04-04 11:02:40 +00:00
new_bp . rows_count + = 1 ;
2015-09-19 13:27:06 +00:00
else if ( value = = " remove_row " )
2018-04-04 11:02:40 +00:00
new_bp . rows_count - = 1 ;
d - > undoStack ( ) . push ( new ChangeBorderCommand ( d , old_bp , new_bp ) ) ;
2010-02-11 23:35:04 +00:00
}
2006-10-27 15:47:22 +00:00
/**
2014-12-26 19:41:00 +00:00
* @ brief QETDiagramEditor : : slot_updateActions
* Manage actions
*/
void QETDiagramEditor : : slot_updateActions ( )
{
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2018-03-24 14:35:32 +00:00
ProjectView * pv = currentProjectView ( ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
bool opened_project = pv ;
bool opened_diagram = dv ;
bool editable_project = ( pv & & ! pv - > project ( ) - > isReadOnly ( ) ) ;
2014-02-08 18:51:06 +00:00
2018-03-31 11:40:55 +00:00
m_close_file - > setEnabled ( opened_project ) ;
2018-06-20 18:03:39 +00:00
m_save_file - > setEnabled ( opened_project ) ;
m_save_file_as - > setEnabled ( opened_project ) ;
m_project_edit_properties - > setEnabled ( opened_project ) ;
2018-06-07 13:48:12 +00:00
//prj_terminalBloc -> setEnabled(opened_project);
2018-08-22 13:34:12 +00:00
m_rotate_texts - > setEnabled ( editable_project ) ;
2018-06-20 18:03:39 +00:00
m_project_add_diagram - > setEnabled ( editable_project ) ;
m_remove_diagram_from_project - > setEnabled ( editable_project ) ;
m_clean_project - > setEnabled ( editable_project ) ;
m_project_folio_list - > setEnabled ( opened_project ) ;
m_project_nomenclature - > setEnabled ( editable_project ) ;
m_export_diagram - > setEnabled ( opened_diagram ) ;
m_print - > setEnabled ( opened_diagram ) ;
m_edit_diagram_properties - > setEnabled ( opened_diagram ) ;
m_project_nomenclature - > setEnabled ( editable_project ) ;
2014-12-26 19:41:00 +00:00
m_zoom_actions_group . setEnabled ( opened_diagram ) ;
m_select_actions_group . setEnabled ( opened_diagram ) ;
m_add_item_actions_group . setEnabled ( editable_project ) ;
m_row_column_actions_group . setEnabled ( editable_project ) ;
2015-06-25 18:23:47 +00:00
m_grey_background - > setEnabled ( opened_diagram ) ;
2014-12-26 19:41:00 +00:00
2015-01-11 11:10:57 +00:00
2014-12-26 19:41:00 +00:00
slot_updateUndoStack ( ) ;
2007-10-28 00:16:32 +00:00
slot_updateModeActions ( ) ;
slot_updatePasteAction ( ) ;
slot_updateComplexActions ( ) ;
2016-07-13 14:57:27 +00:00
slot_updateAutoNumDock ( ) ;
}
/**
* @ brief QETDiagramEditor : : slot_updateAutoNumDock
* Update Auto Num Dock Widget when changing Project
*/
void QETDiagramEditor : : slot_updateAutoNumDock ( ) {
2018-06-20 18:03:39 +00:00
if ( m_workspace . subWindowList ( ) . indexOf ( m_workspace . activeSubWindow ( ) ) ! = activeSubWindowIndex ) {
activeSubWindowIndex = m_workspace . subWindowList ( ) . indexOf ( m_workspace . activeSubWindow ( ) ) ;
2018-04-12 16:24:44 +00:00
if ( currentProjectView ( ) ! = nullptr & & currentDiagramView ( ) ! = nullptr ) {
2018-03-24 14:35:32 +00:00
m_autonumbering_dock - > setProject ( currentProjectView ( ) - > project ( ) , currentProjectView ( ) ) ;
2016-07-13 14:57:27 +00:00
}
}
2007-10-28 00:16:32 +00:00
}
2014-01-05 15:00:46 +00:00
/**
* @ brief QETDiagramEditor : : slot_updateUndoStack
* Update the undo stack view
*/
2014-12-26 19:41:00 +00:00
void QETDiagramEditor : : slot_updateUndoStack ( )
{
2018-03-24 14:35:32 +00:00
if ( currentProjectView ( ) )
undo_group . setActiveStack ( currentProjectView ( ) - > project ( ) - > undoStack ( ) ) ;
2014-01-05 15:00:46 +00:00
}
2007-10-28 00:16:32 +00:00
/**
2015-02-20 18:44:44 +00:00
* @ brief QETDiagramEditor : : slot_updateComplexActions
* Manage the actions who need some conditions to be enable or not .
* This method does nothing if there is no project opened
*/
2017-08-03 17:36:08 +00:00
void QETDiagramEditor : : slot_updateComplexActions ( )
{
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2017-08-03 17:36:08 +00:00
if ( ! dv )
{
QList < QAction * > action_list ;
2018-05-18 21:46:36 +00:00
action_list < < m_conductor_reset < < m_find_element < < m_cut < < m_copy < < m_delete_selection < < m_rotate_selection < < m_edit_selection < < m_group_selected_texts ;
2017-08-03 17:36:08 +00:00
for ( QAction * action : action_list )
action - > setEnabled ( false ) ;
return ;
}
Diagram * diagram_ = dv - > diagram ( ) ;
2017-12-05 20:51:54 +00:00
DiagramContent dc ( diagram_ ) ;
2017-08-03 17:36:08 +00:00
bool ro = diagram_ - > isReadOnly ( ) ;
2015-05-07 22:15:00 +00:00
2015-02-20 18:44:44 +00:00
//Number of selected conductors
2017-08-03 17:36:08 +00:00
int selected_conductors_count = diagram_ - > selectedConductors ( ) . count ( ) ;
m_conductor_reset - > setEnabled ( ! ro & & selected_conductors_count ) ;
2007-10-28 00:16:32 +00:00
2015-02-20 18:44:44 +00:00
// number of selected elements
2017-12-05 20:51:54 +00:00
int selected_elements_count = dc . count ( DiagramContent : : Elements ) ;
2017-08-03 17:36:08 +00:00
m_find_element - > setEnabled ( selected_elements_count = = 1 ) ;
2013-02-12 18:37:08 +00:00
2015-02-20 18:44:44 +00:00
//Action that need items (elements, conductors, texts...) selected, to be enabled
2018-04-04 11:02:40 +00:00
bool copiable_items = dc . hasCopiableItems ( ) ;
2017-12-05 21:41:29 +00:00
bool deletable_items = dc . hasDeletableItems ( ) ;
2017-08-03 17:36:08 +00:00
m_cut - > setEnabled ( ! ro & & copiable_items ) ;
m_copy - > setEnabled ( copiable_items ) ;
m_delete_selection - > setEnabled ( ! ro & & deletable_items ) ;
m_rotate_selection - > setEnabled ( ! ro & & diagram_ - > canRotateSelection ( ) ) ;
2014-02-06 23:55:02 +00:00
2017-12-05 20:51:54 +00:00
//Action that need selected texts or texts group
QList < DiagramTextItem * > texts = DiagramContent ( diagram_ ) . selectedTexts ( ) ;
QList < ElementTextItemGroup * > groups = DiagramContent ( diagram_ ) . selectedTextsGroup ( ) ;
int selected_texts = texts . count ( ) ;
int selected_conductor_texts = 0 ; for ( DiagramTextItem * dti : texts ) { if ( dti - > type ( ) = = ConductorTextItem : : Type ) selected_conductor_texts + + ; }
int selected_dynamic_elmt_text = 0 ; for ( DiagramTextItem * dti : texts ) { if ( dti - > type ( ) = = DynamicElementTextItem : : Type ) selected_dynamic_elmt_text + + ; }
m_rotate_texts - > setEnabled ( ! ro & & ( selected_texts | | groups . size ( ) ) ) ;
2018-05-18 21:46:36 +00:00
//Action that need only element text selected
QList < DynamicElementTextItem * > deti_list = dc . m_element_texts . toList ( ) ;
if ( deti_list . size ( ) > 1 & & dc . count ( ) = = deti_list . count ( ) )
{
Element * elmt = deti_list . first ( ) - > parentElement ( ) ;
bool ok = true ;
for ( DynamicElementTextItem * deti : deti_list )
{
if ( elmt ! = deti - > parentElement ( ) )
ok = false ;
}
m_group_selected_texts - > setEnabled ( ! ro & & ok ) ;
}
else
m_group_selected_texts - > setDisabled ( true ) ;
2013-09-10 14:44:25 +00:00
2015-02-20 18:44:44 +00:00
// actions need only one editable item
2017-12-05 20:51:54 +00:00
int selected_image = dc . count ( DiagramContent : : Images ) ;
2014-03-06 14:04:19 +00:00
2017-12-05 20:51:54 +00:00
int selected_shape = dc . count ( DiagramContent : : Shapes ) ;
2015-02-20 18:44:44 +00:00
int selected_editable = selected_elements_count +
2018-03-25 14:33:49 +00:00
( selected_texts - selected_conductor_texts - selected_dynamic_elmt_text ) +
2015-02-20 18:44:44 +00:00
selected_image +
selected_shape +
selected_conductors_count ;
2013-09-10 14:44:25 +00:00
2015-02-20 18:44:44 +00:00
if ( selected_editable = = 1 )
{
2017-08-03 17:36:08 +00:00
m_edit_selection - > setEnabled ( true ) ;
2015-02-20 18:44:44 +00:00
//edit element
if ( selected_elements_count )
{
2017-08-03 17:36:08 +00:00
m_edit_selection - > setText ( tr ( " Éditer l'élement " , " edit element " ) ) ;
m_edit_selection - > setIcon ( QET : : Icons : : ElementEdit ) ;
2013-09-10 14:44:25 +00:00
}
2015-02-20 18:44:44 +00:00
//edit text field
else if ( selected_texts )
{
2017-08-03 17:36:08 +00:00
m_edit_selection - > setText ( tr ( " Éditer le champ de texte " , " edit text field " ) ) ;
m_edit_selection - > setIcon ( QET : : Icons : : EditText ) ;
2013-09-10 14:44:25 +00:00
}
2015-02-20 18:44:44 +00:00
//edit image
else if ( selected_image )
{
2017-08-03 17:36:08 +00:00
m_edit_selection - > setText ( tr ( " Éditer l'image " , " edit image " ) ) ;
m_edit_selection - > setIcon ( QET : : Icons : : resize_image ) ;
2013-09-10 14:44:25 +00:00
}
2015-02-20 18:44:44 +00:00
//edit conductor
else if ( selected_conductors_count )
{
2017-08-03 17:36:08 +00:00
m_edit_selection - > setText ( tr ( " Éditer le conducteur " , " edit conductor " ) ) ;
2017-11-27 23:41:24 +00:00
m_edit_selection - > setIcon ( QET : : Icons : : ConductorEdit ) ;
2015-02-20 18:44:44 +00:00
}
2013-09-10 14:44:25 +00:00
}
2015-02-20 18:44:44 +00:00
//not an editable item
else
{
2017-08-03 17:36:08 +00:00
m_edit_selection - > setText ( tr ( " Éditer l'objet sélectionné " , " edit selected item " ) ) ;
m_edit_selection - > setIcon ( QET : : Icons : : ElementEdit ) ;
m_edit_selection - > setEnabled ( false ) ;
2013-09-10 14:44:25 +00:00
}
2018-06-17 18:21:56 +00:00
//Actions for edit Z value
QList < QGraphicsItem * > list = dc . items ( DiagramContent : : SelectedOnly | \
DiagramContent : : Elements | \
DiagramContent : : Shapes | \
DiagramContent : : Images ) ;
m_depth_action_group - > setEnabled ( list . isEmpty ( ) ? false : true ) ;
2009-04-03 19:30:25 +00:00
}
2007-10-28 00:16:32 +00:00
/**
2015-01-11 11:10:57 +00:00
* @ brief QETDiagramEditor : : slot_updateModeActions
* Manage action who need an opened diagram or project to be updated
*/
2015-06-25 18:23:47 +00:00
void QETDiagramEditor : : slot_updateModeActions ( )
{
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2006-10-27 15:47:22 +00:00
2015-01-11 11:10:57 +00:00
if ( ! dv )
2007-10-28 00:16:32 +00:00
grp_visu_sel - > setEnabled ( false ) ;
2015-01-11 11:10:57 +00:00
else
{
2015-06-21 15:29:09 +00:00
switch ( ( int ) ( dv - > dragMode ( ) ) )
2015-01-11 11:10:57 +00:00
{
2006-10-27 15:47:22 +00:00
case QGraphicsView : : NoDrag :
2007-10-28 00:16:32 +00:00
grp_visu_sel - > setEnabled ( false ) ;
2006-10-27 15:47:22 +00:00
break ;
case QGraphicsView : : ScrollHandDrag :
2007-10-28 00:16:32 +00:00
grp_visu_sel - > setEnabled ( true ) ;
2018-06-20 18:03:39 +00:00
m_mode_visualise - > setChecked ( true ) ;
2006-10-27 15:47:22 +00:00
break ;
case QGraphicsView : : RubberBandDrag :
2007-10-28 00:16:32 +00:00
grp_visu_sel - > setEnabled ( true ) ;
2018-06-20 18:03:39 +00:00
m_mode_selection - > setChecked ( true ) ;
2006-10-27 15:47:22 +00:00
break ;
}
}
2015-01-11 11:10:57 +00:00
2018-03-24 14:35:32 +00:00
if ( ProjectView * pv = currentProjectView ( ) )
2015-01-11 11:10:57 +00:00
{
m_auto_conductor - > setEnabled ( true ) ;
m_auto_conductor - > setChecked ( pv - > project ( ) - > autoConductor ( ) ) ;
}
else
m_auto_conductor - > setDisabled ( true ) ;
2007-10-28 00:16:32 +00:00
}
/**
Gere les actions ayant besoin du presse - papier
*/
void QETDiagramEditor : : slot_updatePasteAction ( ) {
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2009-04-03 19:30:25 +00:00
bool editable_diagram = ( dv & & ! dv - > diagram ( ) - > isReadOnly ( ) ) ;
2007-11-03 20:20:34 +00:00
// pour coller, il faut un schema ouvert et un schema dans le presse-papier
2018-06-20 18:03:39 +00:00
m_paste - > setEnabled ( editable_diagram & & Diagram : : clipboardMayContainDiagram ( ) ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
2014-12-26 19:41:00 +00:00
* @ brief QETDiagramEditor : : addProjectView
* 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 )
{
2009-04-03 19:30:25 +00:00
if ( ! project_view ) return ;
2014-10-26 11:57:38 +00:00
2017-02-18 13:30:38 +00:00
foreach ( DiagramView * dv , project_view - > diagram_views ( ) )
2009-04-03 19:30:25 +00:00
diagramWasAdded ( dv ) ;
2007-01-29 00:41:12 +00:00
2014-12-26 19:41:00 +00:00
//Manage the close event of project
2009-04-03 19:30:25 +00:00
connect ( project_view , SIGNAL ( projectClosed ( ProjectView * ) ) , this , SLOT ( projectWasClosed ( ProjectView * ) ) ) ;
2014-12-26 19:41:00 +00:00
//Manage the adding of diagram
connect ( project_view , SIGNAL ( diagramAdded ( DiagramView * ) ) , this , SLOT ( diagramWasAdded ( DiagramView * ) ) ) ;
if ( QETProject * project = project_view - > project ( ) )
2009-04-03 19:30:25 +00:00
connect ( project , SIGNAL ( readOnlyChanged ( QETProject * , bool ) ) , this , SLOT ( slot_updateActions ( ) ) ) ;
2014-12-26 19:41:00 +00:00
//Manage request for edit or find element and titleblock
2017-05-01 11:42:55 +00:00
connect ( project_view , & ProjectView : : findElementRequired , this , & QETDiagramEditor : : findElementInPanel ) ;
connect ( project_view , & ProjectView : : editElementRequired , this , & QETDiagramEditor : : editElementInEditor ) ;
2012-01-25 07:29:50 +00:00
2014-12-26 19:41:00 +00:00
// display error messages sent by the project view
2012-07-13 07:21:19 +00:00
connect ( project_view , SIGNAL ( errorEncountered ( QString ) ) , this , SLOT ( showError ( const QString & ) ) ) ;
2014-01-18 19:04:39 +00:00
2014-12-26 19:41:00 +00:00
//We maximise the new window if the current window is inexistent or maximized
2018-06-20 18:03:39 +00:00
QWidget * current_window = m_workspace . activeSubWindow ( ) ;
2014-12-26 19:41:00 +00:00
bool maximise = ( ( ! current_window ) | | ( current_window - > windowState ( ) & Qt : : WindowMaximized ) ) ;
//Add the new window
2018-06-20 18:03:39 +00:00
QMdiSubWindow * sub_window = m_workspace . addSubWindow ( project_view ) ;
2014-12-26 19:41:00 +00:00
sub_window - > setWindowIcon ( project_view - > windowIcon ( ) ) ;
sub_window - > systemMenu ( ) - > clear ( ) ;
2018-03-31 11:40:55 +00:00
//By defaut QMdiSubWindow have a QAction "close" with shortcut QKeySequence::Close
//But the QAction m_close_file of this class have the same shortcut too.
//We remove the shortcut of the QAction of QMdiSubWindow for avoid conflic
for ( QAction * act : sub_window - > actions ( ) )
{
if ( act - > shortcut ( ) = = QKeySequence : : Close )
act - > setShortcut ( QKeySequence ( ) ) ;
}
2014-12-26 19:41:00 +00:00
//Display the new window
if ( maximise ) project_view - > showMaximized ( ) ;
else project_view - > show ( ) ;
2008-07-20 11:37:31 +00:00
}
/**
@ return la liste des fichiers edites par cet editeur de schemas
*/
QList < QString > QETDiagramEditor : : editedFiles ( ) const {
QList < QString > edited_files_list ;
2017-02-05 16:18:50 +00:00
foreach ( ProjectView * project_view , openedProjects ( ) ) {
2009-04-03 19:30:25 +00:00
QString diagram_file ( project_view - > project ( ) - > filePath ( ) ) ;
2008-07-20 11:37:31 +00:00
if ( ! diagram_file . isEmpty ( ) ) {
edited_files_list < < QFileInfo ( diagram_file ) . canonicalFilePath ( ) ;
}
}
return ( edited_files_list ) ;
}
/**
@ param filepath Un chemin de fichier
Note : si filepath est une chaine vide , cette methode retourne 0.
2009-04-03 19:30:25 +00:00
@ return le ProjectView editant le fichier filepath , ou 0 si ce fichier n ' est
2008-07-20 11:37:31 +00:00
pas edite par cet editeur de schemas .
*/
2009-04-03 19:30:25 +00:00
ProjectView * QETDiagramEditor : : viewForFile ( const QString & filepath ) const {
2017-08-05 02:06:59 +00:00
if ( filepath . isEmpty ( ) ) return ( nullptr ) ;
2008-07-20 11:37:31 +00:00
QString searched_can_file_path = QFileInfo ( filepath ) . canonicalFilePath ( ) ;
2013-01-04 14:11:03 +00:00
if ( searched_can_file_path . isEmpty ( ) ) {
// QFileInfo returns an empty path for non-existent files
2017-08-05 02:06:59 +00:00
return ( nullptr ) ;
2013-01-04 14:11:03 +00:00
}
2017-02-05 16:18:50 +00:00
foreach ( ProjectView * project_view , openedProjects ( ) ) {
2009-04-03 19:30:25 +00:00
QString project_can_file_path = QFileInfo ( project_view - > project ( ) - > filePath ( ) ) . canonicalFilePath ( ) ;
if ( project_can_file_path = = searched_can_file_path ) {
return ( project_view ) ;
2008-07-20 11:37:31 +00:00
}
}
2017-08-05 02:06:59 +00:00
return ( nullptr ) ;
2008-07-20 11:37:31 +00:00
}
2016-08-18 16:30:24 +00:00
/**
* @ brief QETDiagramEditor : : drawGrid
* @ return true if the grid of folio must be displayed
*/
bool QETDiagramEditor : : drawGrid ( ) const {
return m_draw_grid - > isChecked ( ) ;
}
2019-03-16 10:50:30 +00:00
/**
* @ brief QETDiagramEditor : : openBackupFiles
* @ param backup_files
*/
void QETDiagramEditor : : openBackupFiles ( QList < KAutoSaveFile * > backup_files )
{
for ( KAutoSaveFile * file : backup_files )
{
//Create the project
DialogWaiting : : instance ( this ) ;
QETProject * project = new QETProject ( file , this ) ;
if ( project - > state ( ) ! = QETProject : : Ok )
{
if ( project - > state ( ) ! = QETProject : : FileOpenDiscard )
{
QET : : QetMessageBox : : warning ( this , tr ( " Échec de l'ouverture du projet " , " message box title " ) ,
QString ( tr ( " Une erreur est survenue lors de l'ouverture du fichier %1. " ,
" message box content " ) ) . arg ( file - > managedFile ( ) . fileName ( ) ) ) ;
}
delete project ;
DialogWaiting : : dropInstance ( ) ;
}
addProject ( project ) ;
DialogWaiting : : dropInstance ( ) ;
}
}
2006-11-11 13:56:40 +00:00
/**
met a jour le menu " Fenetres "
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : slot_updateWindowsMenu ( ) {
2006-10-27 15:47:22 +00:00
// nettoyage du menu
2017-02-05 16:18:50 +00:00
foreach ( QAction * a , windows_menu - > actions ( ) ) windows_menu - > removeAction ( a ) ;
2006-10-27 15:47:22 +00:00
// actions de fermeture
2018-03-31 11:40:55 +00:00
windows_menu - > addAction ( m_close_file ) ;
2007-09-29 12:54:01 +00:00
//windows_menu -> addAction(closeAllAct);
2006-10-27 15:47:22 +00:00
// actions de reorganisation des fenetres
2007-09-29 12:54:01 +00:00
windows_menu - > addSeparator ( ) ;
2018-06-20 18:03:39 +00:00
windows_menu - > addAction ( m_tile_window ) ;
windows_menu - > addAction ( m_cascade_window ) ;
2006-10-27 15:47:22 +00:00
2007-10-28 00:16:32 +00:00
// actions de deplacement entre les fenetres
2007-09-29 12:54:01 +00:00
windows_menu - > addSeparator ( ) ;
2018-06-20 18:03:39 +00:00
windows_menu - > addAction ( m_next_window ) ;
windows_menu - > addAction ( m_previous_window ) ;
2006-10-27 15:47:22 +00:00
// liste des fenetres
2009-04-03 19:30:25 +00:00
QList < ProjectView * > windows = openedProjects ( ) ;
2007-09-29 12:54:01 +00:00
2018-06-20 18:03:39 +00:00
m_tile_window - > setEnabled ( ! windows . isEmpty ( ) & & m_workspace . viewMode ( ) = = QMdiArea : : SubWindowView ) ;
m_cascade_window - > setEnabled ( ! windows . isEmpty ( ) & & m_workspace . viewMode ( ) = = QMdiArea : : SubWindowView ) ;
m_next_window - > setEnabled ( windows . count ( ) > 1 ) ;
m_previous_window - > setEnabled ( windows . count ( ) > 1 ) ;
2007-09-29 12:54:01 +00:00
if ( ! windows . isEmpty ( ) ) windows_menu - > addSeparator ( ) ;
2018-07-30 15:24:29 +00:00
QActionGroup * windows_actions = new QActionGroup ( this ) ;
2017-02-05 16:18:50 +00:00
foreach ( ProjectView * project_view , windows ) {
2009-04-03 19:30:25 +00:00
QString pv_title = project_view - > windowTitle ( ) ;
QAction * action = windows_menu - > addAction ( pv_title ) ;
2007-11-01 23:56:19 +00:00
windows_actions - > addAction ( action ) ;
2015-03-02 20:14:56 +00:00
action - > setStatusTip ( QString ( tr ( " Active le projet « %1 » " ) ) . arg ( pv_title ) ) ;
2006-10-27 15:47:22 +00:00
action - > setCheckable ( true ) ;
2018-03-24 14:35:32 +00:00
action - > setChecked ( project_view = = currentProjectView ( ) ) ;
2006-10-27 15:47:22 +00:00
connect ( action , SIGNAL ( triggered ( ) ) , & windowMapper , SLOT ( map ( ) ) ) ;
2009-04-03 19:30:25 +00:00
windowMapper . setMapping ( action , project_view ) ;
2006-10-27 15:47:22 +00:00
}
}
2006-10-28 19:39:43 +00:00
2009-04-03 19:30:25 +00:00
/**
Edite les proprietes du schema diagram
@ param diagram_view schema dont il faut editer les proprietes
*/
void QETDiagramEditor : : editDiagramProperties ( DiagramView * diagram_view ) {
if ( ProjectView * project_view = findProject ( diagram_view ) ) {
activateProject ( project_view ) ;
project_view - > editDiagramProperties ( diagram_view ) ;
}
}
/**
Edite les proprietes du schema diagram
@ param diagram schema dont il faut editer les proprietes
*/
void QETDiagramEditor : : editDiagramProperties ( Diagram * diagram ) {
if ( ProjectView * project_view = findProject ( diagram ) ) {
activateProject ( project_view ) ;
project_view - > editDiagramProperties ( diagram ) ;
2008-08-10 15:07:59 +00:00
}
2006-11-19 18:40:03 +00:00
}
2007-01-28 00:53:17 +00:00
2009-04-03 19:30:25 +00:00
/**
Affiche les projets dans des fenetres .
*/
void QETDiagramEditor : : setWindowedMode ( ) {
2018-06-20 18:03:39 +00:00
m_workspace . setViewMode ( QMdiArea : : SubWindowView ) ;
m_windowed_view_mode - > setChecked ( true ) ;
2009-04-03 19:30:25 +00:00
slot_updateWindowsMenu ( ) ;
}
/**
Affiche les projets dans des onglets .
*/
void QETDiagramEditor : : setTabbedMode ( ) {
2018-06-20 18:03:39 +00:00
m_workspace . setViewMode ( QMdiArea : : TabbedView ) ;
m_tabbed_view_mode - > setChecked ( true ) ;
2009-04-03 19:30:25 +00:00
slot_updateWindowsMenu ( ) ;
}
2015-09-16 15:11:13 +00:00
/**
* @ brief QETDiagramEditor : : readSettings
* Read the settings
*/
void QETDiagramEditor : : readSettings ( )
{
QSettings settings ;
2007-11-12 15:21:14 +00:00
// dimensions et position de la fenetre
QVariant geometry = settings . value ( " diagrameditor/geometry " ) ;
if ( geometry . isValid ( ) ) restoreGeometry ( geometry . toByteArray ( ) ) ;
// etat de la fenetre (barres d'outils, docks...)
QVariant state = settings . value ( " diagrameditor/state " ) ;
if ( state . isValid ( ) ) restoreState ( state . toByteArray ( ) ) ;
2009-04-03 19:30:25 +00:00
// gestion des projets (onglets ou fenetres)
2009-04-05 12:33:20 +00:00
bool tabbed = settings . value ( " diagrameditor/viewmode " , " tabbed " ) = = " tabbed " ;
2009-04-03 19:30:25 +00:00
if ( tabbed ) {
setTabbedMode ( ) ;
} else {
setWindowedMode ( ) ;
}
2007-11-12 15:21:14 +00:00
}
2015-09-16 15:11:13 +00:00
/**
* @ brief QETDiagramEditor : : writeSettings
* Write the settings
*/
void QETDiagramEditor : : writeSettings ( )
{
QSettings settings ;
2007-11-12 15:21:14 +00:00
settings . setValue ( " diagrameditor/geometry " , saveGeometry ( ) ) ;
settings . setValue ( " diagrameditor/state " , saveState ( ) ) ;
}
2007-11-18 00:22:19 +00:00
2009-04-03 19:30:25 +00:00
/**
Active le schema passe en parametre
@ param diagram Schema a activer
*/
void QETDiagramEditor : : activateDiagram ( Diagram * diagram ) {
if ( QETProject * project = diagram - > project ( ) ) {
if ( ProjectView * project_view = findProject ( project ) ) {
activateWidget ( project_view ) ;
project_view - > showDiagram ( diagram ) ;
}
} else {
/// @todo gerer ce cas
}
}
/**
Active le projet passe en parametre
@ param project Projet a activer
*/
void QETDiagramEditor : : activateProject ( QETProject * project ) {
activateProject ( findProject ( project ) ) ;
}
/**
Active le projet passe en parametre
@ param project_view Projet a activer
*/
void QETDiagramEditor : : activateProject ( ProjectView * project_view ) {
if ( ! project_view ) return ;
activateWidget ( project_view ) ;
}
/**
Gere la fermeture d ' une ProjectView
@ param project_view ProjectView fermee
*/
void QETDiagramEditor : : projectWasClosed ( ProjectView * project_view ) {
QETProject * project = project_view - > project ( ) ;
if ( project ) {
pa - > elementsPanel ( ) . projectWasClosed ( project ) ;
2015-12-16 17:16:15 +00:00
m_element_collection_widget - > removeProject ( project ) ;
2014-11-27 18:46:30 +00:00
undo_group . removeStack ( project - > undoStack ( ) ) ;
2009-04-03 19:30:25 +00:00
QETApp : : unregisterProject ( project ) ;
}
project_view - > deleteLater ( ) ;
project - > deleteLater ( ) ;
}
/**
Edite les proprietes du projet project_view .
@ param project_view Vue sur le projet dont il faut editer les proprietes
*/
void QETDiagramEditor : : editProjectProperties ( ProjectView * project_view ) {
if ( ! project_view ) return ;
activateProject ( project_view ) ;
project_view - > editProjectProperties ( ) ;
}
/**
Edite les proprietes du projet project .
@ param project Projet dont il faut editer les proprietes
*/
void QETDiagramEditor : : editProjectProperties ( QETProject * project ) {
editProjectProperties ( findProject ( project ) ) ;
}
/**
Ajoute un nouveau schema a un projet
@ param project Projet auquel il faut ajouter un schema
*/
void QETDiagramEditor : : addDiagramToProject ( QETProject * project ) {
if ( ! project ) return ;
// recupere le ProjectView visualisant ce projet
if ( ProjectView * project_view = findProject ( project ) ) {
// affiche le projet en question
activateProject ( project ) ;
// ajoute un schema au projet
project_view - > addNewDiagram ( ) ;
}
}
/**
Supprime un schema de son projet
@ param diagram Schema a supprimer
*/
void QETDiagramEditor : : removeDiagram ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
// affiche le schema en question
project_view - > showDiagram ( diagram ) ;
// supprime le schema
project_view - > removeDiagram ( diagram ) ;
}
}
}
2010-02-28 16:13:45 +00:00
/**
Change l ' ordre des schemas d ' un projet , en decalant le schema vers le haut /
la gauche
@ param diagram Schema a decaler vers le haut / la gauche
*/
void QETDiagramEditor : : moveDiagramUp ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
if ( diagram_project - > isReadOnly ( ) ) return ;
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
project_view - > moveDiagramUp ( diagram ) ;
}
}
}
/**
Change l ' ordre des schemas d ' un projet , en decalant le schema vers le bas /
la droite
@ param diagram Schema a decaler vers le bas / la droite
*/
void QETDiagramEditor : : moveDiagramDown ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
if ( diagram_project - > isReadOnly ( ) ) return ;
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
project_view - > moveDiagramDown ( diagram ) ;
}
}
}
2015-03-04 06:00:25 +00:00
/**
Change l ' ordre des schemas d ' un projet , en decalant le schema vers le haut /
la gauche en position 0
@ param diagram Schema a decaler vers le haut / la gauche en position 0
*/
void QETDiagramEditor : : moveDiagramUpTop ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
if ( diagram_project - > isReadOnly ( ) ) return ;
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
project_view - > moveDiagramUpTop ( diagram ) ;
}
}
}
2014-12-14 17:01:11 +00:00
/**
Change l ' ordre des schemas d ' un projet , en decalant le schema vers le haut /
la gauche x10
@ param diagram Schema a decaler vers le haut / la gauche x10
*/
void QETDiagramEditor : : moveDiagramUpx10 ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
if ( diagram_project - > isReadOnly ( ) ) return ;
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
project_view - > moveDiagramUpx10 ( diagram ) ;
}
}
}
/**
Change l ' ordre des schemas d ' un projet , en decalant le schema vers le bas /
la droite x10
@ param diagram Schema a decaler vers le bas / la droite x10
*/
void QETDiagramEditor : : moveDiagramDownx10 ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
if ( diagram_project - > isReadOnly ( ) ) return ;
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
project_view - > moveDiagramDownx10 ( diagram ) ;
}
}
}
2016-09-14 13:58:44 +00:00
void QETDiagramEditor : : reloadOldElementPanel ( ) {
pa - > reloadAndFilter ( ) ;
}
2009-04-03 19:30:25 +00:00
/**
Supprime le schema courant du projet courant
*/
void QETDiagramEditor : : removeDiagramFromProject ( ) {
2018-03-24 14:35:32 +00:00
if ( ProjectView * current_project = currentProjectView ( ) ) {
2009-04-03 19:30:25 +00:00
if ( DiagramView * current_diagram = current_project - > currentDiagram ( ) ) {
2014-02-10 11:48:05 +00:00
bool isFolioList = false ;
2014-02-11 05:10:16 +00:00
// if diagram to remove is a "folio list sheet", then set a flag.
2014-10-19 11:25:03 +00:00
if ( dynamic_cast < DiagramFolioList * > ( current_diagram - > diagram ( ) ) )
2014-02-10 11:48:05 +00:00
isFolioList = true ;
2014-02-11 05:10:16 +00:00
2009-04-03 19:30:25 +00:00
current_project - > removeDiagram ( current_diagram ) ;
2014-02-11 05:10:16 +00:00
// if the removed diagram was a folio sheet, then delete all the remaining folio sheets also.
2014-02-10 11:48:05 +00:00
if ( isFolioList ) {
2017-02-18 13:30:38 +00:00
foreach ( DiagramView * diag , current_project - > diagram_views ( ) ) {
2014-10-19 11:25:03 +00:00
if ( dynamic_cast < DiagramFolioList * > ( diag - > diagram ( ) ) ) {
2014-02-10 11:48:05 +00:00
current_project - > removeDiagram ( diag ) ;
}
}
2014-02-11 05:10:16 +00:00
// else if after diagram removal, the total diagram quantity becomes a factor of 58, then
// remove one (last) folio sheet.
2017-02-18 13:30:38 +00:00
} else if ( current_project - > diagram_views ( ) . size ( ) % 58 = = 0 ) {
foreach ( DiagramView * diag , current_project - > diagram_views ( ) ) {
2018-07-30 15:24:29 +00:00
DiagramFolioList * ptr = dynamic_cast < DiagramFolioList * > ( diag - > diagram ( ) ) ;
2014-02-10 13:58:30 +00:00
if ( ptr & & ptr - > getId ( ) = = current_project - > project ( ) - > getFolioSheetsQuantity ( ) - 1 ) {
2014-02-10 11:48:05 +00:00
current_project - > removeDiagram ( diag ) ;
}
}
}
2009-04-03 19:30:25 +00:00
}
}
}
/**
2014-12-26 19:41:00 +00:00
* @ brief QETDiagramEditor : : diagramWasAdded
* Manage the adding of diagram view in a project
* @ param dv , added diagram view
*/
void QETDiagramEditor : : diagramWasAdded ( DiagramView * dv )
{
2015-05-07 22:15:00 +00:00
connect ( dv , SIGNAL ( selectionChanged ( ) ) , this , SLOT ( selectionChanged ( ) ) ) ;
2014-12-26 19:41:00 +00:00
connect ( dv , SIGNAL ( modeChanged ( ) ) , this , SLOT ( slot_updateModeActions ( ) ) ) ;
2009-04-03 19:30:25 +00:00
}
2009-05-19 19:00:37 +00:00
/**
2017-05-01 11:42:55 +00:00
* @ brief QETDiagramEditor : : findElementInPanel
* Find the item for @ location in the element panel
* @ param location
*/
void QETDiagramEditor : : findElementInPanel ( const ElementsLocation & location )
{
m_element_collection_widget - > setCurrentLocation ( location ) ;
2009-05-19 19:00:37 +00:00
}
2009-07-08 09:41:20 +00:00
/**
Lance l ' editeur d ' element pour l ' element filename
@ param location Emplacement de l ' element a editer
*/
void QETDiagramEditor : : editElementInEditor ( const ElementsLocation & location ) {
2010-03-28 16:27:48 +00:00
QETApp : : instance ( ) - > openElementLocations ( QList < ElementsLocation > ( ) < < location ) ;
2009-07-08 09:41:20 +00:00
}
2013-02-12 18:37:08 +00:00
/**
Launch an element editor to edit the selected element in the current
diagram view .
*/
void QETDiagramEditor : : editSelectedElementInEditor ( ) {
2018-08-23 19:41:58 +00:00
if ( Element * selected_element = currentElement ( ) ) {
2013-02-12 18:37:08 +00:00
editElementInEditor ( selected_element - > location ( ) ) ;
}
}
2012-07-13 07:21:19 +00:00
/**
Show the error message contained in \ a result .
*/
void QETDiagramEditor : : showError ( const QETResult & result ) {
if ( result . isOk ( ) ) return ;
showError ( result . errorMessage ( ) ) ;
}
/**
Show the \ a error message .
*/
void QETDiagramEditor : : showError ( const QString & error ) {
if ( error . isEmpty ( ) ) return ;
2015-03-02 20:14:56 +00:00
QET : : QetMessageBox : : critical ( this , tr ( " Erreur " , " message box title " ) , error ) ;
2012-07-13 07:21:19 +00:00
}
2014-12-26 19:41:00 +00:00
/**
* @ 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 ( ) ;
}
2015-05-07 22:15:00 +00:00
/**
* @ brief QETDiagramEditor : : selectionChanged
* This slot is called when a diagram selection was changed .
*/
void QETDiagramEditor : : selectionChanged ( )
{
slot_updateComplexActions ( ) ;
2018-04-12 16:24:44 +00:00
DiagramView * dv = currentDiagramView ( ) ;
2015-05-07 22:15:00 +00:00
if ( dv & & dv - > diagram ( ) )
m_selection_properties_editor - > setDiagram ( dv - > diagram ( ) ) ;
}
2016-08-30 21:42:35 +00:00
/**
2018-06-20 18:03:39 +00:00
* @ brief QETDiagramEditor : : generateTerminalBlock
2016-08-30 21:42:35 +00:00
*/
2018-06-20 18:03:39 +00:00
void QETDiagramEditor : : generateTerminalBlock ( )
{
bool success ;
2018-07-30 15:24:29 +00:00
QProcess * process = new QProcess ( qApp ) ;
2018-06-20 18:03:39 +00:00
// If launched under control:
//connect(process, SIGNAL(errorOcurred(int error)), this, SLOT(slot_generateTerminalBlock_error()));
//process->start("qet_tb_generator");
2019-09-08 18:29:29 +02:00
# ifdef Q_OS_MACOS
2018-06-20 18:03:39 +00:00
if ( openedProjects ( ) . count ( ) ) {
success = process - > startDetached ( " /Library/Frameworks/Python.framework/Versions/3.5/bin/qet_tb_generator " , { ( QETDiagramEditor : : currentProjectView ( ) - > project ( ) - > filePath ( ) ) } ) ;
}
else {
success = process - > startDetached ( " /Library/Frameworks/Python.framework/Versions/3.5/bin/qet_tb_generator " ) ;
}
2016-10-13 00:08:29 +00:00
# else
2018-06-20 18:03:39 +00:00
if ( openedProjects ( ) . count ( ) ) {
success = process - > startDetached ( " qet_tb_generator " , { ( QETDiagramEditor : : currentProjectView ( ) - > project ( ) - > filePath ( ) ) } ) ;
}
else {
success = process - > startDetached ( " qet_tb_generator " ) ;
}
2016-10-13 00:08:29 +00:00
# endif
2018-06-20 18:03:39 +00:00
if ( ! success ) {
2019-05-20 14:54:04 +00:00
# if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
2018-06-20 18:03:39 +00:00
QMessageBox : : warning ( nullptr ,
tr ( " Error launching qet_tb_generator plugin " ) ,
2019-05-21 00:06:50 +00:00
QObject : : tr ( " To install the plugin qet_tb_generator "
2019-05-20 14:54:04 +00:00
" <br> "
2019-05-20 18:51:32 +00:00
" Visit : "
2019-05-20 14:54:04 +00:00
" <br> "
" <a href='https://pypi.python.org/pypi/qet-tb-generator'>qet-tb-generator</a> "
" <br> "
" Requires python 3.5 or above. "
" <br> "
2019-05-20 18:51:32 +00:00
" <B> " " <U> "
" First install on Windows "
" </B> " " </U> "
2019-05-20 14:54:04 +00:00
" <br> "
" 1. Install, if required, python 3.5 or above "
" <br> "
2019-05-20 18:51:32 +00:00
" Visit : "
2019-05-20 14:54:04 +00:00
" <br> "
" <a href='https://www.python.org/downloads/'>python.org</a> "
" <br> "
" 2. pip install qet_tb_generator "
" <br> "
2019-05-20 18:51:32 +00:00
" <B> " " <U> "
" Update on Windows "
" </B> " " </U> "
2019-05-20 14:54:04 +00:00
" <br> "
" python -m pip install --upgrade qet_tb_generator "
" <br> "
" >>user could launch in a terminal this script in this directory "
" <br> "
2019-05-20 18:51:32 +00:00
" C: \\ users \\ XXXX \\ AppData \\ Local \\ Programs \\ Python \\ Python36-32 \\ Scripts "
2019-05-20 14:54:04 +00:00
" <br> "
2018-06-20 18:03:39 +00:00
) ) ;
}
2016-08-30 21:42:35 +00:00
}
2019-05-20 14:54:04 +00:00
# elif defined(Q_OS_MAC)
QMessageBox : : warning ( nullptr ,
tr ( " Error launching qet_tb_generator plugin " ) ,
2019-05-21 00:06:50 +00:00
QObject : : tr ( " To install the plugin qet_tb_generator "
2019-05-20 14:54:04 +00:00
" <br> "
2019-05-20 18:51:32 +00:00
" Visit : "
2019-05-20 14:54:04 +00:00
" <br> "
" <a href='https://pypi.python.org/pypi/qet-tb-generator'>qet-tb-generator</a> "
" <br> "
2019-05-20 18:51:32 +00:00
" <B> " " <U> "
" First install on macOSX "
" </B> " " </U> "
2019-05-20 14:54:04 +00:00
" <br> "
" 1. Install, if required, python 3.5 "
" <br> "
2019-05-20 18:51:32 +00:00
" Visit : "
2019-05-20 14:54:04 +00:00
" <br> "
" <a href='https://qelectrotech.org/forum/viewtopic.php?pid=5674#p5674'>howto</a> "
" <br> "
" 2. pip3 install qet_tb_generator "
" <br> "
2019-05-20 18:51:32 +00:00
" <B> " " <U> "
" Update on macOSX "
" </B> " " </U> "
2019-05-20 14:54:04 +00:00
" <br> "
" pip3 install --upgrade qet_tb_generator "
" <br> "
) ) ;
}
}
# else
QMessageBox : : warning ( nullptr ,
tr ( " Error launching qet_tb_generator plugin " ) ,
2019-05-21 00:06:50 +00:00
QObject : : tr ( " To install the plugin qet_tb_generator "
2019-05-20 14:54:04 +00:00
" <br> "
2019-05-20 18:51:32 +00:00
" Visit : "
2019-05-20 14:54:04 +00:00
" <br> "
" <a href='https://pypi.python.org/pypi/qet-tb-generator'>qet-tb-generator</a> "
" <br> "
2019-05-20 18:51:32 +00:00
" <br> "
" Requires python 3.5 or above. "
" <br> "
2019-05-20 14:54:04 +00:00
" <br> "
2019-05-20 18:51:32 +00:00
" <B> " " <U> "
" First install on Linux "
" </B> " " </U> "
2019-05-20 14:54:04 +00:00
" <br> "
" 1. check you have pip3 installed: pip3 --version "
" <br> "
" If not install with: sudo apt-get install python3-pip "
" <br> "
" 2. Install the program: sudo pip3 install qet_tb_generator "
" <br> "
" 3. Run the program: qet_tb_generator "
" <br> "
2019-05-20 18:51:32 +00:00
" <br> "
" <B> " " <U> "
" Update on Linux "
" </B> " " </U> "
2019-05-20 14:54:04 +00:00
" <br> "
" sudo pip3 install --upgrade qet_tb_generator "
" <br> "
) ) ;
}
}
# endif
2016-08-30 21:42:35 +00:00