mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 17:50:52 +01:00
Added the TitleBlockTemplateLocationSaver class.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1447 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
#include "templatecellwidget.h"
|
#include "templatecellwidget.h"
|
||||||
#include "templatecommands.h"
|
#include "templatecommands.h"
|
||||||
#include "templateview.h"
|
#include "templateview.h"
|
||||||
#include "templatelocationchooser.h"
|
#include "templatelocationsaver.h"
|
||||||
#include "templatelogomanager.h"
|
#include "templatelogomanager.h"
|
||||||
#include "templatecellwidget.h"
|
#include "templatecellwidget.h"
|
||||||
|
|
||||||
@@ -166,7 +166,6 @@ void QETTitleBlockTemplateEditor::newTemplate() {
|
|||||||
QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
|
QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
|
||||||
qet_template_editor -> edit(TitleBlockTemplateLocation());
|
qet_template_editor -> edit(TitleBlockTemplateLocation());
|
||||||
qet_template_editor -> showMaximized();
|
qet_template_editor -> showMaximized();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -434,11 +433,11 @@ void QETTitleBlockTemplateEditor::saveAs() {
|
|||||||
dialog
|
dialog
|
||||||
*/
|
*/
|
||||||
TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLocationFromUser() {
|
TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLocationFromUser() {
|
||||||
TitleBlockTemplateLocationChooser *chooser = new TitleBlockTemplateLocationChooser(location());
|
TitleBlockTemplateLocationSaver *saver = new TitleBlockTemplateLocationSaver(location());
|
||||||
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
|
|
||||||
QVBoxLayout *dialog_layout = new QVBoxLayout();
|
QVBoxLayout *dialog_layout = new QVBoxLayout();
|
||||||
dialog_layout -> addWidget(chooser);
|
dialog_layout -> addWidget(saver);
|
||||||
dialog_layout -> addWidget(buttons);
|
dialog_layout -> addWidget(buttons);
|
||||||
|
|
||||||
QDialog dialog;
|
QDialog dialog;
|
||||||
@@ -449,7 +448,7 @@ TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLoc
|
|||||||
connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
||||||
|
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
return(chooser -> location());
|
return(saver -> location());
|
||||||
}
|
}
|
||||||
return TitleBlockTemplateLocation();
|
return TitleBlockTemplateLocation();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ TitleBlockTemplatesCollection *TitleBlockTemplateLocationChooser::collection() c
|
|||||||
*/
|
*/
|
||||||
QString TitleBlockTemplateLocationChooser::name() const {
|
QString TitleBlockTemplateLocationChooser::name() const {
|
||||||
int template_index = templates_ -> currentIndex();
|
int template_index = templates_ -> currentIndex();
|
||||||
return(template_index ? templates_ -> currentText() : new_name_ -> text());
|
return(template_index != -1 ? templates_ -> currentText() : QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,9 +51,7 @@ QString TitleBlockTemplateLocationChooser::name() const {
|
|||||||
@param location to be displayed by this widget
|
@param location to be displayed by this widget
|
||||||
*/
|
*/
|
||||||
void TitleBlockTemplateLocationChooser::setLocation(const TitleBlockTemplateLocation &location) {
|
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());
|
int index = indexForCollection(location.parentCollection());
|
||||||
if (index == -1 && collections_ -> count() > 1) index = 1;
|
|
||||||
collections_ -> setCurrentIndex(index);
|
collections_ -> setCurrentIndex(index);
|
||||||
|
|
||||||
if (!location.name().isEmpty()) {
|
if (!location.name().isEmpty()) {
|
||||||
@@ -73,17 +71,14 @@ void TitleBlockTemplateLocationChooser::setLocation(const TitleBlockTemplateLoca
|
|||||||
void TitleBlockTemplateLocationChooser::init() {
|
void TitleBlockTemplateLocationChooser::init() {
|
||||||
collections_ = new QComboBox();
|
collections_ = new QComboBox();
|
||||||
templates_ = new QComboBox();
|
templates_ = new QComboBox();
|
||||||
new_name_ = new QLineEdit();
|
|
||||||
|
|
||||||
updateCollections();
|
updateCollections();
|
||||||
connect(collections_, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTemplates()));
|
connect(collections_, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTemplates()));
|
||||||
connect(templates_, SIGNAL(currentIndexChanged(int)), this, SLOT(updateNewName()));
|
|
||||||
|
|
||||||
QFormLayout *form_layout = new QFormLayout();
|
form_layout_ = new QFormLayout();
|
||||||
form_layout -> addRow(tr("Collection parente", "used in save as form"), collections_);
|
form_layout_ -> addRow(tr("Collection parente", "used in save as form"), collections_);
|
||||||
form_layout -> addRow(tr("Modèle existant", "used in save as form"), templates_);
|
form_layout_ -> addRow(tr("Modèle existant", "used in save as form"), templates_);
|
||||||
form_layout -> addRow(tr("ou nouveau nom", "used in save as form"), new_name_);
|
setLayout(form_layout_);
|
||||||
setLayout(form_layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,31 +109,18 @@ void TitleBlockTemplateLocationChooser::updateCollections() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Update the templates list according to the selected project.
|
Update the templates list according to the selected collection.
|
||||||
*/
|
*/
|
||||||
void TitleBlockTemplateLocationChooser::updateTemplates() {
|
void TitleBlockTemplateLocationChooser::updateTemplates() {
|
||||||
TitleBlockTemplatesCollection *current_collection = collection();
|
TitleBlockTemplatesCollection *current_collection = collection();
|
||||||
if (!current_collection) return;
|
if (!current_collection) return;
|
||||||
|
|
||||||
templates_ -> clear();
|
templates_ -> clear();
|
||||||
templates_ -> addItem(tr("Nouveau modèle (entrez son nom)", "combox box entry"), QVariant(false));
|
|
||||||
|
|
||||||
QStringList available_templates = current_collection -> templates();
|
QStringList available_templates = current_collection -> templates();
|
||||||
if (available_templates.count()) {
|
if (available_templates.count()) {
|
||||||
templates_ -> insertSeparator(1);
|
|
||||||
foreach (QString template_name, available_templates) {
|
foreach (QString template_name, available_templates) {
|
||||||
templates_ -> addItem(template_name, QVariant(true));
|
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,27 +36,26 @@ class TitleBlockTemplateLocationChooser : public QWidget {
|
|||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
TitleBlockTemplateLocation location() const;
|
virtual TitleBlockTemplateLocation location() const;
|
||||||
TitleBlockTemplatesCollection *collection() const;
|
virtual TitleBlockTemplatesCollection *collection() const;
|
||||||
QString name() const;
|
virtual QString name() const;
|
||||||
void setLocation(const TitleBlockTemplateLocation &);
|
virtual void setLocation(const TitleBlockTemplateLocation &);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void init();
|
void init();
|
||||||
int indexForCollection(TitleBlockTemplatesCollection *) const;
|
virtual int indexForCollection(TitleBlockTemplatesCollection *) const;
|
||||||
|
|
||||||
// slots
|
// slots
|
||||||
private slots:
|
protected slots:
|
||||||
void updateCollections();
|
virtual void updateCollections();
|
||||||
void updateTemplates();
|
virtual void updateTemplates();
|
||||||
void updateNewName();
|
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
protected:
|
||||||
|
QFormLayout *form_layout_;
|
||||||
QComboBox *collections_; ///< Collections combo box
|
QComboBox *collections_; ///< Collections combo box
|
||||||
/// Collections index within the combo box
|
/// Collections index within the combo box
|
||||||
QHash<int, TitleBlockTemplatesCollection *> collections_index_;
|
QHash<int, TitleBlockTemplatesCollection *> collections_index_;
|
||||||
QComboBox *templates_; ///< Existing templates combo box
|
QComboBox *templates_; ///< Existing templates combo box
|
||||||
QLineEdit *new_name_; ///< New template name textfield
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
87
sources/titleblock/templatelocationsaver.cpp
Normal file
87
sources/titleblock/templatelocationsaver.cpp
Normal file
@@ -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è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);
|
||||||
|
}
|
||||||
55
sources/titleblock/templatelocationsaver.h
Normal file
55
sources/titleblock/templatelocationsaver.h
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user