QElectroTech  0.8-dev
projectview.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef PROJECT_VIEW_H
19 #define PROJECT_VIEW_H
20 
21 #include <QWidget>
22 #include <QtWidgets>
23 #include <QTabBar>
24 
25 #include "templatelocation.h"
26 #include "qetresult.h"
27 
28 #ifdef Q_OS_MACOS
29 
30 class WheelEnabledTabBar : public QTabWidget
31 {
32 public:
33  WheelEnabledTabBar(QWidget *parent = nullptr)
34  : QTabWidget(parent)
35  {}
36 
37  double temp_index = 0;
38 
39  void wheelEvent(QWheelEvent *event) override
40  {
41  int index = currentIndex();
42  double delta = 0;
43  double scale_factor = 0.005; // Decrease or increase speed of mouse wheel (0.04 = decrease)
44  if (event->modifiers() & Qt::ControlModifier) {
45  if (index != -1) {
46  delta = event->delta() * scale_factor; // Read and scale the scroll value
47  if (delta > 0 && (temp_index > -1)) temp_index = temp_index - abs(delta);
48  if (delta < 0 && (temp_index < count())) temp_index = temp_index + abs(delta);
49 
50  index = int (temp_index);
51  qDebug() << "index" << index << "temp_index" << temp_index << " " << event->delta() << delta;
52 
53  if (index >= 0 && index < count())
54  setCurrentIndex(index);
55 
56  // qDebug() << currentIndex();
57  }
58  }
59  }
60 };
61 #endif
62 
63 
64 class QETProject;
65 class DiagramView;
66 class Diagram;
67 class ElementsLocation;
68 class QTabWidget;
69 class QLabel;
70 class QVBoxLayout;
71 
72 
78 class ProjectView : public QWidget
79 {
80  Q_OBJECT
81 
82  // constructors, destructor
83  public:
84  ProjectView(QETProject *, QWidget * = nullptr);
85  ~ProjectView() override;
86  private:
88 
89  // methods
90  public:
92  void setProject(QETProject *);
93  QList<DiagramView *> diagram_views() const;
94  DiagramView *currentDiagram() const;
95  void closeEvent(QCloseEvent *) override;
96  void changeTabUp();
97  void changeTabDown();
98  void changeFirstTab();
99  void changeLastTab();
100 
101  public slots:
102  void removeDiagram(DiagramView *);
103  void removeDiagram(Diagram *);
104  void showDiagram(DiagramView *);
105  void showDiagram(Diagram *);
106  void editProjectProperties();
110  void moveDiagramUp(DiagramView *);
111  void moveDiagramUp(Diagram *);
113  void moveDiagramDown(Diagram *);
115  void moveDiagramUpTop(Diagram *);
117  void moveDiagramUpx10(Diagram *);
119  void moveDiagramDownx10(Diagram *);
120  void printProject();
121  void exportProject();
122  QETResult save();
123  QETResult saveAs();
124  QETResult doSave();
125  int cleanProject();
126  void updateWindowTitle();
127  void updateTabTitle(DiagramView *);
128  void updateAllTabsTitle();
129  void tabMoved(int, int);
130 
131  signals:
136  void errorEncountered(const QString &);
137  // relayed signals
140 
141  private:
142  void initActions();
143  void initWidgets();
144  void initLayout();
145  void loadDiagrams();
151  void rebuildDiagramsMap();
152  bool tryClosing();
154  int tryClosingDiagrams();
155  QString askUserForFilePath(bool = true);
156  QETResult noProjectResult() const;
157 
158  private slots:
159  void tabChanged(int);
160  void tabDoubleClicked(int);
161  void setDisplayFallbackWidget(bool);
162  void adjustReadOnlyState();
163  void diagramAdded(Diagram *diagram);
164 
165  // attributes
166  private:
171  QVBoxLayout *layout_;
174 
175 #ifdef Q_OS_MACOS
176  WheelEnabledTabBar *m_tab;
177 #else
178  QTabWidget *m_tab;
179 #endif
180 
181  QMap<int, DiagramView *> m_diagram_ids;
183  QList<DiagramView *> m_diagram_view_list;
184 };
185 
186 
187 #endif
QETProject::readOnlyChanged
void readOnlyChanged(QETProject *, bool)
ProjectView::setProject
void setProject(QETProject *)
ProjectView::setProject Set the project display by the project view.
Definition: projectview.cpp:74
ProjectView::diagramAdded
void diagramAdded(DiagramView *)
ProjectView::setDisplayFallbackWidget
void setDisplayFallbackWidget(bool)
Definition: projectview.cpp:1040
QETApp::titleBlockTemplateEditors
static QList< QETTitleBlockTemplateEditor * > titleBlockTemplateEditors()
QETApp::titleBlockTemplateEditors.
Definition: qetapp.cpp:1231
QETProject::addAutoNumDiagram
void addAutoNumDiagram()
ProjectView::moveDiagramDownx10
void moveDiagramDownx10(DiagramView *)
Definition: projectview.cpp:542
ProjectView::initWidgets
void initWidgets()
Definition: projectview.cpp:736
ProjectPropertiesDialog::exec
void exec()
ProjectPropertiesDialog::exec execute this dialog.
Definition: projectpropertiesdialog.cpp:55
QETProject::projectTitleChanged
void projectTitleChanged(QETProject *, const QString &)
QETProject::undoStack
QUndoStack * undoStack()
Definition: qetproject.h:168
QETApp::elementEditors
static QList< QETElementEditor * > elementEditors()
QETApp::elementEditors.
Definition: qetapp.cpp:1223
QETProject::embeddedElementCollection
XmlElementCollection * embeddedElementCollection() const
QETProject::embeddedCollection.
Definition: qetproject.cpp:236
ProjectView::cleanProject
int cleanProject()
Definition: projectview.cpp:661
ProjectView::save
QETResult save()
Definition: projectview.cpp:610
ProjectView::m_diagram_ids
QMap< int, DiagramView * > m_diagram_ids
Definition: projectview.h:181
autonum::sequentialNumbers
Definition: assignvariables.h:35
ProjectView::diagram_views
QList< DiagramView * > diagram_views() const
Definition: projectview.cpp:97
QETTitleBlockTemplateEditor
Definition: qettemplateeditor.h:36
QETProject::folioIndex
int folioIndex(const Diagram *) const
Definition: qetproject.cpp:227
borderpropertieswidget.h
BorderTitleBlock::titleBlockFolioChanged
void titleBlockFolioChanged(const QString &)
titleBlockFolioChanged Signal emitted after Folio has changed
ProjectView::noProjectResult
QETResult noProjectResult() const
Definition: projectview.cpp:342
ProjectView::tryClosing
bool tryClosing()
Definition: projectview.cpp:211
DiagramPrintDialog::setFileName
void setFileName(const QString &)
Definition: diagramprintdialog.cpp:60
QETProject::title
QString title() const
Definition: qetproject.cpp:366
QETProject::projectModified
void projectModified(QETProject *, bool)
TitleBlockTemplatesProjectCollection::deleteUnusedTitleBlocKTemplates
virtual void deleteUnusedTitleBlocKTemplates()
Definition: templatescollection.cpp:341
QET::Icons::AddFolio
QIcon AddFolio
Definition: qeticons.cpp:25
exportdialog.h
qettemplateeditor.h
ProjectView::moveDiagramDown
void moveDiagramDown(DiagramView *)
Definition: projectview.cpp:477
ProjectView::changeLastTab
void changeLastTab()
change current diagramview to last tab
Definition: projectview.cpp:175
ProjectView::updateWindowTitle
void updateWindowTitle()
ProjectView::updateWindowTitle Update the project view title.
Definition: projectview.cpp:851
ProjectView::exportProject
void exportProject()
Definition: projectview.cpp:594
DiagramView::editElementRequired
void editElementRequired(const ElementsLocation &)
Signal emitted when users wish to edit an element from the diagram.
ProjectView::printProject
void printProject()
Definition: projectview.cpp:564
projectview.h
ProjectView::tryClosingDiagrams
int tryClosingDiagrams()
ProjectView::tryClosingDiagrams try to close this project, if diagram or project option are changed a...
Definition: projectview.cpp:284
ProjectView::changeFirstTab
void changeFirstTab()
change current diagramview to first tab
Definition: projectview.cpp:190
QET::Icons::ArrowRightDouble
QIcon ArrowRightDouble
Definition: qeticons.cpp:31
DiagramPrintDialog::setDocName
void setDocName(const QString &)
Definition: diagramprintdialog.cpp:74
ProjectView::editCurrentDiagramProperties
void editCurrentDiagramProperties()
Definition: projectview.cpp:433
xmlelementcollection.h
DialogWaiting::setProgressBar
void setProgressBar(int val)
DialogWaiting::setProgressBar.
Definition: dialogwaiting.cpp:49
qetmessagebox.h
ProjectView::findDiagram
DiagramView * findDiagram(Diagram *)
Definition: projectview.cpp:974
ProjectView::changeTabDown
void changeTabDown()
change current diagramview to next folio
Definition: projectview.cpp:129
ProjectView::removeDiagram
void removeDiagram(DiagramView *)
ProjectView::removeDiagram Remove a diagram (folio) of the project.
Definition: projectview.cpp:352
ProjectView::projectClosed
void projectClosed(ProjectView *)
ProjectView::editProjectProperties
void editProjectProperties()
Definition: projectview.cpp:424
assignvariables.h
ProjectView::moveDiagramUpx10
void moveDiagramUpx10(DiagramView *)
Definition: projectview.cpp:521
ProjectView::updateTabTitle
void updateTabTitle(DiagramView *)
ProjectView::updateTabTitle Update the title of the tab which display the diagram view.
Definition: projectview.cpp:911
titleblockpropertieswidget.h
QETProject::setModified
void setModified(bool)
Definition: qetproject.cpp:1213
ProjectView::tryClosingElementEditors
bool tryClosingElementEditors()
Definition: projectview.cpp:260
Diagram::border_and_titleblock
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
Definition: diagram.h:83
qetapp.h
QETProject::embeddedTitleBlockTemplatesCollection
TitleBlockTemplatesProjectCollection * embeddedTitleBlockTemplatesCollection()
Definition: qetproject.cpp:243
XmlElementCollection::cleanUnusedElement
void cleanUnusedElement()
XmlElementCollection::cleanUnusedElement Remove elements in this collection which is not used in the ...
Definition: xmlelementcollection.cpp:711
ProjectView::m_project
QETProject * m_project
Definition: projectview.h:170
qetelementeditor.h
ProjectView::project
QETProject * project()
Definition: projectview.cpp:65
qetresult.h
ProjectView::~ProjectView
~ProjectView() override
Definition: projectview.cpp:57
Diagram
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition: diagram.h:56
QETProject::diagramAdded
void diagramAdded(QETProject *, Diagram *)
qeticons.h
ProjectView::doSave
QETResult doSave()
Definition: projectview.cpp:636
QETProject::diagrams
QList< Diagram * > diagrams() const
Definition: qetproject.cpp:217
QET::stringToFileName
QString stringToFileName(const QString &)
Definition: qet.cpp:414
QET::QetMessageBox::question
QMessageBox::StandardButton question(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
Definition: qetmessagebox.cpp:53
ProjectView::initActions
void initActions()
Definition: projectview.cpp:721
QETResult::isOk
bool isOk() const
Definition: qetresult.cpp:47
diagramview.h
projectpropertiesdialog.h
ProjectView::lastDiagram
DiagramView * lastDiagram()
Definition: projectview.cpp:183
ProjectView::m_end_view
QAction * m_end_view
Definition: projectview.h:169
ProjectView::showDiagram
void showDiagram(DiagramView *)
Definition: projectview.cpp:404
ProjectView::fallback_label_
QLabel * fallback_label_
Definition: projectview.h:173
DialogWaiting
Definition: dialogwaiting.h:30
ProjectView::tabDoubleClicked
void tabDoubleClicked(int)
Definition: projectview.cpp:1026
ProjectView::editElementRequired
void editElementRequired(const ElementsLocation &)
QETProject::addNewDiagram
Diagram * addNewDiagram(int pos=-1)
QETProject::addNewDiagram Add a new diagram in project at position pos.
Definition: qetproject.cpp:1151
diagramprintdialog.h
BorderTitleBlock::folio
QString folio() const
Definition: bordertitleblock.h:113
ProjectView::adjustReadOnlyState
void adjustReadOnlyState()
Definition: projectview.cpp:865
ProjectView::askUserForFilePath
QString askUserForFilePath(bool=true)
Definition: projectview.cpp:315
ProjectView::m_diagram_view_list
QList< DiagramView * > m_diagram_view_list
Definition: projectview.h:183
QET::Icons::ProjectFileGP
QIcon ProjectFileGP
Definition: qeticons.cpp:148
DialogWaiting::hasInstance
static bool hasInstance()
Definition: dialogwaiting.h:46
dialogwaiting.h
autonum::AssignVariables::formulaToLabel
static QString formulaToLabel(QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt=nullptr)
AssignVariables::formulaToLabel Return the formula with variable assigned (ready to be displayed)
Definition: assignvariables.cpp:187
ProjectView::rebuildDiagramsMap
void rebuildDiagramsMap()
Definition: projectview.cpp:986
qetproject.h
ProjectView::saveAs
QETResult saveAs()
Definition: projectview.cpp:621
QETResult::errorMessage
QString errorMessage() const
Definition: qetresult.cpp:61
ProjectView::ProjectView
ProjectView(QETProject *, QWidget *=nullptr)
Definition: projectview.cpp:42
ElementsLocation
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition: elementslocation.h:46
ProjectView::m_previous_tab_index
int m_previous_tab_index
Definition: projectview.h:182
DiagramView::showDiagram
void showDiagram(Diagram *)
Signal emmitted when diagram must be show.
DialogWaiting::instance
static DialogWaiting * instance(QWidget *parent=nullptr)
Definition: dialogwaiting.h:33
QETProject
Definition: qetproject.h:51
QETResult
Definition: qetresult.h:26
ProjectView
The ProjectView class This class provides a widget displaying the diagrams of a particular project us...
Definition: projectview.h:79
ProjectView::loadDiagrams
void loadDiagrams()
ProjectView::loadDiagrams Load diagrams of project. We create a diagram view for each diagram,...
Definition: projectview.cpp:814
DiagramView::diagram
Diagram * diagram()
Definition: diagramview.h:67
DiagramView::titleChanged
void titleChanged(DiagramView *, const QString &)
Signal emitted after the diagram title changed.
ProjectView::tabChanged
void tabChanged(int)
ProjectView::tabChanged Manage the tab change. If tab_id == -1 (there is no diagram opened),...
Definition: projectview.cpp:1004
ProjectView::firstDiagram
DiagramView * firstDiagram()
Definition: projectview.cpp:198
ProjectView::moveDiagramUpTop
void moveDiagramUpTop(DiagramView *)
Definition: projectview.cpp:498
ProjectView::m_tab
QTabWidget * m_tab
Definition: projectview.h:178
Diagram::folioIndex
int folioIndex() const
Diagram::folioIndex.
Definition: diagram.cpp:2335
ProjectView::m_first_view
QAction * m_first_view
Definition: projectview.h:168
ProjectView::changeTabUp
void changeTabUp()
change current diagramview to previous tab
Definition: projectview.cpp:152
Diagram::title
QString title() const
Diagram::title.
Definition: diagram.cpp:2023
ProjectView::diagramActivated
void diagramActivated(DiagramView *)
ProjectView::nextDiagram
DiagramView * nextDiagram()
Definition: projectview.cpp:140
ProjectView::ProjectView
ProjectView(const ProjectView &)
ProjectView::fallback_widget_
QWidget * fallback_widget_
Definition: projectview.h:172
DialogWaiting::setTitle
void setTitle(const QString &val)
DialogWaiting::setTitle of action.
Definition: dialogwaiting.cpp:75
ProjectView::previousDiagram
DiagramView * previousDiagram()
Definition: projectview.cpp:163
QET::QetMessageBox::critical
QMessageBox::StandardButton critical(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
Definition: qetmessagebox.cpp:23
QETProject::diagramOrderChanged
void diagramOrderChanged(int, int)
Definition: qetproject.cpp:1198
XmlElementCollection::cleanUnusedDirectory
void cleanUnusedDirectory()
XmlElementCollection::cleanUnusedDirectory Remove the empty directories of this collection.
Definition: xmlelementcollection.cpp:721
DiagramView
Definition: diagramview.h:38
ProjectView::initLayout
void initLayout()
Definition: projectview.cpp:792
templatelocation.h
DiagramPrintDialog::exec
void exec()
Definition: diagramprintdialog.cpp:110
DiagramView::findElementRequired
void findElementRequired(const ElementsLocation &)
Signal emitted when users wish to locate an element from the diagram within elements collection.
ProjectView::updateAllTabsTitle
void updateAllTabsTitle()
ProjectView::updateAllTabsTitle Update all tabs title.
Definition: projectview.cpp:943
ProjectView::errorEncountered
void errorEncountered(const QString &)
ProjectView::editDiagramProperties
void editDiagramProperties(DiagramView *)
Definition: projectview.cpp:440
ProjectPropertiesDialog
The ProjectPropertiesDialog class this class builds a dialog to edit whole properties of a project.
Definition: projectpropertiesdialog.h:30
ProjectView::moveDiagramUp
void moveDiagramUp(DiagramView *)
Definition: projectview.cpp:456
conductorpropertieswidget.h
ProjectView::currentDiagram
DiagramView * currentDiagram() const
ProjectView::currentDiagram.
Definition: projectview.cpp:105
ExportDialog
Definition: exportdialog.h:30
QET::Icons::ArrowLeftDouble
QIcon ArrowLeftDouble
Definition: qeticons.cpp:29
ProjectView::diagramRemoved
void diagramRemoved(DiagramView *)
DialogWaiting::progressBarValue
int progressBarValue() const
DialogWaiting::progressBarValue.
Definition: dialogwaiting.cpp:91
ProjectView::findElementRequired
void findElementRequired(const ElementsLocation &)
DiagramPrintDialog
The DiagramPrintDialog class This class implements both the dialog allowing users to configure the pr...
Definition: diagramprintdialog.h:34
ProjectView::tabMoved
void tabMoved(int, int)
Definition: projectview.cpp:953
DialogWaiting::setDetail
void setDetail(const QString &val)
DialogWaiting::setDetail of action.
Definition: dialogwaiting.cpp:83
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
QET::Icons::Diagram
QIcon Diagram
Definition: qeticons.cpp:43
QET::Icons::Cancel
QIcon Cancel
Definition: qeticons.cpp:34
QETElementEditor
Definition: qetelementeditor.h:33
diagram.h
ProjectView::m_add_new_diagram
QAction * m_add_new_diagram
Definition: projectview.h:167
ProjectView::layout_
QVBoxLayout * layout_
Definition: projectview.h:171
ProjectView::closeEvent
void closeEvent(QCloseEvent *) override
Definition: projectview.cpp:116