Title block template editor: implemented "Save as" action.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1410 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2011-12-26 05:42:48 +00:00
parent 188dabf88a
commit 5b6bea0601
18 changed files with 984 additions and 243 deletions

View File

@@ -68,7 +68,7 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) {
prj_del_diagram = new QAction(QET::Icons::DiagramDelete, tr("Supprimer ce sch\351ma"), this);
prj_move_diagram_up = new QAction(QET::Icons::GoUp, tr("Remonter ce sch\351ma"), this);
prj_move_diagram_down = new QAction(QET::Icons::GoDown, tr("Abaisser ce sch\351ma"), this);
tbt_add = new QAction(QET::Icons::TitleBlock, tr("Importer un nouveau mod\350le"), this);
tbt_add = new QAction(QET::Icons::TitleBlock, tr("Nouveau mod\350le"), this);
tbt_edit = new QAction(QET::Icons::TitleBlock, tr("\311diter ce mod\350le"), this);
tbt_remove = new QAction(QET::Icons::TitleBlock, tr("Supprimer ce mod\350le"), this);
move_elements_ = new QAction(QET::Icons::MoveFile, tr("D\351placer dans cette cat\351gorie"), this);

View File

@@ -22,6 +22,7 @@
#include "templatecellwidget.h"
#include "templatecommands.h"
#include "templateview.h"
#include "templatelocationchooser.h"
#include "templatelogomanager.h"
#include "templatecellwidget.h"
@@ -46,6 +47,13 @@ QETTitleBlockTemplateEditor::QETTitleBlockTemplateEditor(QWidget *parent) :
QETTitleBlockTemplateEditor::~QETTitleBlockTemplateEditor() {
}
/**
@return the location of the currently edited template
*/
TitleBlockTemplateLocation QETTitleBlockTemplateEditor::location() const {
return(TitleBlockTemplateLocation(parent_project_, template_name_));
}
/**
Edit the given template.
@param project Parent project of the template to edit.
@@ -101,6 +109,7 @@ void QETTitleBlockTemplateEditor::initActions() {
QETApp *qet_app = QETApp::instance();
save_ = new QAction(QET::Icons::DocumentSave, tr("&Enregistrer", "menu entry"), this);
save_as_ = new QAction(QET::Icons::DocumentSave, tr("Enregistrer sous", "menu entry"), this);
quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "menu entry"), this);
configure_ = new QAction(QET::Icons::Configure, tr("&Configurer QElectroTech", "menu entry"), this);
about_qet_ = new QAction(QET::Icons::QETLogo, tr("\300 &propos de QElectroTech", "menu entry"), this);
@@ -118,6 +127,7 @@ void QETTitleBlockTemplateEditor::initActions() {
about_qt_ -> setStatusTip(tr("Affiche des informations sur la biblioth\350que Qt", "status bar tip"));
connect(save_, SIGNAL(triggered()), this, SLOT(save()));
connect(save_as_, SIGNAL(triggered()), this, SLOT(saveAs()));
connect(quit_, SIGNAL(triggered()), this, SLOT(quit()));
connect(configure_, SIGNAL(triggered()), qet_app, SLOT(configureQET()));
connect(about_qet_, SIGNAL(triggered()), qet_app, SLOT(aboutQET()));
@@ -141,6 +151,7 @@ void QETTitleBlockTemplateEditor::initMenus() {
help_menu_ -> setTearOffEnabled(true);
file_menu_ -> addAction(save_);
file_menu_ -> addAction(save_as_);
file_menu_ -> addSeparator();
file_menu_ -> addAction(quit_);
@@ -273,19 +284,72 @@ void QETTitleBlockTemplateEditor::updateEditorTitle() {
}
/**
Save the currently edited title block template back to its parent project.
Save the template as \a name within \a project.
@see QETProject::setTemplateXmlDescription()
@param project Parent project
@param name Template name
*/
void QETTitleBlockTemplateEditor::save() {
void QETTitleBlockTemplateEditor::saveAs(QETProject *project, const QString &name) {
if (!project || name.isEmpty()) return;
QDomDocument doc;
QDomElement elmt = doc.createElement("root");
tb_template_ -> saveToXmlElement(elmt);
elmt.setAttribute("name", name);
doc.appendChild(elmt);
project -> setTemplateXmlDescription(name, elmt);
parent_project_ = project;
template_name_ = name;
}
/**
Save the currently edited title block template back to its parent project.
*/
void QETTitleBlockTemplateEditor::save() {
if (parent_project_ && !template_name_.isEmpty()) {
parent_project_ -> setTemplateXmlDescription(template_name_, elmt);
saveAs(parent_project_, template_name_);
} else {
saveAs();
}
}
/**
Ask the user where he wishes to save the currently edited template.
*/
void QETTitleBlockTemplateEditor::saveAs() {
TitleBlockTemplateLocation location = getTitleBlockTemplateLocationFromUser();
if (location.isValid()) {
saveAs(location.project(), location.name());
}
}
/**
Ask the user for a title block template location
@return The location chosen by the user, or an empty TitleBlockTemplateLocation if the user cancelled the dialog
*/
TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLocationFromUser() {
TitleBlockTemplateLocationChooser *chooser = new TitleBlockTemplateLocationChooser(location());
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QVBoxLayout *dialog_layout = new QVBoxLayout();
dialog_layout -> addWidget(chooser);
dialog_layout -> addWidget(buttons);
QDialog dialog;
dialog.setWindowTitle(tr("Enregistrer le mod\350le sous", "dialog window title"));
dialog.setLayout(dialog_layout);
connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
if (dialog.exec() == QDialog::Accepted) {
return(chooser -> location());
}
return TitleBlockTemplateLocation();
}
/**
Close the current editor.
*/

View File

@@ -20,6 +20,7 @@
#include <QtGui>
#include "qet.h"
#include "templateview.h"
#include "templatelocation.h"
class ModifyTitleBlockCellCommand;
class TitleBlockTemplateCommand;
class TitleBlockTemplateCellWidget;
@@ -48,7 +49,7 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
/// menus TODO
QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, *display_menu_, *tools_menu_,*/ *config_menu_, *help_menu_;
/// actions
QAction *save_, *quit_, *configure_, *about_qt_, *about_qet_, *merge_cells_, *split_cell_;
QAction *save_, *save_as_, *quit_, *configure_, *about_qt_, *about_qet_, *merge_cells_, *split_cell_;
/// Parent project of the currently edited template
QETProject *parent_project_;
/// Name of the currently edited template
@@ -70,6 +71,7 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
// methods
public:
TitleBlockTemplateLocation location() const;
protected:
@@ -82,14 +84,17 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
void selectedCellsChanged(QList<TitleBlockCell *>);
bool edit(QETProject *, const QString &);
void editLogos();
void save();
void saveAs();
void quit();
private slots:
TitleBlockTemplateLocation getTitleBlockTemplateLocationFromUser();
void pushCellUndoCommand(ModifyTitleBlockCellCommand *);
void pushGridUndoCommand(TitleBlockTemplateCommand *);
void pushUndoCommand(QUndoCommand *);
void updateEditorTitle();
void save();
void quit();
void saveAs(QETProject *, const QString &);
};
#endif

View File

@@ -0,0 +1,71 @@
/*
Copyright 2006-2011 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/>.
*/
#include "templatelocation.h"
/**
Constructor
@param project Parent project of the title block template
@param name Name of the title block template within its parent project or collection
*/
TitleBlockTemplateLocation::TitleBlockTemplateLocation(QETProject *project, const QString &name) :
project_(project),
name_(name)
{
}
/**
Destructor
*/
TitleBlockTemplateLocation::~TitleBlockTemplateLocation() {
}
/**
@return the parent project of the template, or 0 if none was defined
*/
QETProject *TitleBlockTemplateLocation::project() const {
return(project_);
}
/**
@param project The new parent project of the template, or 0 if none
applies.
*/
void TitleBlockTemplateLocation::setProject(QETProject *project) {
project_ = project;
}
/**
@return the name of this template within its parent project or collection.
*/
QString TitleBlockTemplateLocation::name() const {
return(name_);
}
/**
@param name The new name of this template.
*/
void TitleBlockTemplateLocation::setName(const QString &name) {
name_ = name;
}
/**
@return true if this location is null, false otherwise
*/
bool TitleBlockTemplateLocation::isValid() const {
return(project_ && !name_.isEmpty());
}

View File

@@ -0,0 +1,45 @@
/*
Copyright 2006-2011 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_TEMPLATE_LOCATION_H
#define TITLEBLOCK_SLASH_TEMPLATE_LOCATION_H
#include <QtCore>
class QETProject;
/**
This class represents the location of a title block template.
*/
class TitleBlockTemplateLocation {
// constructor, destructor
public:
TitleBlockTemplateLocation(QETProject * = 0, const QString & = QString());
virtual ~TitleBlockTemplateLocation();
// methods
public:
QETProject *project() const;
void setProject(QETProject *);
QString name() const;
void setName(const QString &);
bool isValid() const;
// attributes
private:
QETProject *project_; ///< Parent project of the template, if any
QString name_; ///< Name of the template
};
#endif

View File

@@ -0,0 +1,118 @@
#include "templatelocationchooser.h"
#include "qetapp.h"
#include "qetproject.h"
/**
Constructor
@param location Initial location displayed by the widget
@param widget Parent QWidget
*/
TitleBlockTemplateLocationChooser::TitleBlockTemplateLocationChooser(
const TitleBlockTemplateLocation &location,
QWidget *parent
) :
QWidget(parent)
{
init();
setLocation(location);
}
/**
Destructor
*/
TitleBlockTemplateLocationChooser::~TitleBlockTemplateLocationChooser() {
}
/**
@return the current location
*/
TitleBlockTemplateLocation TitleBlockTemplateLocationChooser::location() const {
return(TitleBlockTemplateLocation(project(), name()));
}
/**
@return the currently selected project
*/
QETProject *TitleBlockTemplateLocationChooser::project() const {
uint project_id = projects_ -> itemData(projects_ -> currentIndex()).toUInt();
return(QETApp::project(project_id));
}
/**
@return the currently selected/entered name
*/
QString TitleBlockTemplateLocationChooser::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 TitleBlockTemplateLocationChooser::setLocation(const TitleBlockTemplateLocation &location) {
// we need a project id
int project_id = QETApp::projectId(location.project());
if (project_id == -1) return;
// attempt to find this project id in our project combo box
int project_index = projects_ -> findData(QVariant(static_cast<uint>(project_id)));
if (project_index == -1) return;
projects_ -> setCurrentIndex(project_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 TitleBlockTemplateLocationChooser::init() {
projects_ = new QComboBox();
templates_ = new QComboBox();
new_name_ = new QLineEdit();
QMap<uint, QETProject *> projects = QETApp::registeredProjects();
foreach (uint project_id, projects.keys()) {
projects_ -> addItem(projects[project_id] -> title(), project_id);
}
updateTemplates();
connect(projects_, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTemplates()));
QFormLayout *form_layout = new QFormLayout();
form_layout -> addRow(tr("Projet parent", "used in save as form"), projects_);
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);
}
/**
Update the templates list according to the selected project.
*/
void TitleBlockTemplateLocationChooser::updateTemplates() {
int current_index = projects_ -> currentIndex();
if (current_index == -1) return;
uint project_id = projects_ -> itemData(current_index).toUInt();
QETProject *project = QETApp::project(project_id);
if (!project) return;
templates_ -> clear();
templates_ -> addItem(tr("Nouveau modèle (entrez son nom)", "combox box entry"), QVariant(false));
QStringList available_templates = project -> embeddedTitleBlockTemplates();
if (available_templates.count()) {
templates_ -> insertSeparator(1);
foreach (QString template_name, available_templates) {
templates_ -> addItem(template_name, QVariant(true));
}
}
}

View File

@@ -0,0 +1,54 @@
/*
Copyright 2006-2011 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_CHOOSER_H
#define TITLEBLOCK_SLASH_LOCATION_CHOOSER_H
#include <QtGui>
#include "templatelocation.h"
/**
This class is a widget that allows the user to choose a target title block
template.
*/
class TitleBlockTemplateLocationChooser : public QWidget {
Q_OBJECT
// Constructor, destructor
public:
TitleBlockTemplateLocationChooser(const TitleBlockTemplateLocation &, QWidget * = 0);
~TitleBlockTemplateLocationChooser();
private:
TitleBlockTemplateLocationChooser(const TitleBlockTemplateLocationChooser &);
// methods
public:
TitleBlockTemplateLocation location() const;
QETProject *project() const;
QString name() const;
void setLocation(const TitleBlockTemplateLocation &);
private:
void init();
// slots
private slots:
void updateTemplates();
// attributes
private:
QComboBox *projects_; ///< Projects combo box
QComboBox *templates_; ///< Existing templates combo box
QLineEdit *new_name_; ///< New template name textfield
};
#endif