[qet] [1447] Added the TitleBlockTemplateLocationSaver class.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1447
Author:   xavier
Date:     2012-01-10 08:07:48 +0100 (Tue, 10 Jan 2012)
Log Message:
-----------
Added the TitleBlockTemplateLocationSaver class.

Modified Paths:
--------------
    branches/0.3/sources/titleblock/qettemplateeditor.cpp
    branches/0.3/sources/titleblock/templatelocationchooser.cpp
    branches/0.3/sources/titleblock/templatelocationchooser.h

Added Paths:
-----------
    branches/0.3/sources/titleblock/templatelocationsaver.cpp
    branches/0.3/sources/titleblock/templatelocationsaver.h

Modified: branches/0.3/sources/titleblock/qettemplateeditor.cpp
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-01-09 20:08:55 UTC (rev 1446)
+++ branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-01-10 07:07:48 UTC (rev 1447)
@@ -22,7 +22,7 @@
 #include "templatecellwidget.h"
 #include "templatecommands.h"
 #include "templateview.h"
-#include "templatelocationchooser.h"
+#include "templatelocationsaver.h"
 #include "templatelogomanager.h"
 #include "templatecellwidget.h"
 
@@ -166,7 +166,6 @@
 	QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
 	qet_template_editor -> edit(TitleBlockTemplateLocation());
 	qet_template_editor -> showMaximized();
-	
 }
 
 /**
@@ -434,11 +433,11 @@
 	dialog
 */
 TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLocationFromUser() {
-	TitleBlockTemplateLocationChooser *chooser = new TitleBlockTemplateLocationChooser(location());
+	TitleBlockTemplateLocationSaver *saver = new TitleBlockTemplateLocationSaver(location());
 	QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
 	
 	QVBoxLayout *dialog_layout = new QVBoxLayout();
-	dialog_layout -> addWidget(chooser);
+	dialog_layout -> addWidget(saver);
 	dialog_layout -> addWidget(buttons);
 	
 	QDialog dialog;
@@ -449,7 +448,7 @@
 	connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
 	
 	if (dialog.exec() == QDialog::Accepted) {
-		return(chooser -> location());
+		return(saver -> location());
 	}
 	return TitleBlockTemplateLocation();
 }

Modified: branches/0.3/sources/titleblock/templatelocationchooser.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatelocationchooser.cpp	2012-01-09 20:08:55 UTC (rev 1446)
+++ branches/0.3/sources/titleblock/templatelocationchooser.cpp	2012-01-10 07:07:48 UTC (rev 1447)
@@ -43,7 +43,7 @@
 */
 QString TitleBlockTemplateLocationChooser::name() const {
 	int template_index = templates_ -> currentIndex();
-	return(template_index ? templates_ -> currentText() : new_name_ -> text());
+	return(template_index != -1 ? templates_ -> currentText() : QString());
 }
 
 /**
@@ -51,9 +51,7 @@
 	@param location to be displayed by this widget
 */
 void TitleBlockTemplateLocationChooser::setLocation(const TitleBlockTemplateLocation &location) {
-	// hack: if o 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()) {
@@ -73,17 +71,14 @@
 void TitleBlockTemplateLocationChooser::init() {
 	collections_ = new QComboBox();
 	templates_ = new QComboBox();
-	new_name_ = new QLineEdit();
 	
 	updateCollections();
 	connect(collections_, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTemplates()));
-	connect(templates_,   SIGNAL(currentIndexChanged(int)), this, SLOT(updateNewName()));
 	
-	QFormLayout *form_layout = new QFormLayout();
-	form_layout -> addRow(tr("Collection parente",   "used in save as form"), collections_);
-	form_layout -> addRow(tr("Mod\xE8le existant",      "used in save as form"), templates_);
-	form_layout -> addRow(tr("ou nouveau nom",       "used in save as form"), new_name_);
-	setLayout(form_layout);
+	form_layout_ = new QFormLayout();
+	form_layout_ -> addRow(tr("Collection parente",   "used in save as form"), collections_);
+	form_layout_ -> addRow(tr("Mod\xE8le existant",      "used in save as form"), templates_);
+	setLayout(form_layout_);
 }
 
 /**
@@ -114,31 +109,18 @@
 }
 
 /**
-	Update the templates list according to the selected project.
+	Update the templates list according to the selected collection.
 */
 void TitleBlockTemplateLocationChooser::updateTemplates() {
 	TitleBlockTemplatesCollection *current_collection = collection();
 	if (!current_collection) return;
 	
 	templates_ -> clear();
-	templates_ -> addItem(tr("Nouveau mod\xE8le (entrez son nom)", "combox box entry"), QVariant(false));
 	
 	QStringList available_templates = current_collection -> templates();
 	if (available_templates.count()) {
-		templates_ -> insertSeparator(1);
 		foreach (QString template_name, available_templates) {
 			templates_ -> addItem(template_name, QVariant(true));
 		}
 	}
-	
-	updateNewName();
 }
