Clean some code

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4264 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-11-16 08:59:43 +00:00
parent 6346130cb9
commit d773581bdd
5 changed files with 27 additions and 106 deletions

View File

@@ -929,10 +929,10 @@ void Diagram::titleBlockTemplateChanged(const QString &template_name) {
@param template_name Name of the title block template that has changed @param template_name Name of the title block template that has changed
@param new_template (Optional) Name of the title block template to use instead @param new_template (Optional) Name of the title block template to use instead
*/ */
void Diagram::titleBlockTemplateRemoved(const QString &template_name, const QString &new_template) { void Diagram::titleBlockTemplateRemoved(const QString &template_name, const QString &new_template)
{
if (border_and_titleblock.titleBlockTemplateName() != template_name) return; if (border_and_titleblock.titleBlockTemplateName() != template_name) return;
const TitleBlockTemplate *final_template = project_->embeddedTitleBlockTemplatesCollection()->getTemplate(new_template);
const TitleBlockTemplate *final_template = project_ -> getTemplateByName(new_template);
border_and_titleblock.titleBlockTemplateRemoved(template_name, final_template); border_and_titleblock.titleBlockTemplateRemoved(template_name, final_template);
update(); update();
} }
@@ -941,16 +941,16 @@ void Diagram::titleBlockTemplateRemoved(const QString &template_name, const QStr
Set the template to use to render the title block of this diagram. Set the template to use to render the title block of this diagram.
@param template_name Name of the title block template. @param template_name Name of the title block template.
*/ */
void Diagram::setTitleBlockTemplate(const QString &template_name) { void Diagram::setTitleBlockTemplate(const QString &template_name)
{
if (!project_) return; if (!project_) return;
QString current_name = border_and_titleblock.titleBlockTemplateName(); QString current_name = border_and_titleblock.titleBlockTemplateName();
const TitleBlockTemplate *titleblock_template = project_ -> getTemplateByName(template_name); const TitleBlockTemplate *titleblock_template = project_->embeddedTitleBlockTemplatesCollection()->getTemplate(template_name);
border_and_titleblock.titleBlockTemplateRemoved(current_name, titleblock_template); border_and_titleblock.titleBlockTemplateRemoved(current_name, titleblock_template);
if (template_name != current_name) { if (template_name != current_name)
emit(usedTitleBlockTemplateChanged(template_name)); emit(usedTitleBlockTemplateChanged(template_name));
}
} }
/** /**

View File

@@ -726,9 +726,10 @@ int ProjectView::cleanProject() {
connect(buttons, SIGNAL(rejected()), &clean_dialog, SLOT(reject())); connect(buttons, SIGNAL(rejected()), &clean_dialog, SLOT(reject()));
int clean_count = 0; int clean_count = 0;
if (clean_dialog.exec() == QDialog::Accepted) { if (clean_dialog.exec() == QDialog::Accepted)
{
if (clean_tbt -> isChecked()) { if (clean_tbt -> isChecked()) {
project_ -> cleanUnusedTitleBlocKTemplates(); project_->embeddedTitleBlockTemplatesCollection()->deleteUnusedTitleBlocKTemplates();
} }
if (clean_elements -> isChecked()) { if (clean_elements -> isChecked()) {
InteractiveMoveElementsHandler *handler = new InteractiveMoveElementsHandler(this); InteractiveMoveElementsHandler *handler = new InteractiveMoveElementsHandler(this);

View File

@@ -337,53 +337,6 @@ void QETProject::setTitle(const QString &title) {
updateDiagramsFolioData(); updateDiagramsFolioData();
} }
/**
@return the list of the titleblock templates embedded within this project
*/
QList<QString> QETProject::embeddedTitleBlockTemplates() {
return(titleblocks_.templates());
}
/**
@param template_name Name of the requested template
@return the requested template, or 0 if there is no valid template of this
name within the project
*/
const TitleBlockTemplate *QETProject::getTemplateByName(const QString &template_name) {
return(titleblocks_.getTemplate(template_name));
}
/**
@param template_name Name of the requested template
@return the XML description of the requested template, or a null QDomElement
if the project does not have such an titleblock template
*/
QDomElement QETProject::getTemplateXmlDescriptionByName(const QString &template_name) {
return(titleblocks_.getTemplateXmlDescription(template_name));
}
/**
This methods allows adding or modifying a template embedded within the
project.
@param template_name Name / Identifier of the template - will be used to
determine whether the given description will be added or will replace an
existing one.
@param xml_elmt An \<titleblocktemplate\> XML element describing the
template. Its "name" attribute must equal to template_name.
@return false if a problem occured, true otherwise
*/
bool QETProject::setTemplateXmlDescription(const QString &template_name, const QDomElement &xml_elmt) {
return(titleblocks_.setTemplateXmlDescription(template_name, xml_elmt));
}
/**
This methods allows removing a template embedded within the project.
@param template_name Name of the template to be removed
*/
void QETProject::removeTemplateByName(const QString &template_name) {
return(titleblocks_.removeTemplate(template_name));
}
/** /**
@return les dimensions par defaut utilisees lors de la creation d'un @return les dimensions par defaut utilisees lors de la creation d'un
nouveau schema dans ce projet. nouveau schema dans ce projet.
@@ -839,11 +792,8 @@ QString QETProject::integrateTitleBlockTemplate(const TitleBlockTemplateLocation
} }
} }
bool integration = setTemplateXmlDescription( if (!titleblocks_.setTemplateXmlDescription(target_name, src_tbt.getTemplateXmlDescription()))
target_name, {
src_tbt.getTemplateXmlDescription()
);
if (!integration) {
handler -> errorWithATemplate(src_tbt, tr("Une erreur s'est produite durant l'intégration du modèle.", "error message")); handler -> errorWithATemplate(src_tbt, tr("Une erreur s'est produite durant l'intégration du modèle.", "error message"));
target_name = QString(); target_name = QString();
} }
@@ -882,13 +832,6 @@ bool QETProject::usesTitleBlockTemplate(const TitleBlockTemplateLocation &locati
return(false); return(false);
} }
/**
Delete all title block templates not used in the project
*/
void QETProject::cleanUnusedTitleBlocKTemplates() {
titleblocks_.deleteUnusedTitleBlocKTemplates();
}
/** /**
Supprime tous les elements inutilises dans le projet Supprime tous les elements inutilises dans le projet
@param handler Gestionnaire d'erreur @param handler Gestionnaire d'erreur
@@ -1112,7 +1055,7 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
//Load the default properties for the new diagrams //Load the default properties for the new diagrams
readDefaultPropertiesXml(xml_project); readDefaultPropertiesXml(xml_project);
//load the embedded titleblock templates //load the embedded titleblock templates
readEmbeddedTemplatesXml(xml_project); titleblocks_.fromXml(xml_project.documentElement());
//Load the embedded elements collection //Load the embedded elements collection
readElementsCollectionXml(xml_project); readElementsCollectionXml(xml_project);
//Load the diagrams //Load the diagrams
@@ -1180,15 +1123,6 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
delete dlgWaiting; delete dlgWaiting;
} }
/**
* @brief QETProject::readEmbeddedTemplatesXml
* Loads the embedded template from the XML description of the project
* @param xml_project : the xml description of the project
*/
void QETProject::readEmbeddedTemplatesXml(QDomDocument &xml_project) {
titleblocks_.fromXml(xml_project.documentElement());
}
/** /**
* @brief QETProject::readElementsCollectionXml * @brief QETProject::readElementsCollectionXml
* Load the diagrams from the xml description of the project * Load the diagrams from the xml description of the project
@@ -1461,16 +1395,6 @@ bool QETProject::embeddedCollectionWasModified() {
return(false); return(false);
} }
/**
@return true if the embedded title block templates collection was modified,
false otherwise.
*/
bool QETProject::titleBlockTemplateCollectionWasModified() {
// we do not expect a new project to embed any title block template (this may
// change in the future though).
return(titleblocks_.templates().count());
}
/** /**
@return the project-wide properties made available to child diagrams. @return the project-wide properties made available to child diagrams.
*/ */
@@ -1500,7 +1424,7 @@ bool QETProject::projectWasModified() {
if ( projectOptionsWereModified() || if ( projectOptionsWereModified() ||
!undo_stack_ -> isClean() || !undo_stack_ -> isClean() ||
embeddedCollectionWasModified() || embeddedCollectionWasModified() ||
titleBlockTemplateCollectionWasModified() ) titleblocks_.templates().count() )
return(true); return(true);
else else

View File

@@ -93,11 +93,6 @@ class QETProject : public QObject
QString title() const; QString title() const;
qreal declaredQElectroTechVersion(); qreal declaredQElectroTechVersion();
void setTitle(const QString &); void setTitle(const QString &);
QList<QString> embeddedTitleBlockTemplates();
const TitleBlockTemplate *getTemplateByName(const QString &template_name);
QDomElement getTemplateXmlDescriptionByName(const QString &);
bool setTemplateXmlDescription(const QString &, const QDomElement &);
void removeTemplateByName(const QString &);
///DEFAULT PROPERTIES ///DEFAULT PROPERTIES
BorderProperties defaultBorderProperties() const; BorderProperties defaultBorderProperties() const;
@@ -138,13 +133,11 @@ class QETProject : public QObject
QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler); QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler);
bool usesElement(const ElementsLocation &); bool usesElement(const ElementsLocation &);
bool usesTitleBlockTemplate(const TitleBlockTemplateLocation &); bool usesTitleBlockTemplate(const TitleBlockTemplateLocation &);
void cleanUnusedTitleBlocKTemplates();
void cleanUnusedElements(MoveElementsHandler *); void cleanUnusedElements(MoveElementsHandler *);
void cleanEmptyCategories(MoveElementsHandler *); void cleanEmptyCategories(MoveElementsHandler *);
bool projectWasModified(); bool projectWasModified();
bool projectOptionsWereModified(); bool projectOptionsWereModified();
bool embeddedCollectionWasModified(); bool embeddedCollectionWasModified();
bool titleBlockTemplateCollectionWasModified();
DiagramContext projectProperties(); DiagramContext projectProperties();
void setProjectProperties(const DiagramContext &); void setProjectProperties(const DiagramContext &);
QUndoStack* undoStack() {return undo_stack_;} QUndoStack* undoStack() {return undo_stack_;}
@@ -184,7 +177,6 @@ class QETProject : public QObject
void readProjectXml(QDomDocument &xml_project); void readProjectXml(QDomDocument &xml_project);
void readDiagramsXml(QDomDocument &xml_project); void readDiagramsXml(QDomDocument &xml_project);
void readEmbeddedTemplatesXml(QDomDocument &xml_project);
void readElementsCollectionXml(QDomDocument &xml_project); void readElementsCollectionXml(QDomDocument &xml_project);
void readProjectPropertiesXml(QDomDocument &xml_project); void readProjectPropertiesXml(QDomDocument &xml_project);
void readDefaultPropertiesXml(QDomDocument &xml_project); void readDefaultPropertiesXml(QDomDocument &xml_project);

View File

@@ -210,18 +210,22 @@ bool QETTitleBlockTemplateEditor::edit(const TitleBlockTemplateLocation &locatio
@param template_name Name of the template to edit within its parent project. @param template_name Name of the template to edit within its parent project.
@return true if this editor was able to edit the given template, false otherwise @return true if this editor was able to edit the given template, false otherwise
*/ */
bool QETTitleBlockTemplateEditor::edit(QETProject *project, const QString &template_name) { bool QETTitleBlockTemplateEditor::edit(QETProject *project, const QString &template_name)
{
// we require a project we will rattach templates to // we require a project we will rattach templates to
if (!project) return(false); if (!project) return(false);
// the template name may be empty to create a new one // the template name may be empty to create a new one
const TitleBlockTemplate *tb_template_orig; const TitleBlockTemplate *tb_template_orig;
if (template_name.isEmpty()) { if (template_name.isEmpty())
{
// loads the default title block template provided by the application // loads the default title block template provided by the application
// it will be used as a start point to design the title block // it will be used as a start point to design the title block
tb_template_orig = QETApp::defaultTitleBlockTemplate(); tb_template_orig = QETApp::defaultTitleBlockTemplate();
} else { }
tb_template_orig = project -> getTemplateByName(template_name); else
{
tb_template_orig = project->embeddedTitleBlockTemplatesCollection()->getTemplate(template_name);
} }
if (!tb_template_orig) { if (!tb_template_orig) {