QElectroTech  0.70
newelementwizard.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 "newelementwizard.h"
19 #include "namelistwidget.h"
20 #include "qetelementeditor.h"
21 #include "qfilenameedit.h"
22 #include "qetmessagebox.h"
24 #include "elementcollectionitem.h"
25 
31 NewElementWizard::NewElementWizard(QWidget *parent, Qt::WindowFlags f) :
32  QWizard(parent, f)
33 {
34  setOptions(options() & ~QWizard::NoCancelButton);
35 
36 #ifdef Q_OS_WIN
37  setWizardStyle(QWizard::AeroStyle);
38 #elif defined(Q_OS_MAC)
39  setWizardStyle(QWizard::MacStyle);
40 #endif
41 
42  setPixmap(LogoPixmap, QPixmap(":/ico/256x256/qelectrotech.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
43  setWindowTitle(tr("Créer un nouvel élément : Assistant", "window title"));
44  setButtonText(QWizard::NextButton, tr("&Suivant >"));
45  addPage(buildStep1());
46  addPage(buildStep2());
47  addPage(buildStep3());
48  setFixedSize(705, 325);
49 }
50 
55 }
56 
63 {
64  QModelIndex index = m_model->indexFromLocation(location);
65  if (index.isValid()) {
66  m_tree_view->scrollTo(index);
67  m_tree_view->setCurrentIndex(index);
68  }
69 }
70 
76 {
77  QWizardPage *page = new QWizardPage();
78  page -> setProperty("WizardState", Category);
79  page -> setTitle(tr("Étape 1/3 : Catégorie parente", "wizard page title"));
80  page -> setSubTitle(tr("Sélectionnez une catégorie dans laquelle enregistrer le nouvel élément.", "wizard page subtitle"));
81  QVBoxLayout *layout = new QVBoxLayout();
82 
83  m_tree_view = new QTreeView(this);
84 
88 
89  m_tree_view->setModel(m_model);
90  m_tree_view->setHeaderHidden(true);
91  m_tree_view->setAnimated(true);
92  layout->addWidget(m_tree_view);
93 
94  page->setLayout(layout);
95  return(page);
96 }
97 
103  QWizardPage *page = new QWizardPage();
104  page -> setProperty("WizardState", Filename);
105  page -> setTitle(tr("Étape 2/3 : Nom du fichier", "wizard page title"));
106  page -> setSubTitle(tr("Indiquez le nom du fichier dans lequel enregistrer le nouvel élément.", "wizard page subtitle"));
107  QVBoxLayout *layout = new QVBoxLayout();
108 
109  m_qle_filename = new QFileNameEdit(tr("nouvel_element"));
110  m_qle_filename -> selectAll();
111  QLabel *explication2 = new QLabel(tr("Vous n'êtes pas obligé de préciser l'extension *.elmt. Elle sera ajoutée automatiquement."));
112  explication2 -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
113  explication2 -> setWordWrap(true);
114  layout -> addWidget(m_qle_filename);
115  layout -> addWidget(explication2);
116  layout -> addSpacing(100);
117 
118  page -> setLayout(layout);
119  return(page);
120 }
121 
127  QWizardPage *page = new QWizardPage();
128  page -> setProperty("WizardState", Names);
129  page -> setTitle(tr("Étape 3/3 : Noms de l'élément", "wizard page title"));
130  page -> setSubTitle(tr("Indiquez le ou les noms de l'élément.", "wizard page subtitle"));
131  QVBoxLayout *layout = new QVBoxLayout();
132 
133  m_names_list = new NameListWidget(this);
134  NamesList hash_name;
135  hash_name.addName(QLocale::system().name().left(2), tr("Nom du nouvel élément", "default name when creating a new element"));
136  m_names_list -> setNames(hash_name);
137  layout -> addWidget(m_names_list);
138 
139  page -> setLayout(layout);
140  return(page);
141 }
142 
148 {
149  WizardState wizard_state = static_cast<WizardState>(currentPage() -> property("WizardState").toInt());
150 
151  if (wizard_state == Category) {
152  return(validStep1());
153  }
154  else if (wizard_state == Filename) {
155  return(validStep2());
156  }
157  else if (wizard_state == Names)
158  {
159  // must have one name minimum
160  if (!m_names_list->isEmpty()) {
162  }
163  return true;
164  }
165  else return(true);
166 }
167 
174 {
175  //They must be one directory selected
176  bool step1_ok = false;
177 
178  QModelIndex index = m_tree_view->currentIndex();
179  if (index.isValid()) {
180 
181  ElementCollectionItem *eci = static_cast<ElementCollectionItem*>(m_model->itemFromIndex(index));
182  if (eci && eci->isDir()) {
183  ElementsLocation loc(eci->collectionPath());
184  if (loc.exist()) {
185  m_chosen_location = loc;
186  step1_ok = true;
187  }
188  }
189  }
190 
191  if (!step1_ok) {
192  QET::QetMessageBox::critical(parentWidget(),
193  tr("Erreur", "message box title"),
194  tr("Vous devez sélectionner une catégorie.", "message box content"));
195  }
196 
197  return(step1_ok);
198 }
199 
206  QString file_name = m_qle_filename -> text();
207 
208  if (file_name.isEmpty()) {
210  tr("Erreur", "message box title"),
211  tr("Vous devez entrer un nom de fichier", "message box content"));
212  return false;
213  }
214 
215  if (!file_name.endsWith(".elmt")) {
216  file_name += ".elmt";
217  }
218 
220  loc_.addToPath(file_name);
221  if (loc_.exist()) {
223  tr("Erreur", "message box title"),
224  tr("Un élément portant le même nom existe déjà"));
225  return false;
226  }
227 
228  m_chosen_file = file_name;
229  return(true);
230 }
231 
237  QETElementEditor *edit_new_element = new QETElementEditor(parentWidget());
238  edit_new_element -> setNames(m_names_list -> names());
239 
241  loc_.addToPath(m_chosen_file);
242  edit_new_element -> setLocation(loc_);
243  edit_new_element -> show();
244 }
The ElementCollectionItem class This class represent a item (a directory or an element) in a element ...
QWizardPage * buildStep1()
NewElementWizard::buildStep1.
NewElementWizard(QWidget *=nullptr, Qt::WindowFlags=nullptr)
QWizardPage * buildStep2()
NewElementWizard::buildStep2.
void preselectedLocation(const ElementsLocation &location)
NewElementWizard::preselectedLocation Select item in the tree view represented by location...
bool isEmpty() const
NameListWidget::isEmpty.
void addName(const QString &, const QString &)
Definition: nameslist.cpp:50
ElementsLocation m_chosen_location
bool validStep1()
NewElementWizard::validStep1 Valid the setp 1.
bool addToPath(const QString &)
ElementsLocation::addToPath Add a string to the actual path of this location.
void createNewElement()
NewElementWizard::createNewElement Lauch an element editor for create the new element.
NameListWidget * m_names_list
bool validStep2()
NewElementWizard::validStep2 Valid the step 2.
QTreeView * m_tree_view
QIcon tr
Definition: qeticons.cpp:204
void hideElement()
ElementsCollectionModel::hideElement Hide element in this model, only directory is managed...
~NewElementWizard() override
bool exist() const
ElementsLocation::exist.
QFileNameEdit * m_qle_filename
bool validateCurrentPage() override
NewElementWizard::validateCurrentPage.
ElementsCollectionModel * m_model
void addCustomCollection(bool set_data=true)
ElementsCollectionModel::addCustomCollection Add the custom elements collection to this model...
virtual QString collectionPath() const =0
virtual bool isDir() const =0
QMessageBox::StandardButton critical(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
QWizardPage * buildStep3()
NewElementWizard::buildStep3.
The NameListWidget class Provide a widget for let user define localized string;.
QModelIndex indexFromLocation(const ElementsLocation &location)
ElementsCollectionModel::indexFromLocation Return the index who represent . Index can be non valid...