When editing a diagram, it is now possible to edit and/or duplicate a title block template from the title block properties dialog.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1479 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-01-25 07:29:50 +00:00
parent cae43d0fc1
commit 0345e54512
11 changed files with 174 additions and 16 deletions

View File

@@ -455,6 +455,7 @@ void DiagramView::editDiagramProperties() {
// construit le dialogue
QDialog popup(diagramEditor());
popup.setWindowModality(Qt::WindowModal);
#ifdef Q_WS_MAC
popup.setWindowFlags(Qt::Sheet);
#endif
@@ -473,6 +474,8 @@ void DiagramView::editDiagramProperties() {
// we have to parse again the TitleBlockProperties object, since the
// first parsing did not know of our templates
titleblock_infos -> setTitleBlockProperties(titleblock);
// relay the signal that requires a title block template edition
connect(titleblock_infos, SIGNAL(editTitleBlockTemplate(QString, bool)), this, SIGNAL(editTitleBlockTemplate(QString, bool)));
}
titleblock_infos -> setReadOnly(diagram_is_read_only);

View File

@@ -103,6 +103,8 @@ class DiagramView : public QGraphicsView {
void findElementRequired(const ElementsLocation &);
/// Signal emis lorsque l'utilisateur souhaite editer un element du schema
void editElementRequired(const ElementsLocation &);
/// Signal emitted when the user wants to edit and/or duplicate an existing title block template
void editTitleBlockTemplate(const QString &, bool);
public slots:
void selectNothing();

View File

@@ -313,6 +313,7 @@ void ProjectView::addDiagram(DiagramView *diagram) {
connect(diagram, SIGNAL(titleChanged(DiagramView *, const QString &)), this, SLOT(updateTabTitle(DiagramView *, const QString &)));
connect(diagram, SIGNAL(findElementRequired(const ElementsLocation &)), this, SIGNAL(findElementRequired(const ElementsLocation &)));
connect(diagram, SIGNAL(editElementRequired(const ElementsLocation &)), this, SIGNAL(editElementRequired(const ElementsLocation &)));
connect(diagram, SIGNAL(editTitleBlockTemplate(const QString &, bool)), this, SLOT(editTitleBlockTemplateRequired(const QString &, bool)));
// signale l'ajout du schema
emit(diagramAdded(diagram));
@@ -807,6 +808,22 @@ void ProjectView::tabMoved(int from, int to) {
emit(diagramOrderChanged(this, from, to));
}
/**
Require the edition of the \a template_name title blocke template.
@param template_name Name of the tempalte to be edited
@param duplicate If true, this methd will ask the user for a template name
in order to duplicate the \a template_name template
*/
void ProjectView::editTitleBlockTemplateRequired(const QString &template_name, bool duplicate) {
if (!project_) return;
emit(
editTitleBlockTemplate(
project_ -> embeddedTitleBlockTemplatesCollection() -> location(template_name),
duplicate
)
);
}
/**
@param diagram Schema a trouver
@return le DiagramView correspondant au schema passe en parametre, ou 0 si

View File

@@ -18,6 +18,7 @@
#ifndef PROJECT_VIEW_H
#define PROJECT_VIEW_H
#include <QtGui>
#include "templatelocation.h"
class QETProject;
class DiagramView;
class Diagram;
@@ -67,6 +68,7 @@ class ProjectView : public QWidget {
void updateWindowTitle();
void updateTabTitle(DiagramView *, const QString &);
void tabMoved(int, int);
void editTitleBlockTemplateRequired(const QString &, bool);
signals:
void diagramAdded(DiagramView *);
@@ -75,9 +77,10 @@ class ProjectView : public QWidget {
void diagramActivated(DiagramView *);
void diagramOrderChanged(ProjectView *, int, int);
void projectClosed(ProjectView *);
// Pour relayer les signaux
// relayed signals
void findElementRequired(const ElementsLocation &);
void editElementRequired(const ElementsLocation &);
void editTitleBlockTemplate(const TitleBlockTemplateLocation &, bool);
private:
void loadDiagrams();

View File

@@ -1013,9 +1013,14 @@ void QETApp::openElementLocations(const QList<ElementsLocation> &locations_list)
/**
Launch a new title block template editor to edit the given template
@param location location of the title block template to be edited
@param duplicate if true, the template is opened for duplication, which means
the user will be prompter for a new template name.
@see QETTitleBlockTemplateEditor::setOpenForDuplication()
*/
void QETApp::openTitleBlockTemplate(const TitleBlockTemplateLocation &location) {
void QETApp::openTitleBlockTemplate(const TitleBlockTemplateLocation &location, bool duplicate) {
QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
qet_template_editor -> setOpenForDuplication(duplicate);
qet_template_editor -> edit(location);
qet_template_editor -> showMaximized();
}

View File

@@ -199,7 +199,7 @@ class QETApp : public QETSingleApplication {
void openProjectFiles(const QStringList &);
void openElementFiles(const QStringList &);
void openElementLocations(const QList<ElementsLocation> &);
void openTitleBlockTemplate(const TitleBlockTemplateLocation &);
void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool = false);
void openTitleBlockTemplate(const QString &);
void configureQET();
void aboutQET();

View File

@@ -1264,10 +1264,16 @@ void QETDiagramEditor::addProjectView(ProjectView *project_view) {
// gere les demandes consistant a retrouver un element dans le panel
connect(project_view, SIGNAL(findElementRequired(const ElementsLocation &)), this, SLOT(findElementInPanel(const ElementsLocation &)));
// gere les demandes pour l'edition d'un element
connect(project_view, SIGNAL(editElementRequired(const ElementsLocation &)), this, SLOT(editElementInEditor(const ElementsLocation &)));
// handles requests to edit and/or duplicate an existing title block template
connect(
project_view, SIGNAL(editTitleBlockTemplate(const TitleBlockTemplateLocation &, bool)),
QETApp::instance(), SLOT(openTitleBlockTemplate(TitleBlockTemplateLocation, bool))
);
// affiche la fenetre
if (maximise) project_view -> showMaximized();
else project_view -> show();

View File

@@ -34,6 +34,8 @@ QETTitleBlockTemplateEditor::QETTitleBlockTemplateEditor(QWidget *parent) :
QMainWindow(parent),
opened_from_file_(false),
read_only_(false),
duplicate_(false),
first_activation_(true),
tb_template_(0),
logo_manager_(0)
{
@@ -59,6 +61,22 @@ TitleBlockTemplateLocation QETTitleBlockTemplateEditor::location() const {
return(location_);
}
/**
@param true for this editor to prompt the user for a new template name as
soon as the window appears in order to duplicate the edited one.
*/
void QETTitleBlockTemplateEditor::setOpenForDuplication(bool duplicate) {
duplicate_ = duplicate;
}
/**
@return true if this editor will prompt the user for a new template name as
soon as the window appears in order to duplicate the edited one.
*/
bool QETTitleBlockTemplateEditor::openForDuplication() const {
return(duplicate_);
}
/**
@return true if the currently edited template can be closed. A template can be
closed if it has not been modified. If the template has been modified, this
@@ -88,6 +106,20 @@ bool QETTitleBlockTemplateEditor::canClose() {
return(result);
}
/**
@param event Object describing the received event.
*/
bool QETTitleBlockTemplateEditor::event(QEvent *event) {
if (first_activation_ && event -> type() == QEvent::WindowActivate) {
if (duplicate_ && !opened_from_file_ && location_.isValid()) {
// this editor is supposed to duplicate its current location
QTimer::singleShot(250, this, SLOT(duplicateCurrentLocation()));
}
first_activation_ = false;
}
return(QMainWindow::event(event));
}
/**
Handle the closing of the main window
@param qce The QCloseEvent event
@@ -99,6 +131,29 @@ void QETTitleBlockTemplateEditor::closeEvent(QCloseEvent *qce) {
} else qce -> ignore();
}
/**
Ask the user for a new template name in order to duplicate the currently
edited template.
*/
void QETTitleBlockTemplateEditor::duplicateCurrentLocation() {
// this method does not work for templates edited from the filesystem
if (opened_from_file_) return;
bool accepted = false;
QString new_template_name = QInputDialog::getText(
this,
tr("Dupliquer un mod\350le de cartouche", "input dialog title"),
tr("Pour dupliquer ce mod\350le, entrez le nom voulu pour sa copie", "input dialog text"),
QLineEdit::Normal,
QString("%1_copy").arg(location_.name()),
&accepted
);
if (accepted) {
TitleBlockTemplateLocation new_template_location(new_template_name, location_.parentCollection());
saveAs(new_template_location);
}
}
/**
@param location Location of the tile block template to be edited.
*/
@@ -665,13 +720,14 @@ bool QETTitleBlockTemplateEditor::saveAsFile() {
currently edited template, false to allow full edition.
*/
void QETTitleBlockTemplateEditor::setReadOnly(bool read_only) {
if (read_only == read_only_) return;
read_only_ = read_only;
if (logo_manager_) {
logo_manager_ -> setReadOnly(read_only_);
if (read_only != read_only_) {
read_only_ = read_only;
if (logo_manager_) {
logo_manager_ -> setReadOnly(read_only_);
}
template_cell_editor_widget_ -> setReadOnly(read_only_);
template_edition_area_view_ -> setReadOnly(read_only_);
}
template_cell_editor_widget_ -> setReadOnly(read_only_);
template_edition_area_view_ -> setReadOnly(read_only_);
updateActions();
updateEditorTitle();
}

View File

@@ -60,6 +60,13 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
bool opened_from_file_;
/// whether the currently edited template is considered read only
bool read_only_;
/**
Whether to ask the user a new template name when the window appears in order
to rename the edited template.
*/
bool duplicate_;
/// Used to track the first activation of the editor main window.
bool first_activation_;
/// Template Object edited
TitleBlockTemplate *tb_template_;
/// Template preview
@@ -78,9 +85,12 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
// methods
public:
TitleBlockTemplateLocation location() const;
void setOpenForDuplication(bool);
bool openForDuplication() const;
protected:
bool canClose();
bool event(QEvent *);
void closeEvent(QCloseEvent *);
private:
@@ -92,6 +102,7 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
public slots:
void selectedCellsChanged(QList<TitleBlockCell *>);
void duplicateCurrentLocation();
bool edit(const TitleBlockTemplateLocation &);
bool edit(QETProject *, const QString &);
bool edit(const QString &);

View File

@@ -17,7 +17,6 @@
*/
#include "titleblockpropertieswidget.h"
#include "qeticons.h"
#include "qetapp.h"
/**
Constructeur
@@ -39,6 +38,7 @@ TitleBlockPropertiesWidget::TitleBlockPropertiesWidget(const TitleBlockPropertie
// by default, we do not display the template combo box
titleblock_template_label -> setVisible(false);
titleblock_template_name -> setVisible(false);
titleblock_template_button_ -> setVisible(false);
}
/// Destructeur
@@ -65,10 +65,8 @@ TitleBlockProperties TitleBlockPropertiesWidget::titleBlockProperties() const {
prop.date = QDate::currentDate();
}
int index = titleblock_template_name -> currentIndex();
if (index != -1) {
prop.template_name = titleblock_template_name -> itemData(index).toString();
}
QString current_template_name = currentTitleBlockTemplateName();
if (!current_template_name.isEmpty()) prop.template_name = current_template_name;
for (int i = 0 ; i < additional_fields_table -> rowCount() ; ++ i) {
QTableWidgetItem *qtwi_name = additional_fields_table -> item(i, 0);
@@ -176,6 +174,18 @@ void TitleBlockPropertiesWidget::setTitleBlockTemplatesList(const QList<QString>
void TitleBlockPropertiesWidget::setTitleBlockTemplatesVisible(bool visible) {
titleblock_template_name -> setVisible(visible);
titleblock_template_label -> setVisible(visible);
titleblock_template_button_ -> setVisible(visible);
}
/**
@return the name of the currenlty selected title block template.
*/
QString TitleBlockPropertiesWidget::currentTitleBlockTemplateName() const {
int index = titleblock_template_name -> currentIndex();
if (index != -1) {
return(titleblock_template_name -> itemData(index).toString());
}
return(QString());
}
/**
@@ -190,12 +200,46 @@ void TitleBlockPropertiesWidget::checkTableRows() {
}
}
/**
Edit the currently selected title block template
*/
void TitleBlockPropertiesWidget::editCurrentTitleBlockTemplate() {
QString current_template_name = currentTitleBlockTemplateName();
if (current_template_name.isEmpty()) return;
emit(editTitleBlockTemplate(current_template_name, false));
}
/**
Duplicate the currently selected title block template (the user is asked
for a name), then edit it.
*/
void TitleBlockPropertiesWidget::duplicateCurrentTitleBlockTemplate() {
QString current_template_name = currentTitleBlockTemplateName();
if (current_template_name.isEmpty()) return;
emit(editTitleBlockTemplate(current_template_name, true));
}
/**
Builds the various child widgets for this widget
*/
void TitleBlockPropertiesWidget::initWidgets(const TitleBlockProperties &titleblock) {
// actions
titleblock_template_edit_ = new QAction(tr("\311diter ce mod\350le", "menu entry"), this);
titleblock_template_duplicate_ = new QAction(tr("Dupliquer et editer ce mod\350le", "menu entry"), this);
connect(titleblock_template_edit_, SIGNAL(triggered()), this, SLOT(editCurrentTitleBlockTemplate()));
connect(titleblock_template_duplicate_, SIGNAL(triggered()), this, SLOT(duplicateCurrentTitleBlockTemplate()));
// menu
titleblock_template_menu_ = new QMenu(tr("Title block templates actions"));
titleblock_template_menu_ -> addAction(titleblock_template_edit_);
titleblock_template_menu_ -> addAction(titleblock_template_duplicate_);
// widgets
titleblock_template_label = new QLabel(tr("Mod\350le :"), this);
titleblock_template_name = new QComboBox(this);
titleblock_template_button_ = new QPushButton(QET::Icons::TitleBlock, QString());
titleblock_template_button_ -> setMenu(titleblock_template_menu_);
titleblock_title = new QLineEdit(this);
titleblock_author = new QLineEdit(this);
@@ -301,6 +345,7 @@ void TitleBlockPropertiesWidget::initLayouts() {
QHBoxLayout *template_layout = new QHBoxLayout();
template_layout -> addWidget(titleblock_template_label);
template_layout -> addWidget(titleblock_template_name);
template_layout -> addWidget(titleblock_template_button_);
template_layout -> setStretch(0, 1);
template_layout -> setStretch(1, 500);

View File

@@ -41,10 +41,13 @@ class TitleBlockPropertiesWidget : public QWidget {
void setReadOnly(bool);
void setTitleBlockTemplatesList(const QList<QString> &);
void setTitleBlockTemplatesVisible(bool);
QString currentTitleBlockTemplateName() const;
// slots:
private slots:
void checkTableRows();
void editCurrentTitleBlockTemplate();
void duplicateCurrentTitleBlockTemplate();
// private methods
private:
@@ -52,11 +55,18 @@ class TitleBlockPropertiesWidget : public QWidget {
void initLayouts();
int nameLessRowsCount() const;
signals:
void editTitleBlockTemplate(const QString &, bool);
// attributs
private:
QStackedLayout *stack_layout;
QLabel *titleblock_template_label;
QComboBox *titleblock_template_name;
QPushButton *titleblock_template_button_;
QMenu *titleblock_template_menu_;
QAction *titleblock_template_edit_;
QAction *titleblock_template_duplicate_;
QLineEdit *titleblock_title;
QLineEdit *titleblock_author;
QDateEdit *titleblock_date;