File: templatelocationsaver.cpp

package info (click to toggle)
qelectrotech 1%3A0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 70,580 kB
  • sloc: cpp: 51,282; xml: 750; sh: 261; perl: 258; makefile: 6
file content (104 lines) | stat: -rw-r--r-- 3,237 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
	Copyright 2006-2017 The QElectroTech Team
	This file is part of QElectroTech.
	
	QElectroTech is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.
	
	QElectroTech is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "templatelocationsaver.h"
#include "qetapp.h"
#include "qetproject.h"
#include "templatescollection.h"

/**
	Constructor
	@param location Initial location displayed by the widget
	@param widget Parent QWidget
*/
TitleBlockTemplateLocationSaver::TitleBlockTemplateLocationSaver(
	const TitleBlockTemplateLocation &location,
	QWidget *parent
) :
	TitleBlockTemplateLocationChooser(location, parent)
{
	init();
	setLocation(location);
}

/**
	Destructor
*/
TitleBlockTemplateLocationSaver::~TitleBlockTemplateLocationSaver() {
}

/**
	@return the currently selected/entered name
*/
QString TitleBlockTemplateLocationSaver::name() const {
	int template_index = templates_ -> currentIndex();
	return(template_index ? templates_ -> currentText() : new_name_ -> text());
}

/**
	Set the location displayed by this widget
	@param location to be displayed by this widget
*/
void TitleBlockTemplateLocationSaver::setLocation(const TitleBlockTemplateLocation &location) {
	// hack: if no suitable index was found, set it to 1, which is supposed to be the user collection
	int index = indexForCollection(location.parentCollection());
	if (index == -1 && collections_ -> count() > 1) index = 1;
	collections_ -> setCurrentIndex(index);
	
	if (!location.name().isEmpty()) {
		int template_index = templates_ -> findText(location.name());
		if (template_index != -1) {
			templates_ -> setCurrentIndex(template_index);
			return;
		}
	}
	templates_ -> setCurrentIndex(0);
}

/**
	Initialize this widget.
	@param location Initial location displayed by the widget
*/
void TitleBlockTemplateLocationSaver::init() {
	new_name_ = new QLineEdit();
	connect(templates_, SIGNAL(currentIndexChanged(int)), this, SLOT(updateNewName()));
	form_layout_ -> addRow(tr("ou nouveau nom",       "used in save as form"), new_name_);
	updateTemplates();
}

/**
	Update the templates list according to the selected collection.
*/
void TitleBlockTemplateLocationSaver::updateTemplates() {
	TitleBlockTemplatesCollection *current_collection = collection();
	if (!current_collection) return;
	
	TitleBlockTemplateLocationChooser::updateTemplates();
	templates_ -> insertItem(0, tr("Nouveau modèle (entrez son nom)", "combox box entry"), QVariant(false));
	templates_ -> insertSeparator(1);
	
	updateNewName();
}

/**
	Enable or diable the "new name" text field depending of the selected
	template.
*/
void TitleBlockTemplateLocationSaver::updateNewName() {
	int template_index = templates_ -> currentIndex();
	new_name_ -> setEnabled(!template_index);
}