-
-/**
-	Enable or diable the "new name" text field depending of the selected
-	template.
-*/
-void TitleBlockTemplateLocationChooser::updateNewName() {
-	int template_index = templates_ -> currentIndex();
-	new_name_ -> setEnabled(!template_index);
-}

Modified: branches/0.3/sources/titleblock/templatelocationchooser.h
===================================================================
--- branches/0.3/sources/titleblock/templatelocationchooser.h	2012-01-09 20:08:55 UTC (rev 1446)
+++ branches/0.3/sources/titleblock/templatelocationchooser.h	2012-01-10 07:07:48 UTC (rev 1447)
@@ -36,27 +36,26 @@
 	
 	// methods
 	public:
-	TitleBlockTemplateLocation location() const;
-	TitleBlockTemplatesCollection *collection() const;
-	QString name() const;
-	void setLocation(const TitleBlockTemplateLocation &);
+	virtual TitleBlockTemplateLocation location() const;
+	virtual TitleBlockTemplatesCollection *collection() const;
+	virtual QString name() const;
+	virtual void setLocation(const TitleBlockTemplateLocation &);
 	
-	private:
+	protected:
 	void init();
-	int indexForCollection(TitleBlockTemplatesCollection *) const;
+	virtual int indexForCollection(TitleBlockTemplatesCollection *) const;
 	
 	// slots
-	private slots:
-	void updateCollections();
-	void updateTemplates();
-	void updateNewName();
+	protected slots:
+	virtual void updateCollections();
+	virtual void updateTemplates();
 	
 	// attributes
-	private:
+	protected:
+	QFormLayout *form_layout_;
 	QComboBox *collections_;  ///< Collections combo box
 	/// Collections index within the combo box
 	QHash<int, TitleBlockTemplatesCollection *> collections_index_;
 	QComboBox *templates_;    ///< Existing templates combo box
-	QLineEdit *new_name_;     ///< New template name textfield
 };
 #endif

Added: branches/0.3/sources/titleblock/templatelocationsaver.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatelocationsaver.cpp	                        (rev 0)
+++ branches/0.3/sources/titleblock/templatelocationsaver.cpp	2012-01-10 07:07:48 UTC (rev 1447)
@@ -0,0 +1,87 @@
+#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 o 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);
+		} else {
+			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\xE8le (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);
+}

Added: branches/0.3/sources/titleblock/templatelocationsaver.h
===================================================================
--- branches/0.3/sources/titleblock/templatelocationsaver.h	                        (rev 0)
+++ branches/0.3/sources/titleblock/templatelocationsaver.h	2012-01-10 07:07:48 UTC (rev 1447)
@@ -0,0 +1,55 @@
+/*
+	Copyright 2006-2012 Xavier Guerrin
+	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/>.
+*/
+#ifndef TITLEBLOCK_SLASH_LOCATION_SAVER_H
+#define TITLEBLOCK_SLASH_LOCATION_SAVER_H
+#include <QtGui>
+#include "templatelocationchooser.h"
+class TitleBlockTemplateCollection;
+
+/**
+	This class is a widget that allows the user to choose a target title block
+	template, with the intention to save it. Therefore, compared to a
+	TitleBlockTemplateLocationChooser, it includes an extra field for the user to
+	set the name of the new template if needed.
+*/
+class TitleBlockTemplateLocationSaver : public TitleBlockTemplateLocationChooser {
+	Q_OBJECT
+	// Constructor, destructor
+	public:
+	TitleBlockTemplateLocationSaver(const TitleBlockTemplateLocation &, QWidget * = 0);
+	~TitleBlockTemplateLocationSaver();
+	private:
+	TitleBlockTemplateLocationSaver(const TitleBlockTemplateLocationSaver &);
+	
+	// methods
+	virtual QString name() const;
+	virtual void setLocation(const TitleBlockTemplateLocation &);
+	
+	private:
+	void init();
+	
+	// slots
+	protected slots:
+	virtual void updateTemplates();
+	virtual void updateNewName();
+	
+	// attributes
+	protected:
+	QLineEdit *new_name_;     ///< New template name textfield
+};
+#endif


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/