QElectroTech  0.70
templatelocationsaver.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 "templatelocationsaver.h"
19 #include "qetapp.h"
20 #include "qetproject.h"
21 #include "templatescollection.h"
22 
29  const TitleBlockTemplateLocation &location,
30  QWidget *parent
31 ) :
32  TitleBlockTemplateLocationChooser(location, parent)
33 {
34  init();
36 }
37 
42 }
43 
48  int template_index = templates_ -> currentIndex();
49  return(template_index ? templates_ -> currentText() : new_name_ -> text());
50 }
51 
57  // hack: if no suitable index was found, set it to 1, which is supposed to be the user collection
59  if (index == -1 && collections_ -> count() > 1) index = 1;
60  collections_ -> setCurrentIndex(index);
61 
62  if (!location.name().isEmpty()) {
63  int template_index = templates_ -> findText(location.name());
64  if (template_index != -1) {
65  templates_ -> setCurrentIndex(template_index);
66  return;
67  }
68  }
69  templates_ -> setCurrentIndex(0);
70 }
71 
77  new_name_ = new QLineEdit();
78  connect(templates_, SIGNAL(currentIndexChanged(int)), this, SLOT(updateNewName()));
79  form_layout_ -> addRow(tr("ou nouveau nom", "used in save as form"), new_name_);
81 }
82 
87  TitleBlockTemplatesCollection *current_collection = collection();
88  if (!current_collection) return;
89 
91  templates_ -> insertItem(0, tr("Nouveau modèle (entrez son nom)", "combox box entry"), QVariant(false));
92  templates_ -> insertSeparator(1);
93 
94  updateNewName();
95 }
96 
102  int template_index = templates_ -> currentIndex();
103  new_name_ -> setEnabled(!template_index);
104 }
QLineEdit * new_name_
New template name textfield.
virtual int indexForCollection(TitleBlockTemplatesCollection *) const
virtual TitleBlockTemplateLocation location() const
QIcon tr
Definition: qeticons.cpp:204
TitleBlockTemplateLocationSaver(const TitleBlockTemplateLocation &, QWidget *=nullptr)
QComboBox * templates_
Existing templates combo box.
void setLocation(const TitleBlockTemplateLocation &) override
virtual TitleBlockTemplatesCollection * collection() const
TitleBlockTemplatesCollection * parentCollection() const