QElectroTech  0.70
templatelocationchooser.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 "qetapp.h"
20 #include "qetproject.h"
21 #include "templatescollection.h"
22 
29  const TitleBlockTemplateLocation &location,
30  QWidget *parent
31 ) :
32  QWidget(parent)
33 {
34  init();
36 }
37 
42 }
43 
49 }
50 
55  return(collections_index_[collections_ -> currentIndex()]);
56 }
57 
62  int template_index = templates_ -> currentIndex();
63  return(template_index != -1 ? templates_ -> currentText() : QString());
64 }
65 
72  collections_ -> setCurrentIndex(index);
73 
74  if (!location.name().isEmpty()) {
75  int template_index = templates_ -> findText(location.name());
76  if (template_index != -1) {
77  templates_ -> setCurrentIndex(template_index);
78  } else {
79  templates_ -> setCurrentIndex(0);
80  }
81  }
82 }
83 
89  collections_ = new QComboBox();
90  templates_ = new QComboBox();
91 
93  connect(collections_, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTemplates()));
94 
95  form_layout_ = new QFormLayout();
96  form_layout_ -> addRow(tr("Collection parente", "used in save as form"), collections_);
97  form_layout_ -> addRow(tr("Modèle existant", "used in save as form"), templates_);
98  setLayout(form_layout_);
99 }
100 
106  QList<int> indexes = collections_index_.keys(coll);
107  if (indexes.count()) return(indexes.first());
108  return(-1);
109 }
110 
115  collections_ -> clear();
116  collections_index_.clear();
117 
118  int index = 0;
120  collections_ -> addItem(collection -> title());
121  collections_index_.insert(index, collection);
122  ++ index;
123  }
124 
125  updateTemplates();
126 }
127 
132  TitleBlockTemplatesCollection *current_collection = collection();
133  if (!current_collection) return;
134 
135  templates_ -> clear();
136 
137  QStringList available_templates = current_collection -> templates();
138  if (available_templates.count()) {
139  foreach (QString template_name, available_templates) {
140  templates_ -> addItem(template_name, QVariant(true));
141  }
142  }
143 }
TitleBlockTemplateLocationChooser(const TitleBlockTemplateLocation &, QWidget *=nullptr)
virtual void setLocation(const TitleBlockTemplateLocation &)
virtual int indexForCollection(TitleBlockTemplatesCollection *) const
virtual TitleBlockTemplateLocation location() const
QIcon tr
Definition: qeticons.cpp:204
QHash< int, TitleBlockTemplatesCollection * > collections_index_
Collections index within the combo box.
QComboBox * templates_
Existing templates combo box.
static QList< TitleBlockTemplatesCollection * > availableTitleBlockTemplatesCollections()
Definition: qetapp.cpp:476
virtual TitleBlockTemplatesCollection * collection() const
TitleBlockTemplatesCollection * parentCollection() const