QElectroTech  0.70
titleblockpropertieswidget.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 */
19 #include "ui_titleblockpropertieswidget.h"
20 #include "templatescollection.h"
21 #include "qeticons.h"
22 #include "titleblocktemplate.h"
23 #include "qetapp.h"
24 #include <QMenu>
25 #include <utility>
26 
34 TitleBlockPropertiesWidget::TitleBlockPropertiesWidget(const TitleBlockProperties &titleblock, bool current_date, QETProject *project, QWidget *parent) :
35  QWidget(parent),
37 {
38  ui->setupUi(this);
39  initDialog(current_date, project);
40  setProperties(titleblock);
41 }
42 
51 TitleBlockPropertiesWidget::TitleBlockPropertiesWidget(TitleBlockTemplatesCollection *tbt_collection, const TitleBlockProperties &titleblock, bool current_date, QETProject *project, QWidget *parent) :
52  QWidget(parent),
54 {
55  ui->setupUi(this);
56  initDialog(current_date,project);
57  addCollection(tbt_collection);
59  setProperties(titleblock);
60 }
61 
70 TitleBlockPropertiesWidget::TitleBlockPropertiesWidget(QList<TitleBlockTemplatesCollection *> tbt_collection, const TitleBlockProperties &titleblock, bool current_date, QETProject *project, QWidget *parent) :
71  QWidget(parent),
73 {
74  ui->setupUi(this);
75  initDialog(current_date,project);
76  foreach (TitleBlockTemplatesCollection *c, tbt_collection)
77  addCollection(c);
79  setProperties(titleblock);
80 }
81 
87 {
88  delete ui;
89 }
90 
96  ui -> m_title_le -> setText (properties.title);
97  ui -> m_author_le -> setText (properties.author);
98  ui -> m_file_le -> setText (properties.filename);
99  ui -> m_plant -> setText (properties.plant);
100  ui -> m_loc -> setText (properties.locmach);
101  ui -> m_indice -> setText (properties.indexrev);
102  ui -> m_folio_le -> setText (properties.folio);
103  ui -> m_display_at_cb -> setCurrentIndex(properties.display_at == Qt::BottomEdge ? 0 : 1);
104  ui->auto_page_cb->setCurrentText(properties.auto_page_num);
105 
106  //About date
107  ui -> m_date_now_pb -> setDisabled(true);
108  ui -> m_date_edit -> setDisabled(true);
109  ui -> m_date_edit -> setDate(QDate::currentDate());
110 
111  if (!ui -> m_current_date_rb -> isHidden()) {
113  ui -> m_current_date_rb -> setChecked(true);
114  else {
115  if (properties.date.isNull())
116  ui -> m_no_date_rb -> setChecked(true);
117  else {
118  ui -> m_fixed_date_rb -> setChecked(true);
119  ui -> m_date_edit -> setDate(properties.date);
120  }
121  }
122  }
123  else {
125  ui -> m_fixed_date_rb ->setChecked(true);
126  else {
127  if (properties.date.isNull())
128  ui -> m_no_date_rb -> setChecked(true);
129  else {
130  ui -> m_fixed_date_rb -> setChecked(true);
131  ui -> m_date_edit -> setDate(properties.date);
132  }
133  }
134  } //About date
135 
136  //Set the current titleblock if any
137  int index = 0;
138  if (!properties.template_name.isEmpty())
139  {
141  if (index == -1) index = 0;
142  }
143  ui -> m_tbt_cb -> setCurrentIndex(index);
144 
145  m_dcw -> setContext(properties.context);
146 }
147 
154  prop.title = ui -> m_title_le -> text();
155  prop.author = ui -> m_author_le -> text();
156  prop.filename = ui -> m_file_le -> text();
157  prop.plant = ui -> m_plant -> text();
158  prop.locmach = ui -> m_loc -> text();
159  prop.indexrev = ui -> m_indice -> text();
160  prop.folio = ui -> m_folio_le -> text();
161  prop.display_at = ui -> m_display_at_cb -> currentIndex() == 0 ? Qt::BottomEdge : Qt::RightEdge;
162 
163  if (ui->m_no_date_rb->isChecked()) {
165  prop.date = QDate();
166  }
167  else if (ui -> m_fixed_date_rb -> isChecked()) {
169  prop.date = ui->m_date_edit->date();
170  }
171  else if (ui->m_current_date_rb->isVisible() && ui->m_current_date_rb->isChecked()) {
173  prop.date = QDate::currentDate();
174  }
175 
176  if (!currentTitleBlockTemplateName().isEmpty())
177  {
179  prop.collection = m_map_index_to_collection_type.at(ui->m_tbt_cb->currentIndex());
180  }
181 
182  prop.context = m_dcw -> context();
183 
184  prop.auto_page_num = ui->auto_page_cb->currentText();
185 
186  return prop;
187 }
188 
195  prop.title = ui -> m_title_le -> text();
196  prop.author = ui -> m_author_le -> text();
197  prop.filename = ui -> m_file_le -> text();
198  prop.plant = ui -> m_plant -> text();
199  prop.locmach = ui -> m_loc -> text();
200  prop.indexrev = ui -> m_indice -> text();
201  prop.folio = "%autonum";
202  prop.display_at = ui -> m_display_at_cb -> currentIndex() == 0 ? Qt::BottomEdge : Qt::RightEdge;
203 
204  if (ui->m_no_date_rb->isChecked()) {
206  prop.date = QDate();
207  }
208  else if (ui -> m_fixed_date_rb -> isChecked()) {
210  prop.date = ui->m_date_edit->date();
211  }
212  else if (ui->m_current_date_rb->isVisible() && ui->m_current_date_rb->isChecked()) {
214  prop.date = QDate::currentDate();
215  }
216 
217  if (!currentTitleBlockTemplateName().isEmpty())
218  {
220  prop.collection = m_map_index_to_collection_type.at(ui->m_tbt_cb->currentIndex());
221  }
222 
223  prop.context = m_dcw -> context();
224 
225  prop.auto_page_num = std::move(autoNum);
226 
227  return prop;
228 }
229 
231 {
232  QET::QetCollection qc = m_map_index_to_collection_type.at(ui->m_tbt_cb->currentIndex());
233  TitleBlockTemplatesCollection *collection = nullptr;
235  if (c -> collection() == qc)
236  collection = c;
237 
238  if (!collection)
240 
241  return collection->location(currentTitleBlockTemplateName());
242 }
243 
249  ui -> m_tbt_label -> setVisible(visible);
250  ui -> m_tbt_cb -> setVisible(visible);
251  ui -> m_tbt_pb -> setVisible(visible);
252 }
253 
259  ui->m_tbt_gb->setDisabled(ro);
260 }
261 
267  int index = ui -> m_tbt_cb -> currentIndex();
268  if(index != -1)
269  return (ui -> m_tbt_cb -> itemData(index).toString());
270  return QString();
271 }
272 
279 {
280  if (!tbt_collection || m_tbt_collection_list.contains(tbt_collection)) return;
281  m_tbt_collection_list << tbt_collection;
282 }
283 
289 void TitleBlockPropertiesWidget::initDialog(const bool &current_date, QETProject *project) {
290  m_dcw = new DiagramContextWidget();
291  ui -> m_tab2_vlayout -> addWidget(m_dcw);
292 
294  ui -> m_current_date_rb -> setVisible(current_date);
295 
296  m_tbt_edit = new QAction(tr("Éditer ce modèle", "menu entry"), this);
297  m_tbt_duplicate = new QAction(tr("Dupliquer et éditer ce modèle", "menu entry"), this);
298 
299  connect(m_tbt_edit, SIGNAL(triggered()), this, SLOT(editCurrentTitleBlockTemplate()));
300  connect(m_tbt_duplicate, SIGNAL(triggered()), this, SLOT(duplicateCurrentTitleBlockTemplate()));
301 
302  m_tbt_menu = new QMenu(tr("Title block templates actions"));
303  m_tbt_menu -> addAction(m_tbt_edit);
304  m_tbt_menu -> addAction(m_tbt_duplicate);
305  ui -> m_tbt_pb -> setMenu(m_tbt_menu);
306 
307  connect(ui->m_tbt_cb, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCurrentTitleBlockTemplate(int)));
308 
309  if (project!= nullptr){
310  keys_2 = project -> folioAutoNum().keys();
311  foreach (QString str, keys_2) { ui -> auto_page_cb -> addItem(str); }
312  if (ui->auto_page_cb->currentText()==nullptr)
313  ui->auto_page_cb->addItem(tr("Créer un Folio Numérotation Auto"));
314  }
315  else{
316  ui->auto_page_cb->hide();
317  ui->m_edit_autofolionum_pb->hide();
318  ui->label_9->hide();
319  }
320 
321 }
322 
330 int TitleBlockPropertiesWidget::getIndexFor(const QString &tbt_name, const QET::QetCollection collection) const
331 {
332  for (int i = 0; i<ui->m_tbt_cb->count(); i++) {
333  if (ui->m_tbt_cb->itemData(i).toString() == tbt_name)
334  if (m_map_index_to_collection_type.at(i) == collection)
335  return i;
336  }
337  return -1;
338 }
339 
342 }
343 
346 }
347 
353 {
354  ui -> m_tbt_cb ->clear();
355 
356  if (m_tbt_collection_list.isEmpty())
357  {
359  return;
360  }
362 
363  //Add the default title block
366  ui -> m_tbt_cb -> addItem(QET::Icons::QETLogo, tr("Modèle par défaut"));
367 
368  //Add every title block stored in m_tbt_collection_list
370  {
371  QIcon icon;
372  QET::QetCollection qc = tbt_c -> collection();
373  if (qc == QET::QetCollection::Common)
374  icon = QET::Icons::QETLogo;
375  else if (qc == QET::QetCollection::Custom)
376  icon = QET::Icons::Home;
377  else if (qc == QET::QetCollection::Embedded)
378  icon = QET::Icons::TitleBlock;
379 
380  foreach(QString tbt_name, tbt_c -> templates())
381  {
383  ui -> m_tbt_cb -> addItem(icon, tbt_name, tbt_name);
384  }
385  }
386 }
387 
393 {
394  m_dcw -> clear();
395 
397  TitleBlockTemplatesCollection *collection = nullptr;
399  if (c -> collection() == qc)
400  collection = c;
401 
402  if (!collection) return;
403 
404  // get template
405  TitleBlockTemplate *tpl = collection -> getTemplate(ui -> m_tbt_cb -> currentText());
406  if(tpl != nullptr) {
407  // get all template fields
408  QStringList fields = tpl -> listOfVariables();
409  // set fields to additional_fields_ widget
410  DiagramContext templateContext;
411  for(int i =0; i<fields.count(); i++)
412  templateContext.addValue(fields.at(i), "");
413  m_dcw -> setContext(templateContext);
414  }
415 }
416 
422  ui -> m_date_edit -> setDate(QDate::currentDate());
423 }
424 
430  emit openAutoNumFolioEditor(ui->auto_page_cb->currentText());
431  if (ui->auto_page_cb->currentText()!=tr("Créer un Folio Numérotation Auto"))
432  {
433  //still to implement: load current auto folio num settings
434  }
435 }
void setProperties(const TitleBlockProperties &properties)
TitleBlockPropertiesWidget::setProperties.
QString locmach
Location(displayed by the default template)
void setReadOnly(const bool &ro)
TitleBlockPropertiesWidget::setReadOnly if true, this widget is disable.
From an embedded collection (a project for exemple)
Definition: qet.h:153
QString plant
Plant (displayed by the default template)
From user collection.
Definition: qet.h:152
Qt::Edge display_at
Edge to display the titleblock.
void addCollection(TitleBlockTemplatesCollection *tbt_collection)
TitleBlockPropertiesWidget::addCollection add a collection of title block available in the combo box...
QIcon QETLogo
Definition: qeticons.cpp:151
void setTitleBlockTemplatesVisible(const bool &visible)
TitleBlockPropertiesWidget::setTitleBlockTemplatesVisible if true, title block template combo box and...
QIcon Home
Definition: qeticons.cpp:114
void changeCurrentTitleBlockTemplate(int)
TitleBlockPropertiesWidget::changeCurrentTitleBlockTemplate Load the additionnal field of title block...
TitleBlockTemplateLocation currentTitleBlockLocation() const
void on_m_edit_autofolionum_pb_clicked()
TitleBlockPropertiesWidget::on_m_edit_autofolionum_pb_clicked Open Auto Folio Num dialog...
void openAutoNumFolioEditor(QString)
void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool=false)
Definition: qetapp.cpp:1412
QDate date
Date (displayed by the default template)
QetCollection
Enum used to specify the origin of a collection of thing (title block, element etc...)
Definition: qet.h:150
bool addValue(const QString &, const QVariant &, bool show=true)
QString filename
Filename (displayed by the default template)
QList< TitleBlockTemplatesCollection * > m_tbt_collection_list
QIcon TitleBlock
Definition: qeticons.cpp:165
void updateTemplateList()
TitleBlockPropertiesWidget::updateTemplateList Update the title block template list available in the ...
~TitleBlockPropertiesWidget() override
TitleBlockPropertiesWidget::~TitleBlockPropertiesWidget destructor.
DiagramContext context
Container for the additional, user-defined fields.
TitleBlockProperties propertiesAutoNum(QString autoNum) const
TitleBlockPropertiesWidget::properties.
TitleBlockProperties properties() const
TitleBlockPropertiesWidget::properties.
QIcon tr
Definition: qeticons.cpp:204
virtual TitleBlockTemplateLocation location(const QString &=QString())=0
DateManagement useDate
Wheter to use the date attribute.
QString currentTitleBlockTemplateName() const
TitleBlockPropertiesWidget::currentTitleBlockTemplateName.
Ui::TitleBlockPropertiesWidget * ui
QString author
Author of the diagram/folio (displayed by the default template)
int getIndexFor(const QString &tbt_name, const QET::QetCollection collection) const
TitleBlockPropertiesWidget::getIndexFor Find the index of the combo box for the title block availabl...
QString indexrev
Revision Index (displayed by the default template)
QIcon ro
Definition: qeticons.cpp:199
void initDialog(const bool &current_date, QETProject *project)
TitleBlockPropertiesWidget::initDialog Init this dialog.
QList< QET::QetCollection > m_map_index_to_collection_type
QET::QetCollection collection
Specify the location of the title block.
void on_m_date_now_pb_clicked()
TitleBlockPropertiesWidget::on_m_date_now_pb_clicked Set the date to current date.
QString folio
Folio information (displayed by the default template)
From common collection.
Definition: qet.h:151
QString title
Folio title (displayed by the default template)
static QETApp * instance()
Definition: qetapp.cpp:143
QString template_name
Name of the template used to render the title block - an empty string means "the default template pro...
TitleBlockPropertiesWidget(const TitleBlockProperties &titleblock=TitleBlockProperties(), bool current_date=false, QETProject *project=nullptr, QWidget *parent=nullptr)
TitleBlockPropertiesWidget::TitleBlockPropertiesWidget default constructor.