QElectroTech  0.70
projectconfigpages.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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 #include "projectconfigpages.h"
19 #include "qeticons.h"
20 #include "qetproject.h"
21 #include "borderpropertieswidget.h"
23 #include "diagramcontextwidget.h"
25 #include <QtWidgets>
28 #include "selectautonumw.h"
29 #include "numerotationcontext.h"
30 #include "folioautonumbering.h"
31 #include "formulaautonumberingw.h"
33 #include "ui_autonumberingmanagementw.h"
34 
41  ConfigPage(parent),
42  m_project(project)
43 {
44 }
45 
50 }
51 
56  return(m_project);
57 }
58 
64 QETProject *ProjectConfigPage::setProject(QETProject *new_project, bool read_values) {
65  if (new_project == m_project) return(m_project);
66 
67  QETProject *former_project = m_project;
68  m_project = new_project;
69  if (m_project && read_values) {
72  }
73  return(former_project);
74 }
75 
80  if (!m_project || m_project -> isReadOnly()) return;
82 }
83 
90  initWidgets();
91  initLayout();
92  if (m_project) {
95  }
96 }
97 
98 //######################################################################################//
99 
106  ProjectConfigPage(project, parent)
107 {
108  init();
109 }
110 
115 }
116 
121  return(tr("Général", "configuration page title"));
122 }
123 
128  return(QET::Icons::Settings);
129 }
130 
135  bool modified_project = false;
136 
137  QString new_title = title_value_ -> text();
138  if (m_project -> title() != new_title) {
139  m_project -> setTitle(new_title);
140  modified_project = true;
141  }
142 
143  DiagramContext new_properties = project_variables_ -> context();
144  if (m_project -> projectProperties() != new_properties) {
145  m_project -> setProjectProperties(new_properties);
146  modified_project = true;
147  }
148  if (modified_project) {
149  m_project -> setModified(true);
150  }
151 }
152 
157  return(title_value_ -> text());
158 }
159 
164  title_label_ = new QLabel(tr("Titre du projet :", "label when configuring"));
165  title_value_ = new QLineEdit();
166  title_information_ = new QLabel(tr("Ce titre sera disponible pour tous les folios de ce projet en tant que %projecttitle.", "informative label"));
167  project_variables_label_ = new QLabel(
168  tr(
169  "Vous pouvez définir ci-dessous des propriétés personnalisées qui seront disponibles pour tous les folios de ce projet (typiquement pour les cartouches).",
170  "informative label"
171  )
172  );
173  project_variables_label_ -> setWordWrap(true);
175  project_variables_ -> setContext(DiagramContext());
176 }
177 
182  QVBoxLayout *main_layout0 = new QVBoxLayout();
183  QHBoxLayout *title_layout0 = new QHBoxLayout();
184  title_layout0 -> addWidget(title_label_);
185  title_layout0 -> addWidget(title_value_);
186  main_layout0 -> addLayout(title_layout0);
187  main_layout0 -> addWidget(title_information_);
188  main_layout0 -> addSpacing(10);
189  main_layout0 -> addWidget(project_variables_label_);
190  main_layout0 -> addWidget(project_variables_);
191  setLayout(main_layout0);
192  this -> setMinimumWidth(680);
193 
194 }
195 
200  title_value_ -> setText(m_project -> title());
201  project_variables_ -> setContext(m_project -> projectProperties());
202 }
203 
209  bool is_read_only = m_project -> isReadOnly();
210  title_value_ -> setReadOnly(is_read_only);
211 }
212 
213 //######################################################################################//
214 
222  ProjectConfigPage(project, parent)
223 {
224  initWidgets();
227 }
228 
235  return tr("Numérotation auto");
236 }
237 
244  return QIcon (QET::Icons::AutoNum);
245 }
246 
251 
257 {
258  QTabWidget *tab_widget = new QTabWidget(this);
259 
260  //Management tab
262  tab_widget->addTab(m_amw, tr("Management"));
263 
264  //Conductor tab
266  tab_widget->addTab(m_saw_conductor, tr("Conducteurs"));
267 
268  //Element tab
269  m_saw_element = new SelectAutonumW(0);
270  tab_widget->addTab(m_saw_element, tr("Eléments"));
271 
272  //Folio Tab
273  m_saw_folio = new SelectAutonumW(2);
274  tab_widget->addTab(m_saw_folio, tr("Folios"));
275 
276  //AutoNumbering Tab
278  tab_widget->addTab(m_faw, tr("Numérotation auto des folios"));
279 
280  QHBoxLayout *main_layout = new QHBoxLayout();
281  main_layout->addWidget(tab_widget);
282  setLayout(main_layout);
283 }
284 
290 {
291  //Conductor Tab
292  const QStringList strlc(m_project->conductorAutoNum().keys());
293  m_saw_conductor->contextComboBox()->addItems(strlc);
294 
295  //Element Tab
296  const QStringList strle(m_project->elementAutoNum().keys());
297  m_saw_element->contextComboBox()->addItems(strle);
298 
299  //Folio Tab
300  const QStringList strlf(m_project->folioAutoNum().keys());
301  m_saw_folio->contextComboBox()->addItems(strlf);
302 
303  //Folio AutoNumbering Tab
305 }
306 
312 }
313 
319 {
320  //Management Tab
321  connect (m_amw, SIGNAL(applyPressed()), this, SLOT(applyManagement()));
322 
323  //Conductor Tab
326  connect(m_saw_conductor->contextComboBox(), SIGNAL(currentIndexChanged(QString)), this, SLOT(updateContextConductor(QString)));
327 
328  //Element Tab
331  connect(m_saw_element->contextComboBox(), SIGNAL(currentIndexChanged(QString)), this, SLOT(updateContextElement(QString)));
332 
333  //Folio Tab
336  connect(m_saw_folio->contextComboBox(), SIGNAL(currentIndexChanged(QString)), this, SLOT(updateContextFolio(QString)));
337 
338  // Auto Folio Numbering
339  connect (m_faw, SIGNAL (applyPressed()), this, SLOT (applyAutoNum()));
340 }
341 
348  if (str == tr("Nom de la nouvelle numérotation")) m_saw_conductor -> setContext(NumerotationContext());
350 }
351 
358  if (str == tr("Nom de la nouvelle numérotation")) m_saw_folio -> setContext(NumerotationContext());
360 }
361 
368 {
369  if (str == tr("Nom de la nouvelle numérotation"))
370  {
372  }
373  else
374  {
376  }
377 }
378 
384 {
385  // If the text is the default text "Name of new numerotation" save the edited context
386  // With the the name "No name"
387  if (m_saw_element->contextComboBox()->currentText() == tr("Nom de la nouvelle numérotation"))
388  {
389  QString title(tr("Sans nom"));
390 
391  m_project->addElementAutoNum (title, m_saw_element -> toNumContext());
393  m_saw_element->contextComboBox()->addItem(tr("Sans nom"));
394  }
395  // If the text isn't yet to the autonum of the project, add this new item to the combo box.
396  else if ( !m_project -> elementAutoNum().keys().contains( m_saw_element->contextComboBox()->currentText()))
397  {
400  m_saw_element->contextComboBox()->addItem(m_saw_element->contextComboBox()->currentText());
401  }
402  // Else, the text already exist in the autonum of the project, just update the context
403  else
404  {
405  m_project->addElementAutoNum (m_saw_element->contextComboBox() -> currentText(), m_saw_element -> toNumContext());
407  }
408 }
409 
415 {
416  //if default text, return
417  if (m_saw_element->contextComboBox()->currentText() == tr("Nom de la nouvelle numérotation"))
418  return;
420  m_saw_element->contextComboBox()->removeItem (m_saw_element->contextComboBox()->currentIndex());
421 }
422 
428 {
429  // If the text is the default text "Name of new numerotation" save the edited context
430  // With the the name "No name"
431  if (m_saw_conductor->contextComboBox()-> currentText() == tr("Nom de la nouvelle numérotation"))
432  {
433  m_project->addConductorAutoNum (tr("Sans nom"), m_saw_conductor -> toNumContext());
434  project()->setCurrentConductorAutoNum(tr("Sans nom"));
435  m_saw_conductor->contextComboBox()-> addItem(tr("Sans nom"));
436  }
437  // If the text isn't yet to the autonum of the project, add this new item to the combo box.
438  else if ( !m_project -> conductorAutoNum().keys().contains( m_saw_conductor->contextComboBox()->currentText()))
439  {
442  m_saw_conductor->contextComboBox()-> addItem(m_saw_conductor->contextComboBox()->currentText());
443  }
444  // Else, the text already exist in the autonum of the project, just update the context
445  else
446  {
448  m_project->addConductorAutoNum (m_saw_conductor->contextComboBox()-> currentText(), m_saw_conductor -> toNumContext());
449  }
451 }
452 
458  // If the text is the default text "Name of new numerotation" save the edited context
459  // With the the name "No name"
460  if (m_saw_folio->contextComboBox() -> currentText() == tr("Nom de la nouvelle numérotation")) {
461  m_project->addFolioAutoNum (tr("Sans nom"), m_saw_folio -> toNumContext());
462  m_saw_folio->contextComboBox() -> addItem(tr("Sans nom"));
463  }
464  // If the text isn't yet to the autonum of the project, add this new item to the combo box.
465  else if ( !m_project -> folioAutoNum().keys().contains( m_saw_folio->contextComboBox()->currentText())) {
467  m_saw_folio->contextComboBox() -> addItem(m_saw_folio->contextComboBox()->currentText());
468  }
469  // Else, the text already exist in the autonum of the project, just update the context
470  else {
471  m_project->addFolioAutoNum (m_saw_folio->contextComboBox() -> currentText(), m_saw_folio -> toNumContext());
472  }
474 }
475 
481 
482  if (m_faw->newFolios){
483  int foliosRemaining = m_faw->newFoliosNumber();
484  emit (saveCurrentTbp());
485  emit (setAutoNum(m_faw->autoNumSelected()));
486  while (foliosRemaining > 0){
488  foliosRemaining = foliosRemaining-1;
489  }
490  emit (loadSavedTbp());
491  }
492  else{
493  QString autoNum = m_faw->autoNumSelected();
494  int fromFolio = m_faw->fromFolio();
495  int toFolio = m_faw->toFolio();
496  m_project->autoFolioNumberingSelectedFolios(fromFolio,toFolio,autoNum);
497  }
498 }
499 
505  int from;
506  int to;
507  //Apply to Entire Project
508  if (m_amw->ui->m_apply_project_rb->isChecked()) {
509  from = 0;
510  to = project()->diagrams().size() - 1;
511  }
512  //Apply to selected Folios
513  else {
514  from = m_amw->ui->m_from_folios_cb->itemData(m_amw->ui->m_from_folios_cb->currentIndex()).toInt();
515  to = m_amw->ui->m_to_folios_cb->itemData(m_amw->ui->m_to_folios_cb->currentIndex()).toInt();
516  }
517 
518  //Conductor Autonumbering Update Policy
519  //Allow Both Existent and New Conductors
520  if (m_amw->ui->m_both_conductor_rb->isChecked()) {
521  //Unfreeze Existent and New Conductors
522  project()->freezeExistentConductorLabel(false, from,to);
523  project()->freezeNewConductorLabel(false, from,to);
525  }
526  //Allow Only New
527  else if (m_amw->ui->m_new_conductor_rb->isChecked()) {
528  //Freeze Existent and Unfreeze New Conductors
529  project()->freezeExistentConductorLabel(true, from,to);
530  project()->freezeNewConductorLabel(false, from,to);
532  }
533  //Allow Only Existent
534  else if (m_amw->ui->m_existent_conductor_rb->isChecked()) {
535  //Freeze Existent and Unfreeze New Conductors
536  project()->freezeExistentConductorLabel(false, from,to);
537  project()->freezeNewConductorLabel(true, from,to);
539  }
540  //Disable
541  else if (m_amw->ui->m_disable_conductor_rb->isChecked()) {
542  //Freeze Existent and New Elements, Set Freeze Element Project Wide
543  project()->freezeExistentConductorLabel(true, from,to);
544  project()->freezeNewConductorLabel(true, from,to);
546  }
547 
548  //Element Autonumbering Update Policy
549  //Allow Both Existent and New Elements
550  if (m_amw->ui->m_both_element_rb->isChecked()) {
551  //Unfreeze Existent and New Elements
552  project()->freezeExistentElementLabel(false, from,to);
553  project()->freezeNewElementLabel(false, from,to);
554  project()->setFreezeNewElements(false);
555  }
556  //Allow Only New
557  else if (m_amw->ui->m_new_element_rb->isChecked()) {
558  //Freeze Existent and Unfreeze New Elements
559  project()->freezeExistentElementLabel(true, from,to);
560  project()->freezeNewElementLabel(false, from,to);
561  project()->setFreezeNewElements(false);
562  }
563  //Allow Only Existent
564  else if (m_amw->ui->m_existent_element_rb->isChecked()) {
565  //Freeze New and Unfreeze Existent Elements, Set Freeze Element Project Wide
566  project()->freezeExistentElementLabel(false, from,to);
567  project()->freezeNewElementLabel(true, from,to);
568  project()->setFreezeNewElements(true);
569  }
570  //Disable
571  else if (m_amw->ui->m_disable_element_rb->isChecked()) {
572  //Freeze Existent and New Elements, Set Freeze Element Project Wide
573  project()->freezeExistentElementLabel(true, from,to);
574  project()->freezeNewElementLabel(true, from,to);
575  project()->setFreezeNewElements(true);
576  }
577 
578  //Folio Autonumbering Status
579  if (m_amw->ui->m_both_folio_rb->isChecked()) {
580 
581  }
582  else if (m_amw->ui->m_new_folio_rb->isChecked()) {
583 
584  }
585  else if (m_amw->ui->m_existent_folio_rb->isChecked()) {
586 
587  }
588  else if (m_amw->ui->m_disable_folio_rb->isChecked()) {
589 
590  }
591 
592 }
593 
599  //if default text, return
600  if ( m_saw_conductor->contextComboBox()-> currentText() == tr("Nom de la nouvelle numérotation") ) return;
601  m_project -> removeConductorAutoNum (m_saw_conductor->contextComboBox()-> currentText() );
602  m_saw_conductor->contextComboBox()-> removeItem (m_saw_conductor->contextComboBox()-> currentIndex() );
604 }
605 
611  //if default text, return
612  if ( m_saw_folio->contextComboBox() -> currentText() == tr("Nom de la nouvelle numérotation") ) return;
613  m_project -> removeFolioAutoNum (m_saw_folio->contextComboBox() -> currentText() );
614  m_saw_folio->contextComboBox() -> removeItem (m_saw_folio->contextComboBox() -> currentIndex() );
616 }
617 
624 {
625  Q_UNUSED(i);
626 }
QList< Diagram * > diagrams() const
Definition: qetproject.cpp:210
void saveContextFolio()
ProjectAutoNumConfigPage::saveContext_folio Save the current displayed folio context in project...
void applyProjectConf() override
void addFolioAutoNum(const QString &key, const NumerotationContext &context)
QETProject::addFolioAutoNum Add a new folio numerotation context. If key already exist, replace old context by the new context.
Definition: qetproject.cpp:612
void conductorAutoNumAdded()
void folioAutoNumRemoved()
SelectAutonumW * m_saw_conductor
void setContext(QList< QString > autonums)
FolioAutonumberingW::setContext construct autonums in the comboBox selected in the QcomboBox...
void initWidgets() override
ProjectAutoNumConfigPage::initWidgets Init some widget of this page.
void saveContextConductor()
ProjectAutoNumConfigPage::saveContext_conductor Save the current displayed conductor context in proje...
void conductorAutoNumRemoved()
void autoFolioNumberingSelectedFolios(int, int, const QString &)
QETProject::autoFolioNumberingNewFolios.
Definition: qetproject.cpp:794
QHash< QString, NumerotationContext > conductorAutoNum() const
QETProject::conductorAutoNum.
Definition: qetproject.cpp:494
SelectAutonumW * m_saw_element
void removeContextElement()
ProjectAutoNumConfigPage::removeContextElement Remove from project the current element numerotation c...
void setCurrrentElementAutonum(QString autoNum)
QETProject::setCurrrentElementAutonum.
Definition: qetproject.cpp:540
void adjustReadOnly() override
void removeClicked()
void freezeNewElementLabel(bool freeze, int from, int to)
QETProject::freezeNewElementLabel Freeze New Elements in the selected folios.
Definition: qetproject.cpp:736
int newFoliosNumber()
FolioAutonumberingW::newFoliosNumber returns the number of folios to create.
void applyAutoNum()
ProjectAutoNumConfigPage::applyAutoNum Apply auto folio numbering, New Folios or Selected Folios...
Ui::AutoNumberingManagementW * ui
QString title() const override
void removeElementAutoNum(const QString &key)
QETProject::removeElementAutonum Remove Element Numerotation Context stored with key.
Definition: qetproject.cpp:630
void autoFolioNumberingNewFolios()
QETProject::autoFolioNumberingNewFolios emit Signal to add new Diagram with autonum properties...
Definition: qetproject.cpp:785
QIcon AutoNum
Definition: qeticons.cpp:207
void saveContextElement()
ProjectAutoNumConfigPage::saveContextElement Save the current displayed Element formula in project...
virtual void initWidgets()=0
virtual void changeToTab(int)
ProjectAutoNumConfigPage::changeToTab.
QHash< QString, NumerotationContext > folioAutoNum() const
QETProject::folioAutoNum.
Definition: qetproject.cpp:577
void setCurrentConductorAutoNum(QString autoNum)
QETProject::setCurrentConductorAutoNum.
Definition: qetproject.cpp:569
QETProject * m_project
Currently edited project.
QString title() const override
ProjectAutoNumConfigPage::title Title of this config page.
ProjectMainConfigPage(QETProject *, QWidget *=nullptr)
virtual void initLayout()=0
void adjustReadOnly() override
ProjectAutoNumConfigPage::adjustReadOnly set this config page disable if project is read only...
void folioAutoNumAdded()
QIcon Settings
Definition: qeticons.cpp:159
QIcon icon() const override
int toFolio()
FolioAutonumberingW::toFolio returns the current "To Folio" index.
void setFreezeNewElements(bool)
QETProject::setfreezeNewElements Set Project Wide freeze new elements.
Definition: qetproject.cpp:754
int fromFolio()
FolioAutonumberingW::fromFolio returns the current "From Folio" index.
void updateContextFolio(const QString &)
ProjectAutoNumConfigPage::updateContext_folio Display the current selected context for folio...
QString autoNumSelected()
FolioAutonumberingW::autoNumSelected returns the current autonum selected.
void addConductorAutoNum(const QString &key, const NumerotationContext &context)
QETProject::addConductorAutoNum Add a new conductor numerotation context. If key already exist...
Definition: qetproject.cpp:588
void applyConf() override
void readValuesFromProject() override
void buildConnections()
ProjectAutoNumConfigPage::buildConnections setup some connections.
ProjectAutoNumConfigPage(QETProject *project, QWidget *parent=nullptr)
ProjectAutoNumConfigPage::ProjectAutoNumConfigPage Default constructor.
void freezeNewConductorLabel(bool freeze, int from, int to)
QETProject::freezeNewConductorLabel Freeze New Conductors in the selected folios. ...
Definition: qetproject.cpp:696
QComboBox * contextComboBox() const
void setFreezeNewConductors(bool)
QETProject::setfreezeNewConductors Set Project Wide freeze new conductors.
Definition: qetproject.cpp:714
void applyManagement()
ProjectAutoNumConfigPage::applyAutoManagement Apply Management Options in Selected Folios...
QIcon tr
Definition: qeticons.cpp:204
void updateContextElement(const QString &)
ProjectAutoNumConfigPage::updateContextElement Display the current selected context for element...
void setContext(const NumerotationContext &context)
SelectAutonumW::setCurrentContext build the context of current diagram selected in the QcomboBox...
AutoNumberingManagementW * m_amw
void freezeExistentConductorLabel(bool freeze, int from, int to)
QETProject::freezeExistentConductorLabel Freeze Existent Conductors in the selected folios...
Definition: qetproject.cpp:684
void removeContextConductor()
ProjectAutoNumConfigPage::removeContext Remove from project the current conductor numerotation contex...
void updateContextConductor(const QString &)
ProjectAutoNumConfigPage::updateContext_conductor Display the current selected context for conductor...
void readValuesFromProject() override
ProjectAutoNumConfigPage::readValuesFromProject Read value stored on project, and update display...
void removeContextFolio()
ProjectAutoNumConfigPage::removeContext_folio Remove from project the current folio numerotation cont...
void applyProjectConf() override
ProjectAutoNumConfigPage::applyProjectConf.
virtual QETProject * setProject(QETProject *project, bool=true)
void freezeExistentElementLabel(bool freeze, int from, int to)
QETProject::freezeExistentElementLabel Freeze Existent Elements in the selected folios.
Definition: qetproject.cpp:724
DiagramContextWidget * project_variables_
void applyPressed()
virtual void readValuesFromProject()=0
virtual QETProject * project() const
QIcon icon() const override
ProjectAutoNumConfigPage::icon Icon of this config pafe.
NumerotationContext toNumContext() const
SelectAutonumW::toNumContext.
void addElementAutoNum(const QString &key, const NumerotationContext &context)
QETProject::addElementAutoNum Add a new element numerotation context. If key already exist...
Definition: qetproject.cpp:599
void setAutoNum(QString)
QHash< QString, NumerotationContext > elementAutoNum() const
QETProject::elementAutoNum.
Definition: qetproject.cpp:502
virtual void adjustReadOnly()=0
FolioAutonumberingW * m_faw
ProjectConfigPage(QETProject *, QWidget *=nullptr)
virtual void applyProjectConf()=0