diff --git a/sources/diagramfoliolist.cpp b/sources/diagramfoliolist.cpp index 812cffb07..3b24d0c8e 100644 --- a/sources/diagramfoliolist.cpp +++ b/sources/diagramfoliolist.cpp @@ -19,7 +19,6 @@ #include #include "qetapp.h" -int DiagramFolioList::folioList_quantity = 0; qreal DiagramFolioList::colWidths[4] = {0.1, 0.55, 0.2, 0.15}; /** @@ -27,11 +26,13 @@ qreal DiagramFolioList::colWidths[4] = {0.1, 0.55, 0.2, 0.15}; * Constructor * @param parent parent QObject */ -DiagramFolioList::DiagramFolioList(QObject *parent) : Diagram(parent) { - - id = folioList_quantity; - folioList_quantity++; - +DiagramFolioList::DiagramFolioList( QETProject *project, QObject *parent) : Diagram(parent) { + if (project) { + setProject(project); + id = project -> getFolioSheetsQuantity(); + } + else + id = 0; } /** @@ -40,8 +41,9 @@ DiagramFolioList::DiagramFolioList(QObject *parent) : Diagram(parent) { */ DiagramFolioList::~DiagramFolioList() { - if (folioList_quantity > 0) - folioList_quantity--; + int folioSheetQty = project() -> getFolioSheetsQuantity(); + if (folioSheetQty > 0) + project() -> setFolioSheetsQuantity(folioSheetQty-1); } /** diff --git a/sources/diagramfoliolist.h b/sources/diagramfoliolist.h index 5b98c3885..f6602f85c 100644 --- a/sources/diagramfoliolist.h +++ b/sources/diagramfoliolist.h @@ -24,14 +24,13 @@ class DiagramFolioList : public Diagram { public: - DiagramFolioList(QObject *parent = 0); + DiagramFolioList( QETProject *project = 0, QObject *parent = 0); virtual ~DiagramFolioList(); virtual QList lines() const {return list_lines_;} virtual QList rectangles() const {return list_rectangles_;} void setId(int i) {id = i;} int getId() const {return id;} - static int folioList_quantity; static qreal colWidths[4]; protected: diff --git a/sources/projectview.cpp b/sources/projectview.cpp index f4f35e274..54e6b03e0 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -305,7 +305,7 @@ void ProjectView::addNewDiagram() { DiagramView *new_diagram_view = new DiagramView(new_diagram); addDiagram(new_diagram_view); - if (project_ -> diagrams().size() % 58 == 1 && DiagramFolioList::folioList_quantity != 0) + if (project_ -> diagrams().size() % 58 == 1 && project_ -> getFolioSheetsQuantity() != 0) addNewDiagramFolioList(); showDiagram(new_diagram_view); } @@ -340,11 +340,7 @@ void ProjectView::addDiagram(DiagramView *diagram, bool front) { tabs_ -> addTab(diagram, QET::Icons::Diagram, diagram -> title()); diagram -> setFrameStyle(QFrame::Plain | QFrame::NoFrame); - // Add diagram type is a folio list then add it just after the last folio list in project, else add it at the back. - //if (DiagramFolioList *ptr = dynamic_cast(diagram)) - //diagrams_.insert(DiagramFolioList::folioList_quantity, diagram); - //else - diagrams_ << diagram; + diagrams_ << diagram; rebuildDiagramsMap(); connect(diagram, SIGNAL(showDiagram(Diagram*)), this, SLOT(showDiagram(Diagram*))); @@ -356,11 +352,9 @@ void ProjectView::addDiagram(DiagramView *diagram, bool front) { // signal diagram was added emit(diagramAdded(diagram)); // move tab to front if wanted - if (front) { //DiagramFolioList *ptr = dynamic_cast(diagram ->diagram())) { - //int tabCount = tabs_ -> count(); - //for (int i = 0; i < (tabCount-1) - (DiagramFolioList::folioList_quantity-1); i++) - //moveDiagramUp(diagram); - tabs_->moveTab(tabs_->count()-1, DiagramFolioList::folioList_quantity-1); + if (front) { + tabs_->moveTab(tabs_->count()-1, project_ -> getFolioSheetsQuantity()-1); + //diagram -> diagram() -> project() -> setFolioSheetsQuantity(true); } } @@ -431,7 +425,6 @@ void ProjectView::removeDiagram(Diagram *diagram) { void ProjectView::showDiagram(DiagramView *diagram) { if (!diagram) return; tabs_ -> setCurrentWidget(diagram); - ; } /** diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 7578e8d7e..01acd8698 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1681,7 +1681,7 @@ void QETDiagramEditor::addDiagramToProject() { void QETDiagramEditor::addDiagramFolioListToProject() { ProjectView *current_project = currentProject(); - if (current_project && DiagramFolioList::folioList_quantity == 0) { + if (current_project && current_project -> project() -> getFolioSheetsQuantity() == 0) { int diagram_qty = current_project -> diagrams().size(); for (int i = 0; i <= diagram_qty/58; i++) current_project -> addNewDiagramFolioList(); @@ -1814,11 +1814,14 @@ void QETDiagramEditor::removeDiagramFromProject() { current_project -> removeDiagram(diag); } } + //current_project ->project() ->setFolioSheetsQuantity(0); } else if (current_project -> diagrams().size() % 58 == 0) { foreach (DiagramView *diag, current_project -> diagrams()) { DiagramFolioList *ptr = dynamic_cast(diag -> diagram()); - if (ptr && ptr -> getId() == DiagramFolioList::folioList_quantity-1) { + if (ptr && ptr -> getId() == current_project -> project() -> getFolioSheetsQuantity() - 1) { current_project -> removeDiagram(diag); + //int folioQuantity = current_project -> project() -> getFolioSheetsQuantity(); + //current_project -> project() -> setFolioSheetsQuantity(folioQuantity - 1); } } } diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index ca3409ef4..7814ba592 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -46,14 +46,15 @@ QETProject::QETProject(int diagrams, QObject *parent) : project_qet_version_(-1), modified_(false), read_only_(false), - titleblocks_(this) + titleblocks_(this), + folioSheetsQuantity(0) { // 0 a n schema(s) vide(s) int diagrams_count = qMax(0, diagrams); for (int i = 0 ; i < diagrams_count ; ++ i) { addNewDiagram(); } - + // une collection d'elements vide collection_ = new XmlElementsCollection(); collection_ -> setProtocol("embed"); @@ -79,7 +80,8 @@ QETProject::QETProject(const QString &path, QObject *parent) : project_qet_version_(-1), modified_(false), read_only_(false), - titleblocks_(this) + titleblocks_(this), + folioSheetsQuantity(0) { // ouvre le fichier QFile project_file(path); @@ -121,7 +123,8 @@ QETProject::QETProject(const QDomElement &xml_element, QObject *parent) : project_qet_version_(-1), modified_(false), read_only_(false), - titleblocks_(this) + titleblocks_(this), + folioSheetsQuantity(0) { // copie le contenu XML document_root_.appendChild(document_root_.importNode(xml_element, true)); @@ -154,6 +157,8 @@ QETProject::~QETProject() { diagrams_.removeAll(diagram); delete diagram; } + + folioSheetsQuantity = 0; // qDebug() << diagrams_; delete undo_stack_; } @@ -167,6 +172,14 @@ QETProject::ProjectState QETProject::state() const { return(state_); } +int QETProject::getFolioSheetsQuantity() const { + return(folioSheetsQuantity); +} + +void QETProject::setFolioSheetsQuantity(int quantity) { + folioSheetsQuantity = quantity; +} + /** @return la liste des schemas de ce projet */ @@ -440,6 +453,7 @@ QDomDocument QETProject::toXml() { QDomElement project_root = xml_doc.createElement("project"); project_root.setAttribute("version", QET::version); project_root.setAttribute("title", project_title_); + project_root.setAttribute("folioSheetQuantity", QString::number(folioSheetsQuantity)); xml_doc.appendChild(project_root); // titleblock templates, if any @@ -467,9 +481,12 @@ QDomDocument QETProject::toXml() { // qDebug() << "Export XML de" << diagrams_.count() << "schemas"; int order_num = 1; foreach(Diagram *diagram, diagrams_) { - qDebug() << qPrintable(QString("QETProject::toXml() : exporting diagram \"%1\" [%2]").arg(diagram -> title()).arg(QET::pointerString(diagram))); - QDomNode appended_diagram = project_root.appendChild(diagram -> writeXml(xml_doc)); - appended_diagram.toElement().setAttribute("order", order_num ++); + DiagramFolioList *ptr = dynamic_cast(diagram); + if ( !ptr ) { + qDebug() << qPrintable(QString("QETProject::toXml() : exporting diagram \"%1\" [%2]").arg(diagram -> title()).arg(QET::pointerString(diagram))); + QDomNode appended_diagram = project_root.appendChild(diagram -> writeXml(xml_doc)); + appended_diagram.toElement().setAttribute("order", order_num ++); + } } // collection @@ -841,7 +858,7 @@ Diagram *QETProject::addNewDiagramFolioList() { if (isReadOnly()) return(0); //create new diagram - Diagram *diagram_folio_list = new DiagramFolioList(); + Diagram *diagram_folio_list = new DiagramFolioList(this); // setup default properties diagram_folio_list -> border_and_titleblock.importBorder(defaultBorderProperties()); @@ -853,7 +870,9 @@ Diagram *QETProject::addNewDiagramFolioList() { diagram_folio_list -> border_and_titleblock.displayRows(false); diagram_folio_list -> border_and_titleblock.displayColumns(false); + addDiagram(diagram_folio_list); + setFolioSheetsQuantity( getFolioSheetsQuantity()+1 ); emit(diagramAdded(this, diagram_folio_list)); return(diagram_folio_list); @@ -946,6 +965,10 @@ void QETProject::readProjectXml() { // la racine du document XML est sensee etre un element "project" if (root_elmt.tagName() == "project") { + + if (root_elmt.hasAttribute("folioSheetQuantity")) + setFolioSheetsQuantity(root_elmt.attribute("folioSheetQuantity","0").toInt()); + // mode d'ouverture normal if (root_elmt.hasAttribute("version")) { bool conv_ok; @@ -1042,6 +1065,13 @@ void QETProject::readDiagramsXml() { d->initElementsLinks(); } + if (getFolioSheetsQuantity()) { + setFolioSheetsQuantity(0); + int diagCount = diagrams().size(); + for (int i = 0; i <= diagCount/58; i++) + addNewDiagramFolioList(); + } + //delete dialog object delete dlgWaiting; } diff --git a/sources/qetproject.h b/sources/qetproject.h index 8be3ae23a..9256d3a7e 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -74,6 +74,8 @@ class QETProject : public QObject { public: ProjectState state() const; QList diagrams() const; + int getFolioSheetsQuantity() const; + void setFolioSheetsQuantity(int); int folioIndex(const Diagram *) const; ElementsCollection *embeddedCollection() const; TitleBlockTemplatesProjectCollection *embeddedTitleBlockTemplatesCollection(); @@ -175,6 +177,8 @@ class QETProject : public QObject { QDomDocument document_root_; /// Diagrams carried by the project QList diagrams_; + /// Folio List Sheet is added to this project. + int folioSheetsQuantity; /// Embedded elements collection XmlElementsCollection *collection_; /// Project title