Folio List: XML save/open added. When Application starts, folio list is not added

so that user gets the option to choose whether he wants to add folio list or not.
Bug remaining:
- When open project file with folio_list present, folio list sheets are at the end,
  not at the beginning.
- Possibly many others. Thorough testing required.



git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2847 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
abhishekm71
2014-02-10 13:58:30 +00:00
parent c96036b7fa
commit 0888f6e347
6 changed files with 63 additions and 32 deletions

View File

@@ -19,7 +19,6 @@
#include <QPainter>
#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);
}
/**

View File

@@ -24,14 +24,13 @@
class DiagramFolioList : public Diagram
{
public:
DiagramFolioList(QObject *parent = 0);
DiagramFolioList( QETProject *project = 0, QObject *parent = 0);
virtual ~DiagramFolioList();
virtual QList<QLineF *> lines() const {return list_lines_;}
virtual QList<QRectF *> 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:

View File

@@ -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,10 +340,6 @@ 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<DiagramFolioList *>(diagram))
//diagrams_.insert(DiagramFolioList::folioList_quantity, diagram);
//else
diagrams_ << diagram;
rebuildDiagramsMap();
@@ -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<DiagramFolioList *>(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);
;
}
/**

View File

@@ -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<DiagramFolioList *>(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);
}
}
}

View File

@@ -46,7 +46,8 @@ 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);
@@ -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,10 +481,13 @@ QDomDocument QETProject::toXml() {
// qDebug() << "Export XML de" << diagrams_.count() << "schemas";
int order_num = 1;
foreach(Diagram *diagram, diagrams_) {
DiagramFolioList *ptr = dynamic_cast<DiagramFolioList *>(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
project_root.appendChild(collection_ -> writeXml(xml_doc));
@@ -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;
}

View File

@@ -74,6 +74,8 @@ class QETProject : public QObject {
public:
ProjectState state() const;
QList<Diagram *> 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<Diagram *> diagrams_;
/// Folio List Sheet is added to this project.
int folioSheetsQuantity;
/// Embedded elements collection
XmlElementsCollection *collection_;
/// Project title