QElectroTech  0.70
integrationmovetemplateshandler.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 "templatescollection.h"
20 #include "qetmessagebox.h"
21 
28  parent_widget_(parent),
29  integ_dialog_(nullptr)
30 {
31 }
32 
37 }
38 
45  QString no_parent_collection_error_message(tr("Impossible d'accéder à la catégorie parente", "error message"));
46  QString cant_get_xml_description_error_message(tr("Impossible d'obtenir la description XML de ce modèle", "error message"));
47 
48  // we'll need the parent collection of both templates
49  TitleBlockTemplatesCollection *src_tbt_parent_collection = src.parentCollection();
50  if (!src_tbt_parent_collection) return(errorWithATemplate(src, no_parent_collection_error_message));
51 
52  TitleBlockTemplatesCollection *dst_tbt_parent_collection = dst.parentCollection();
53  if (!dst_tbt_parent_collection) return(errorWithATemplate(dst, no_parent_collection_error_message));
54 
55 
56  // first, we compare templates (actually we compare their XML code... sadly not the most efficient approach)
57  QDomElement src_xml_elmt = src.getTemplateXmlDescription();
58  if (src_xml_elmt.isNull()) return(errorWithATemplate(src, cant_get_xml_description_error_message));
59  QDomElement dst_xml_elmt = dst.getTemplateXmlDescription();
60  if (dst_xml_elmt.isNull()) return(errorWithATemplate(dst, cant_get_xml_description_error_message));
61 
62  QDomDocument src_tbt_document;
63  src_tbt_document.appendChild(src_tbt_document.importNode(src_xml_elmt, true));
64  QDomDocument dst_tbt_document;
65  dst_tbt_document.appendChild(dst_tbt_document.importNode(dst_xml_elmt, true));
66 
67 
68  if (src_tbt_document.toString(0) == dst_tbt_document.toString(0)) {
69  // the templates are the same, consider the integration is done
70  qDebug() << Q_FUNC_INFO << "Not integrating" << src.parentCollection() << "/" << src.name()<< "because it is already present in the project";
71  return(QET::Managed);
72  } else {
73  return(askUser(src, dst));
74  }
75 }
76 
83  QString error_message = QString("Une erreur s'est produite avec le modèle %1 : %2").arg(tbt.toString()).arg(message);
86  tr("Erreur", "message box title"),
87  error_message,
88  QMessageBox::Ok,
89  QMessageBox::Ok
90  );
91  return(QET::Ignore);
92 }
93 
99  return(rename_);
100 }
101 
106  return(QDateTime::currentDateTime().toString("yyyyMMddhhmmss"));
107 }
108 
115  return(QString("%1-%2.elmt").arg(tbt.name()).arg(dateString()));
116 }
117 
125  Q_UNUSED(src)
126  initDialog();
127  int result = integ_dialog_ -> exec();
128  if (result == QDialog::Accepted) {
129  if (use_existing_template_ -> isChecked()) {
130  return(QET::Managed);
131  } else if (erase_template_ -> isChecked()) {
132  return(QET::Erase);
133  } else {
135  return(QET::Rename);
136  }
137  } else {
138  return(QET::Abort);
139  }
140 }
141 
146  if (integ_dialog_) return;
147  integ_dialog_ = new QDialog(parent_widget_);
148  integ_dialog_ -> setWindowTitle(tr("Intégration d'un modèle de cartouche"));
149 
150  dialog_label_ = new QLabel(
151  QString(
152  tr(
153  "Le modèle a déjà été "
154  "intégré dans le projet. Toutefois, la version que vous "
155  "tentez d'appliquer semble différente. Que souhaitez-vous "
156  "faire ?",
157  "dialog content - %1 is a title block template name"
158  )
159  )
160  );
161 
162  use_existing_template_ = new QRadioButton(
163  QString(
164  tr(
165  "Utiliser le modèle déjà intégré",
166  "dialog content"
167  )
168  )
169  );
170 
171  integrate_new_template_ = new QRadioButton(
172  QString(
173  tr(
174  "Intégrer le modèle déposé",
175  "dialog content"
176  )
177  )
178  );
180 
181  erase_template_ = new QRadioButton(
182  QString(
183  tr(
184  "Écraser le modèle déjà intégré",
185  "dialog content"
186  )
187  )
188  );
190 
191  integrate_both_ = new QRadioButton(
192  QString(
193  tr(
194  "Faire cohabiter les deux modèles",
195  "dialog content"
196  )
197  )
198  );
199 
200  button_group1_ = new QButtonGroup(this);
203  button_group2_ = new QButtonGroup(this);
204  button_group2_ -> addButton(erase_template_);
205  button_group2_ -> addButton(integrate_both_);
206 
207  integrate_new_template_ -> setChecked(true);
208  integrate_both_ -> setChecked(true);
209 
210  buttons_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
211 
212  dialog_glayout = new QGridLayout();
213  dialog_glayout -> setColumnMinimumWidth(0, 20);
214  dialog_glayout -> addWidget(erase_template_, 0, 1);
215  dialog_glayout -> addWidget(integrate_both_, 1, 1);
216 
217  dialog_vlayout_ = new QVBoxLayout(integ_dialog_);
218  dialog_vlayout_ -> addWidget(dialog_label_);
221  dialog_vlayout_ -> addLayout(dialog_glayout);
222  dialog_vlayout_ -> addWidget(buttons_);
223 
224  connect(use_existing_template_, SIGNAL(toggled(bool)), this, SLOT(correctRadioButtons()));
225  connect(integrate_new_template_, SIGNAL(toggled(bool)), this, SLOT(correctRadioButtons()));
226  connect(buttons_, SIGNAL(accepted()), integ_dialog_, SLOT(accept()));
227  connect(buttons_, SIGNAL(rejected()), integ_dialog_, SLOT(reject()));
228 }
229 
235  int a, b, c, d;
236  button -> getContentsMargins(&a, &b, &c, &d);
237  button -> setContentsMargins(a + 15, b, c, d);
238 }
239 
244  erase_template_ -> setEnabled(integrate_new_template_ -> isChecked());
245  integrate_both_ -> setEnabled(integrate_new_template_ -> isChecked());
246 }
247 
abort the whole operation, ignoring the curent item
Definition: qet.h:129
QRadioButton * use_existing_template_
Radio button the user may click to use the existing template and stop the integration.
QET::Action askUser(const TitleBlockTemplateLocation &, const TitleBlockTemplateLocation &)
Action
Definition: qet.h:125
QRadioButton * integrate_new_template_
Radio button the user may click to integrate the template.
QDomElement getTemplateXmlDescription() const
QString newNameForTemplate(const TitleBlockTemplateLocation &)
the target has to be renamed
Definition: qet.h:131
Erase the target content.
Definition: qet.h:128
QET::Action errorWithATemplate(const TitleBlockTemplateLocation &, const QString &) override
QRadioButton * erase_template_
Radio button the user may click for the integrated template to erase the existing one...
QIcon tr
Definition: qeticons.cpp:204
QDialog * integ_dialog_
Dialog in case of conflict when integrating a title block template.
QString rename_
Name to be used when renaming a title block template.
Skip the current item.
Definition: qet.h:127
QET::Action templateAlreadyExists(const TitleBlockTemplateLocation &src, const TitleBlockTemplateLocation &dst) override
QIcon Cancel
Definition: qeticons.cpp:34
TitleBlockTemplatesCollection * parentCollection() const
the current item was handled by the Strategy object: do not treat it and continue ...
Definition: qet.h:130
QMessageBox::StandardButton critical(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
QWidget * parent_widget_
Widget used as parent to display dialogs.