mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Simplify how the diagrams are saved
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4927 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
878e3d5bf0
commit
34d7d134d3
@ -675,12 +675,6 @@ bool Diagram::initFromXml(QDomElement &document, QPointF position, bool consider
|
||||
// import le contenu et les proprietes du schema depuis l'element XML fourni en parametre
|
||||
bool from_xml = fromXml(document, position, consider_informations, content_ptr);
|
||||
|
||||
// initialise le document XML interne a partir de l'element XML fourni en parametre
|
||||
if (from_xml) {
|
||||
xml_document_.clear();
|
||||
xml_document_.appendChild(xml_document_.importNode(document, true));
|
||||
// a ce stade, le document XML interne contient le code XML qui a ete importe, et non pas une version re-exporte par la methode toXml()
|
||||
}
|
||||
return(from_xml);
|
||||
}
|
||||
|
||||
@ -744,7 +738,6 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
||||
|
||||
// if child haven't got a child, loading is finish (diagram is empty)
|
||||
if (root.firstChild().isNull()) {
|
||||
write(document);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@ -937,42 +930,6 @@ void Diagram::folioSequentialsFromXml(const QDomElement &root, QHash<QString, QS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Enregistre le schema XML dans son document XML interne et emet le signal
|
||||
written().
|
||||
*/
|
||||
void Diagram::write()
|
||||
{
|
||||
qDebug() << qPrintable(QString("Diagram::write() : saving changes from diagram \"%1\"").arg(title())) << "[" << this << "]";
|
||||
write(toXml().documentElement());
|
||||
}
|
||||
|
||||
/**
|
||||
Enregistre un element XML dans son document XML interne et emet le signal
|
||||
written().
|
||||
@param element xml a enregistrer
|
||||
*/
|
||||
void Diagram::write(const QDomElement &element) {
|
||||
xml_document_.clear();
|
||||
xml_document_.appendChild(xml_document_.importNode(element, true));
|
||||
emit(written());
|
||||
}
|
||||
|
||||
/**
|
||||
@return le schema en XML tel qu'il doit etre enregistre dans le fichier projet
|
||||
@param xml_doc document XML a utiliser pour creer l'element
|
||||
*/
|
||||
QDomElement Diagram::writeXml(QDomDocument &xml_doc) const
|
||||
{
|
||||
//If diagram was not explicitely saved, we write nothing.
|
||||
if (xml_document_.isNull())
|
||||
return(QDomElement());
|
||||
|
||||
QDomElement diagram_elmt = xml_document_.documentElement();
|
||||
QDomNode new_node = xml_doc.importNode(diagram_elmt, true);
|
||||
return(new_node.toElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Diagram::refreshContents
|
||||
* refresh all content of diagram.
|
||||
|
@ -155,9 +155,6 @@ class Diagram : public QGraphicsScene
|
||||
bool initFromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
|
||||
bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
|
||||
bool fromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
|
||||
void write();
|
||||
void write(const QDomElement &);
|
||||
QDomElement writeXml(QDomDocument &) const;
|
||||
void folioSequentialsToXml(QHash<QString, QStringList>*, QDomElement *, QString, QString, QDomDocument *);
|
||||
void folioSequentialsFromXml(const QDomElement&, QHash<QString, QStringList>*, QString, QString, QString, QString);
|
||||
|
||||
@ -245,7 +242,6 @@ class Diagram : public QGraphicsScene
|
||||
|
||||
signals:
|
||||
void showDiagram (Diagram *);
|
||||
void written();
|
||||
void usedTitleBlockTemplateChanged(const QString &);
|
||||
void diagramTitleChanged(Diagram *, const QString &);
|
||||
void findElementRequired(const ElementsLocation &); /// Signal emitted when users wish to locate an element from the diagram within elements collection
|
||||
|
@ -297,10 +297,6 @@ int ProjectView::tryClosingDiagrams() {
|
||||
| QMessageBox::Cancel,
|
||||
QMessageBox::Save);
|
||||
|
||||
if (close_dialog == QMessageBox::Save) {
|
||||
saveDiagrams(project()->diagrams());
|
||||
}
|
||||
|
||||
return(close_dialog);
|
||||
}
|
||||
|
||||
@ -708,9 +704,6 @@ QETResult ProjectView::doSave()
|
||||
return(saveAs());
|
||||
}
|
||||
|
||||
// look for diagrams matching the required save options
|
||||
saveDiagrams(m_project->diagrams());
|
||||
|
||||
// write to file
|
||||
QETResult result = m_project -> write();
|
||||
updateWindowTitle();
|
||||
@ -718,22 +711,6 @@ QETResult ProjectView::doSave()
|
||||
return(result);
|
||||
}
|
||||
|
||||
/**
|
||||
Save \a diagrams without emitting the written() signal and without writing
|
||||
the project file itself.
|
||||
*/
|
||||
void ProjectView::saveDiagrams(const QList<Diagram *> &diagrams) {
|
||||
foreach (Diagram *diagram, diagrams) {
|
||||
// Diagram::write() emits the written() signal, which is connected
|
||||
// to QETProject::write() through QETProject::componentWritten().
|
||||
// We do not want to write the project immediately, so we block
|
||||
// this signal.
|
||||
diagram -> blockSignals(true);
|
||||
diagram -> write();
|
||||
diagram -> blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Allow the user to clean the project, which includes:
|
||||
* deleting unused title block templates
|
||||
|
@ -85,7 +85,6 @@ class ProjectView : public QWidget
|
||||
QETResult save();
|
||||
QETResult saveAs();
|
||||
QETResult doSave();
|
||||
void saveDiagrams(const QList<Diagram *> &);
|
||||
int cleanProject();
|
||||
void updateWindowTitle();
|
||||
void updateTabTitle(DiagramView *);
|
||||
|
@ -121,7 +121,7 @@ QETProject::QETProject(const QString &path, QObject *parent) :
|
||||
*/
|
||||
QETProject::~QETProject()
|
||||
{
|
||||
qDeleteAll(diagrams_);
|
||||
qDeleteAll(m_diagrams_list);
|
||||
delete undo_stack_;
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ void QETProject::setFolioSheetsQuantity(int quantity) {
|
||||
@return la liste des schemas de ce projet
|
||||
*/
|
||||
QList<Diagram *> QETProject::diagrams() const {
|
||||
return(diagrams_);
|
||||
return(m_diagrams_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,7 +165,7 @@ QList<Diagram *> QETProject::diagrams() const {
|
||||
*/
|
||||
int QETProject::folioIndex(const Diagram *diagram) const {
|
||||
// QList::indexOf returns -1 if no item matched.
|
||||
return(diagrams_.indexOf(const_cast<Diagram *>(diagram)));
|
||||
return(m_diagrams_list.indexOf(const_cast<Diagram *>(diagram)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -601,7 +601,7 @@ NumerotationContext QETProject::folioAutoNum (const QString &key) const {
|
||||
*/
|
||||
void QETProject::freezeExistentConductorLabel(bool freeze, int from, int to) {
|
||||
for (int i = from; i <= to; i++) {
|
||||
diagrams_.at(i)->freezeConductors(freeze);
|
||||
m_diagrams_list.at(i)->freezeConductors(freeze);
|
||||
}
|
||||
}
|
||||
|
||||
@ -613,7 +613,7 @@ void QETProject::freezeExistentConductorLabel(bool freeze, int from, int to) {
|
||||
*/
|
||||
void QETProject::freezeNewConductorLabel(bool freeze, int from, int to) {
|
||||
for (int i = from; i <= to; i++) {
|
||||
diagrams_.at(i)->setFreezeNewConductors(freeze);
|
||||
m_diagrams_list.at(i)->setFreezeNewConductors(freeze);
|
||||
}
|
||||
}
|
||||
|
||||
@ -641,7 +641,7 @@ void QETProject::setFreezeNewConductors(bool set) {
|
||||
*/
|
||||
void QETProject::freezeExistentElementLabel(bool freeze, int from, int to) {
|
||||
for (int i = from; i <= to; i++) {
|
||||
diagrams_.at(i)->freezeElements(freeze);
|
||||
m_diagrams_list.at(i)->freezeElements(freeze);
|
||||
}
|
||||
}
|
||||
|
||||
@ -653,7 +653,7 @@ void QETProject::freezeExistentElementLabel(bool freeze, int from, int to) {
|
||||
*/
|
||||
void QETProject::freezeNewElementLabel(bool freeze, int from, int to) {
|
||||
for (int i = from; i <= to; i++) {
|
||||
diagrams_.at(i)->setFreezeNewElements(freeze);
|
||||
m_diagrams_list.at(i)->setFreezeNewElements(freeze);
|
||||
}
|
||||
}
|
||||
|
||||
@ -710,16 +710,16 @@ void QETProject::autoFolioNumberingNewFolios(){
|
||||
* rename folios with selected autonum
|
||||
*/
|
||||
void QETProject::autoFolioNumberingSelectedFolios(int from, int to, QString autonum){
|
||||
int total_folio = diagrams_.count();
|
||||
int total_folio = m_diagrams_list.count();
|
||||
DiagramContext project_wide_properties = project_properties_;
|
||||
for (int i=from; i<=to; i++) {
|
||||
QString title = diagrams_[i] -> title();
|
||||
QString title = m_diagrams_list[i] -> title();
|
||||
NumerotationContext nC = folioAutoNum(autonum);
|
||||
NumerotationContextCommands nCC = NumerotationContextCommands(nC);
|
||||
diagrams_[i] -> border_and_titleblock.setFolio("%autonum");
|
||||
diagrams_[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, nCC.toRepresentedString(), project_wide_properties);
|
||||
diagrams_[i] -> project() -> addFolioAutoNum(autonum,nCC.next());
|
||||
diagrams_[i] -> update();
|
||||
m_diagrams_list[i] -> border_and_titleblock.setFolio("%autonum");
|
||||
m_diagrams_list[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, nCC.toRepresentedString(), project_wide_properties);
|
||||
m_diagrams_list[i] -> project() -> addFolioAutoNum(autonum,nCC.next());
|
||||
m_diagrams_list[i] -> update();
|
||||
}
|
||||
}
|
||||
|
||||
@ -761,13 +761,18 @@ QDomDocument QETProject::toXml() {
|
||||
|
||||
// qDebug() << "Export XML de" << diagrams_.count() << "schemas";
|
||||
int order_num = 1;
|
||||
foreach(Diagram *diagram, diagrams_) {
|
||||
|
||||
const QList<Diagram *> diagrams_list = m_diagrams_list;
|
||||
for(Diagram *diagram : diagrams_list)
|
||||
{
|
||||
// Write the diagram to XML only if it is not of type DiagramFolioList.
|
||||
DiagramFolioList *ptr = dynamic_cast<DiagramFolioList *>(diagram);
|
||||
if ( !ptr ) {
|
||||
if ( !ptr )
|
||||
{
|
||||
qDebug() << qPrintable(QString("QETProject::toXml() : exporting diagram \"%1\"").arg(diagram -> title())) << "[" << diagram << "]";
|
||||
QDomNode appended_diagram = project_root.appendChild(diagram -> writeXml(xml_doc));
|
||||
QDomElement xml_diagram = diagram->toXml().documentElement();
|
||||
QDomNode xml_node = xml_doc.importNode(xml_diagram, true);
|
||||
|
||||
QDomNode appended_diagram = project_root.appendChild(xml_node);
|
||||
appended_diagram.toElement().setAttribute("order", order_num ++);
|
||||
}
|
||||
}
|
||||
@ -851,7 +856,7 @@ bool QETProject::isEmpty() const {
|
||||
|
||||
// compte le nombre de schemas non vides
|
||||
int pertinent_diagrams = 0;
|
||||
foreach(Diagram *diagram, diagrams_) {
|
||||
foreach(Diagram *diagram, m_diagrams_list) {
|
||||
if (!diagram -> isEmpty()) ++ pertinent_diagrams;
|
||||
}
|
||||
|
||||
@ -1034,14 +1039,6 @@ bool QETProject::usesTitleBlockTemplate(const TitleBlockTemplateLocation &locati
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
Gere la reecriture du projet
|
||||
*/
|
||||
void QETProject::componentWritten() {
|
||||
// reecrit tout le projet
|
||||
write();
|
||||
}
|
||||
|
||||
/**
|
||||
Ajoute un nouveau schema au projet et emet le signal diagramAdded
|
||||
*/
|
||||
@ -1110,9 +1107,9 @@ QList <Diagram *> QETProject::addNewDiagramFolioList() {
|
||||
void QETProject::removeDiagram(Diagram *diagram) {
|
||||
// ne fait rien si le projet est en lecture seule
|
||||
if (isReadOnly()) return;
|
||||
if (!diagram || !diagrams_.contains(diagram)) return;
|
||||
if (!diagram || !m_diagrams_list.contains(diagram)) return;
|
||||
|
||||
if (diagrams_.removeAll(diagram)) {
|
||||
if (m_diagrams_list.removeAll(diagram)) {
|
||||
emit(diagramRemoved(this, diagram));
|
||||
delete diagram;
|
||||
}
|
||||
@ -1131,10 +1128,10 @@ void QETProject::removeDiagram(Diagram *diagram) {
|
||||
void QETProject::diagramOrderChanged(int old_index, int new_index) {
|
||||
if (old_index < 0 || new_index < 0) return;
|
||||
|
||||
int diagram_max_index = diagrams_.size() - 1;
|
||||
int diagram_max_index = m_diagrams_list.size() - 1;
|
||||
if (old_index > diagram_max_index || new_index > diagram_max_index) return;
|
||||
|
||||
diagrams_.move(old_index, new_index);
|
||||
m_diagrams_list.move(old_index, new_index);
|
||||
updateDiagramsFolioData();
|
||||
setModified(true);
|
||||
emit(projectDiagramsOrderChanged(this, old_index, new_index));
|
||||
@ -1528,8 +1525,6 @@ void QETProject::addDiagram(Diagram *diagram) {
|
||||
// Ensure diagram know is parent project
|
||||
diagram -> setProject(this);
|
||||
|
||||
// If diagram is write, we must rewrite the project
|
||||
connect(diagram, SIGNAL(written()), this, SLOT(componentWritten()));
|
||||
connect(
|
||||
&(diagram -> border_and_titleblock),
|
||||
SIGNAL(needFolioData()),
|
||||
@ -1542,7 +1537,7 @@ void QETProject::addDiagram(Diagram *diagram) {
|
||||
);
|
||||
|
||||
// add diagram to project
|
||||
diagrams_ << diagram;
|
||||
m_diagrams_list << diagram;
|
||||
|
||||
updateDiagramsFolioData();
|
||||
}
|
||||
@ -1626,24 +1621,24 @@ bool QETProject::projectWasModified() {
|
||||
folio le projet contient.
|
||||
*/
|
||||
void QETProject::updateDiagramsFolioData() {
|
||||
int total_folio = diagrams_.count();
|
||||
int total_folio = m_diagrams_list.count();
|
||||
|
||||
DiagramContext project_wide_properties = project_properties_;
|
||||
project_wide_properties.addValue("projecttitle", title());
|
||||
|
||||
for (int i = 0 ; i < total_folio ; ++ i) {
|
||||
QString title = diagrams_[i] -> title();
|
||||
QString autopagenum = diagrams_[i]->border_and_titleblock.autoPageNum();
|
||||
QString title = m_diagrams_list[i] -> title();
|
||||
QString autopagenum = m_diagrams_list[i]->border_and_titleblock.autoPageNum();
|
||||
NumerotationContext nC = folioAutoNum(autopagenum);
|
||||
NumerotationContextCommands nCC = NumerotationContextCommands(nC);
|
||||
if((diagrams_[i]->border_and_titleblock.folio().contains("%autonum"))&&(!autopagenum.isNull())){
|
||||
diagrams_[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, nCC.toRepresentedString(), project_wide_properties);
|
||||
diagrams_[i]->project()->addFolioAutoNum(autopagenum,nCC.next());
|
||||
if((m_diagrams_list[i]->border_and_titleblock.folio().contains("%autonum"))&&(!autopagenum.isNull())){
|
||||
m_diagrams_list[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, nCC.toRepresentedString(), project_wide_properties);
|
||||
m_diagrams_list[i]->project()->addFolioAutoNum(autopagenum,nCC.next());
|
||||
}
|
||||
else{
|
||||
diagrams_[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, NULL, project_wide_properties);
|
||||
m_diagrams_list[i] -> border_and_titleblock.setFolioData(i + 1, total_folio, NULL, project_wide_properties);
|
||||
}
|
||||
diagrams_[i] -> update();
|
||||
m_diagrams_list[i] -> update();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1655,7 +1650,7 @@ void QETProject::updateDiagramsFolioData() {
|
||||
void QETProject::updateDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *collection, const QString &template_name) {
|
||||
Q_UNUSED(collection)
|
||||
|
||||
foreach (Diagram *diagram, diagrams_) {
|
||||
foreach (Diagram *diagram, m_diagrams_list) {
|
||||
diagram -> titleBlockTemplateChanged(template_name);
|
||||
}
|
||||
}
|
||||
@ -1669,7 +1664,7 @@ void QETProject::removeDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection
|
||||
Q_UNUSED(collection)
|
||||
|
||||
// warn diagrams that the given template is about to be removed
|
||||
foreach (Diagram *diagram, diagrams_) {
|
||||
foreach (Diagram *diagram, m_diagrams_list) {
|
||||
diagram -> titleBlockTemplateRemoved(template_name);
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,6 @@ class QETProject : public QObject
|
||||
QUndoStack* undoStack() {return undo_stack_;}
|
||||
|
||||
public slots:
|
||||
void componentWritten();
|
||||
Diagram *addNewDiagram();
|
||||
QList <Diagram *> addNewDiagramFolioList();
|
||||
void removeDiagram(Diagram *);
|
||||
@ -224,7 +223,7 @@ class QETProject : public QObject
|
||||
/// Current state of the project
|
||||
ProjectState state_;
|
||||
/// Diagrams carried by the project
|
||||
QList<Diagram *> diagrams_;
|
||||
QList<Diagram *> m_diagrams_list;
|
||||
/// Project title
|
||||
QString project_title_;
|
||||
/// QElectroTech version declared in the XML document at opening time
|
||||
|
Loading…
x
Reference in New Issue
Block a user