[qet] [2836] List of Drawings: DXF export added and multple sheets for large project added. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2836
Author: abhishekm71
Date: 2014-02-08 19:17:10 +0100 (Sat, 08 Feb 2014)
Log Message:
-----------
List of Drawings: DXF export added and multple sheets for large project added.
Pending work:
- folio string to be formatted correctly.
- thorough testing to be done because lot of changes to addDiagram / removeDiagram had to be done
to add the feature of multiple folio list sheets
Modified Paths:
--------------
trunk/sources/diagramfoliolist.cpp
trunk/sources/diagramfoliolist.h
trunk/sources/exportdialog.cpp
trunk/sources/exportdialog.h
trunk/sources/projectview.cpp
trunk/sources/qetdiagrameditor.cpp
trunk/sources/qetproject.cpp
trunk/sources/qetproject.h
Modified: trunk/sources/diagramfoliolist.cpp
===================================================================
--- trunk/sources/diagramfoliolist.cpp 2014-02-08 16:37:45 UTC (rev 2835)
+++ trunk/sources/diagramfoliolist.cpp 2014-02-08 18:17:10 UTC (rev 2836)
@@ -18,7 +18,34 @@
#include "diagramfoliolist.h"
#include <QPainter>
+int DiagramFolioList::folioList_quantity = 0;
+qreal DiagramFolioList::colWidths[4] = {0.1, 0.55, 0.2, 0.15};
+DiagramFolioList::DiagramFolioList(QObject *parent) : Diagram(parent)
+{
+ list_lines_.clear();
+ list_rectangles_.clear();
+
+ id = folioList_quantity;
+ folioList_quantity++;
+
+ qreal width = border_and_titleblock.columnsTotalWidth();
+ qreal height = border_and_titleblock.rowsTotalHeight();
+
+ //top left corner of drawable area
+ qreal x0 = border_and_titleblock.rowsHeaderWidth();
+ qreal y0 = border_and_titleblock.columnsHeaderHeight();
+ QRectF row_RectF(x0, y0, width, height);
+
+ buildGrid(row_RectF,30,2,colWidths);
+}
+
+DiagramFolioList::~DiagramFolioList()
+{
+ if (folioList_quantity > 0)
+ folioList_quantity--;
+}
+
void DiagramFolioList::drawBackground(QPainter *p, const QRectF &r)
{
p -> save();
@@ -30,37 +57,51 @@
// dessine un fond blanc
p -> setPen(Qt::NoPen);
- //set brush color to present background color.
p -> setBrush(Diagram::background_color);
p -> drawRect(r);
-
p -> setPen(Qt::black);
- qreal width = border_and_titleblock.columnsTotalWidth();
- qreal height = border_and_titleblock.rowsTotalHeight();
- QList<Diagram *> diagram_list = project() -> diagrams();
-
- //top left corner of drawable area
- qreal x0 = border_and_titleblock.rowsHeaderWidth();
- qreal y0 = border_and_titleblock.columnsHeaderHeight();
- qreal drawings_quantity = diagram_list.size();
- qreal rowHeight = height / (drawings_quantity+1) * 0.8;
- rowHeight = (rowHeight > height*0.05) ? height*0.05 : rowHeight;
- QRectF row_RectF(x0 + width*.1, y0 + height*.05, width*0.8, rowHeight);
-
QString authorTranslatable = tr("Auteur");
QString titleTranslatable = tr("Titre");
QString folioTranslatable = tr("Folio");
QString dateTranslatable = tr("Date");
+ qreal x0 = list_rectangles_[0] -> topLeft().x();
+ qreal y0 = list_rectangles_[0] -> topLeft().y();
+ qreal rowHeight = (list_rectangles_[0] -> height())/30;
+ QRectF row_RectF(x0, y0, list_rectangles_[0] -> width(), rowHeight);
+
fillRow(p, row_RectF, authorTranslatable, titleTranslatable, folioTranslatable, dateTranslatable);
- foreach (Diagram *diagram, diagram_list) {
+ QList<Diagram *> diagram_list = project() -> diagrams();
+
+ int startDiagram = id * 58;
+
+ for (int i = startDiagram; i < startDiagram+29 && i < diagram_list.size(); ++i) {
y0 += rowHeight;
- QRectF row_rect(x0 + width*.1, y0 + height*.05, width*0.8, rowHeight);
- fillRow(p, row_rect, diagram -> border_and_titleblock.author(), diagram -> border_and_titleblock.title(),
- diagram -> border_and_titleblock.folio(), diagram -> border_and_titleblock.date().toString("dd/MM/yyyy"));
+ QRectF row_rect(x0, y0, list_rectangles_[0] -> width(), rowHeight);
+ fillRow(p, row_rect, diagram_list[i] -> border_and_titleblock.author(),
+ diagram_list[i] -> border_and_titleblock.title(),
+ diagram_list[i] -> border_and_titleblock.folio(),
+ diagram_list[i] -> border_and_titleblock.date().toString("dd/MM/yyyy"));
}
- p -> setPen(Qt::NoPen);
+
+ x0 = list_rectangles_[1] -> topLeft().x();
+ y0 = list_rectangles_[1] -> topLeft().y();
+ rowHeight = (list_rectangles_[1] -> height())/30;
+ QRectF row_RectF2(x0, y0, list_rectangles_[1] -> width(), rowHeight);
+ fillRow(p, row_RectF2, authorTranslatable, titleTranslatable, folioTranslatable, dateTranslatable);
+
+ startDiagram += 29;
+
+ for (int i = startDiagram; i < startDiagram+29 && i < diagram_list.size(); ++i) {
+ y0 += rowHeight;
+ QRectF row_rect(x0, y0, list_rectangles_[1] -> width(), rowHeight);
+ fillRow(p, row_rect, diagram_list[i] -> border_and_titleblock.author(),
+ diagram_list[i] -> border_and_titleblock.title(),
+ diagram_list[i] -> border_and_titleblock.folio(),
+ diagram_list[i] -> border_and_titleblock.date().toString("dd/MM/yyyy"));
+ }
+
border_and_titleblock.draw(p, margin, margin);
p -> restore();
}
@@ -68,16 +109,54 @@
void DiagramFolioList::fillRow(QPainter *qp, const QRectF &row_rect, QString author, QString title,
QString folio, QString date)
{
- qp -> drawRect(row_rect);
qreal x = row_rect.topLeft().x();
qreal y = row_rect.topLeft().y();
- qreal column_width = row_rect.width() / 4;
- qp -> drawText(QRectF(x, y, column_width, row_rect.height()), Qt::AlignCenter, folio);
- qp -> drawText(QRectF(x + column_width, y, column_width, row_rect.height()), Qt::AlignCenter, title);
- qp -> drawText(QRectF(x + 2*column_width, y, column_width, row_rect.height()), Qt::AlignCenter, author);
- qp -> drawText(QRectF(x + 3*column_width, y, column_width, row_rect.height()), Qt::AlignCenter, date);
+ qp -> drawText(QRectF(x, y, colWidths[0]*row_rect.width(), row_rect.height()), Qt::AlignCenter, folio);
+ x += colWidths[0]*row_rect.width();
- for (int i = 1; i <= 3; i++ )
- qp -> drawLine(x + i*column_width, y, x + i*column_width, y + row_rect.height());
+ qp -> drawText(QRectF(x, y, colWidths[1]*row_rect.width(), row_rect.height()), Qt::AlignCenter, title);
+ x += colWidths[1]*row_rect.width();
+
+ qp -> drawText(QRectF(x, y, colWidths[2]*row_rect.width(), row_rect.height()), Qt::AlignCenter, author);
+ x += colWidths[2]*row_rect.width();
+
+ qp -> drawText(QRectF(x, y, colWidths[3]*row_rect.width(), row_rect.height()), Qt::AlignCenter, date);
}
+
+void DiagramFolioList::buildGrid(const QRectF &rect, int rows, int tables, qreal colWidths[])
+{
+ qreal sum = 0;
+ for (int i = 0; i < 4; i++ )
+ sum += colWidths[i];
+ if ( sum < 0.99 || sum > 1.01 ) {
+ qDebug() << "Invalid input: Column widths do not sum to 1";
+ return;
+ }
+
+ qreal tablesSpacing = rect.height() * 0.02;
+ qreal tableWidth = (rect.width() - tablesSpacing*(tables+1) ) / tables;
+ qreal rowHeight = (rect.height() - 2*tablesSpacing) / rows;
+ int cols = 4;//colWidths.size();
+
+ qreal x0 = tablesSpacing + rect.topLeft().x();
+ qreal y0 = tablesSpacing + rect.topLeft().y();
+
+ for (int i = 0; i < tables; ++i) {
+ QRectF *tableRect = new QRectF(x0, y0, tableWidth, rect.height() - 2*tablesSpacing);
+ addRect(*tableRect);
+ list_rectangles_.push_back(tableRect);
+ for (int j = 1; j < rows; ++j) {
+ QLineF *line = new QLineF(x0, y0 + j*rowHeight, x0 + tableWidth,y0 + j*rowHeight);
+ addLine(*line);
+ list_lines_.push_back(line);
+ }
+ for (int j = 0; j < cols-1; ++j) {
+ QLineF *line = new QLineF(x0 + colWidths[j]*tableWidth, y0, x0 + colWidths[j]*tableWidth,y0 + rows*rowHeight);
+ addLine(*line);
+ list_lines_.push_back(line);
+ x0 += colWidths[j]*tableWidth;
+ }
+ x0 += colWidths[cols-1]*tableWidth + tablesSpacing;
+ }
+}
Modified: trunk/sources/diagramfoliolist.h
===================================================================
--- trunk/sources/diagramfoliolist.h 2014-02-08 16:37:45 UTC (rev 2835)
+++ trunk/sources/diagramfoliolist.h 2014-02-08 18:17:10 UTC (rev 2836)
@@ -19,19 +19,33 @@
#define DIAGRAMFOLIOLIST_H
#include "diagram.h"
+#include "qetgraphicsitem/independenttextitem.h"
class DiagramFolioList : public Diagram
{
public:
- DiagramFolioList(QObject *parent = 0) : Diagram(parent) {}
- virtual ~DiagramFolioList() {}
+ DiagramFolioList(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:
void drawBackground(QPainter *, const QRectF &);
private:
void fillRow(QPainter *, const QRectF &, QString, QString, QString, QString);
+ void buildGrid(const QRectF &, int, int, qreal[]);
+
+ QList<QLineF *> list_lines_;
+ QList<QRectF *> list_rectangles_;
+ int id;
+
};
#endif // DIAGRAMFOLIOLIST_H
Modified: trunk/sources/exportdialog.cpp
===================================================================
--- trunk/sources/exportdialog.cpp 2014-02-08 16:37:45 UTC (rev 2835)
+++ trunk/sources/exportdialog.cpp 2014-02-08 18:17:10 UTC (rev 2836)
@@ -33,6 +33,7 @@
#include "qetgraphicsitem/ghostelement.h"
#include "qetgraphicsitem/independenttextitem.h"
#include "qetgraphicsitem/diagramimageitem.h"
+#include "diagramfoliolist.h"
/**
Constructeur
@@ -390,20 +391,89 @@
QList<Conductor *> list_conductors;
QList<DiagramTextItem *> list_texts;
QList<DiagramImageItem *> list_images;
+ QList<QLineF *> list_lines;
+ QList<QRectF *> list_rectangles;
- // Determine les elements a "XMLiser"
- foreach(QGraphicsItem *qgi, diagram -> items()) {
- if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
- list_elements << elmt;
- } else if (Conductor *f = qgraphicsitem_cast<Conductor *>(qgi)) {
- list_conductors << f;
- } else if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(qgi)) {
- list_texts << iti;
- } else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
- list_images << dii;
+ DiagramFolioList *ptr;
+ if (ptr = dynamic_cast<DiagramFolioList *>(diagram)) {
+ list_lines = ptr -> lines();
+ list_rectangles = ptr -> rectangles();
+
+ // fill the rows with text.
+ QString authorTranslatable = tr("Auteur");
+ QString titleTranslatable = tr("Titre");
+ QString folioTranslatable = tr("Folio");
+ QString dateTranslatable = tr("Date");
+
+ qreal x0 = list_rectangles[0] -> topLeft().x();
+ qreal y0 = list_rectangles[0] -> topLeft().y();
+ qreal rowHeight = (list_rectangles[0] -> height())/30;
+ QRectF row_RectF(x0, y0, list_rectangles[0] -> width(), rowHeight);
+
+ fillRow(file_path, row_RectF, authorTranslatable, titleTranslatable, folioTranslatable, dateTranslatable);
+ QList<Diagram *> diagram_list = ptr -> project() -> diagrams();
+
+ int startDiagram = (ptr -> getId()) * 58;
+
+ for (int i = startDiagram; i < startDiagram+29 && i < diagram_list.size(); ++i) {
+ y0 += rowHeight;
+ QRectF row_rect(x0, y0, list_rectangles[0] -> width(), rowHeight);
+ fillRow(file_path, row_rect, diagram_list[i] -> border_and_titleblock.author(),
+ diagram_list[i] -> border_and_titleblock.title(),
+ diagram_list[i] -> border_and_titleblock.folio(),
+ diagram_list[i] -> border_and_titleblock.date().toString("dd/MM/yyyy"));
}
+
+ x0 = list_rectangles[1] -> topLeft().x();
+ y0 = list_rectangles[1] -> topLeft().y();
+ rowHeight = (list_rectangles[1] -> height())/30;
+ QRectF row_RectF2(x0, y0, list_rectangles[1] -> width(), rowHeight);
+ fillRow(file_path, row_RectF2, authorTranslatable, titleTranslatable, folioTranslatable, dateTranslatable);
+
+ startDiagram += 29;
+
+ for (int i = startDiagram; i < startDiagram+29 && i < diagram_list.size(); ++i) {
+ y0 += rowHeight;
+ QRectF row_rect(x0, y0, list_rectangles[1] -> width(), rowHeight);
+ fillRow(file_path, row_rect, diagram_list[i] -> border_and_titleblock.author(),
+ diagram_list[i] -> border_and_titleblock.title(),
+ diagram_list[i] -> border_and_titleblock.folio(),
+ diagram_list[i] -> border_and_titleblock.date().toString("dd/MM/yyyy"));
+ }
+
+ } else {
+ // Determine les elements a "XMLiser"
+ foreach(QGraphicsItem *qgi, diagram -> items()) {
+ if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
+ list_elements << elmt;
+ } else if (Conductor *f = qgraphicsitem_cast<Conductor *>(qgi)) {
+ list_conductors << f;
+ } else if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(qgi)) {
+ list_texts << iti;
+ } else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
+ list_images << dii;
+ }
+ }
}
+ //draw lines
+ foreach(QLineF *line, list_lines) {
+ qreal x1 = (line -> p1().x()) * Createdxf::xScale;
+ qreal y1 = Createdxf::sheetHeight - (line -> p1().y()) * Createdxf::yScale;
+ qreal x2 = (line -> p2().x()) * Createdxf::xScale;
+ qreal y2 = Createdxf::sheetHeight - (line -> p2().y()) * Createdxf::yScale;
+ Createdxf::drawLine(file_path, x1, y1, x2, y2, 0);
+ }
+
+ //draw rectangles
+ foreach(QRectF *rect, list_rectangles) {
+ qreal x1 = (rect -> bottomLeft().x()) * Createdxf::xScale;
+ qreal y1 = Createdxf::sheetHeight - (rect -> bottomLeft().y()) * Createdxf::yScale;
+ qreal w = rect -> width() * Createdxf::xScale;
+ qreal h = rect -> height() * Createdxf::yScale;
+ Createdxf::drawRectangle(file_path, x1, y1, w, h, 0);
+ }
+
//Draw elements
foreach(Element *elmt, list_elements) {
@@ -743,6 +813,33 @@
}
}
+void ExportDialog::fillRow(QString file_path, const QRectF &row_rect, QString author, QString title,
+ QString folio, QString date)
+{
+ qreal x = row_rect.bottomLeft().x();
+ qreal y = row_rect.bottomLeft().y();
+
+ x *= Createdxf::xScale;
+ y = Createdxf::sheetHeight - y * Createdxf::yScale;
+ qreal height = row_rect.height() * Createdxf::yScale *0.75;
+ y += height*0.2;
+
+ Createdxf::drawTextAligned(file_path, folio, x, y+height*0.1, height*0.8, 0, 0, 1, 0,
+ x + DiagramFolioList::colWidths[0]*row_rect.width()*Createdxf::xScale/2, 0);
+ x += DiagramFolioList::colWidths[0]*row_rect.width()*Createdxf::xScale;
+
+ Createdxf::drawTextAligned(file_path, title, x, y+height*0.1, height*0.8, 0, 0, 1, 0,
+ x + DiagramFolioList::colWidths[1]*row_rect.width()*Createdxf::xScale/2, 0);
+ x += DiagramFolioList::colWidths[1]*row_rect.width()*Createdxf::xScale;
+
+ Createdxf::drawTextAligned(file_path, author, x, y+height*0.1, height*0.8, 0, 0, 1, 0,
+ x + DiagramFolioList::colWidths[2]*row_rect.width()*Createdxf::xScale/2, 0);
+ x += DiagramFolioList::colWidths[2]*row_rect.width()*Createdxf::xScale;
+
+ Createdxf::drawTextAligned(file_path, date, x, y+height*0.1, height*0.8, 0, 0, 1, 0,
+ x + DiagramFolioList::colWidths[3]*row_rect.width()*Createdxf::xScale/2, 0);
+}
+
QPointF ExportDialog::rotation_transformed(qreal px, qreal py , qreal origin_x, qreal origin_y, qreal angle) {
angle *= -3.14159265 / 180;
Modified: trunk/sources/exportdialog.h
===================================================================
--- trunk/sources/exportdialog.h 2014-02-08 16:37:45 UTC (rev 2835)
+++ trunk/sources/exportdialog.h 2014-02-08 18:17:10 UTC (rev 2836)
@@ -85,6 +85,7 @@
void saveReloadDiagramParameters(Diagram *, bool = true);
void generateSvg(Diagram *, int, int, bool, QIODevice &);
void generateDxf(Diagram *, int, int, bool, QString &);
+ void fillRow(QString, const QRectF &, QString, QString, QString, QString);
QImage generateImage(Diagram *, int, int, bool);
void exportDiagram(ExportDiagramLine *);
qreal diagramRatio(Diagram *);
Modified: trunk/sources/projectview.cpp
===================================================================
--- trunk/sources/projectview.cpp 2014-02-08 16:37:45 UTC (rev 2835)
+++ trunk/sources/projectview.cpp 2014-02-08 18:17:10 UTC (rev 2836)
@@ -35,6 +35,7 @@
#include "qetmessagebox.h"
#include "qettabbar.h"
#include "qettemplateeditor.h"
+#include "diagramfoliolist.h"
/**
Constructeur
@@ -303,11 +304,14 @@
Diagram *new_diagram = project_ -> addNewDiagram();
DiagramView *new_diagram_view = new DiagramView(new_diagram);
addDiagram(new_diagram_view);
+
+ if (project_ -> diagrams().size() % 58 == 1 && DiagramFolioList::folioList_quantity != 0)
+ addNewDiagramFolioList();
showDiagram(new_diagram_view);
}
void ProjectView::addNewDiagramFolioList() {
- if (project_ -> isReadOnly() || project_ -> isFolioListAdded()) return;
+ if (project_ -> isReadOnly()) return;
Diagram *new_diagram = project_ -> addNewDiagramFolioList();
DiagramView *new_diagram_view = new DiagramView(new_diagram);
Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp 2014-02-08 16:37:45 UTC (rev 2835)
+++ trunk/sources/qetdiagrameditor.cpp 2014-02-08 18:17:10 UTC (rev 2836)
@@ -33,6 +33,7 @@
#include "qetresult.h"
#include "genericpanel.h"
#include "nomenclature.h"
+#include "diagramfoliolist.h"
#include "ui/dialogautonum.h"
@@ -1682,8 +1683,11 @@
}
void QETDiagramEditor::addDiagramFolioListToProject() {
- if (ProjectView *current_project = currentProject()) {
- current_project -> addNewDiagramFolioList();
+ ProjectView *current_project = currentProject();
+ if (current_project && DiagramFolioList::folioList_quantity == 0) {
+ int diagram_qty = current_project -> diagrams().size();
+ for (int i = 0; i <= diagram_qty/58; i++)
+ current_project -> addNewDiagramFolioList();
}
}
Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp 2014-02-08 16:37:45 UTC (rev 2835)
+++ trunk/sources/qetproject.cpp 2014-02-08 18:17:10 UTC (rev 2836)
@@ -46,8 +46,7 @@
project_qet_version_(-1),
modified_(false),
read_only_(false),
- titleblocks_(this),
- folio_list_added_(false)
+ titleblocks_(this)
{
// 0 a n schema(s) vide(s)
int diagrams_count = qMax(0, diagrams);
@@ -847,7 +846,6 @@
diagram_folio_list -> border_and_titleblock.setTitle(title);
addDiagram(diagram_folio_list);
- folio_list_added_ = true;
emit(diagramAdded(this, diagram_folio_list));
return(diagram_folio_list);
}
@@ -861,14 +859,31 @@
if (isReadOnly()) return;
if (!diagram || !diagrams_.contains(diagram)) return;
-
- if (diagrams_.removeAll(diagram)) {
- DiagramFolioList *ptr = dynamic_cast<DiagramFolioList *>(diagram);
- if (ptr)
- folio_list_added_ = false;
+ DiagramFolioList *ptr = dynamic_cast<DiagramFolioList *>(diagram);
+ if (ptr) {
+ foreach (Diagram *diag, diagrams_) {
+ ptr = dynamic_cast<DiagramFolioList *>(diag);
+ if (ptr) {
+ diagrams_.removeAll(ptr);
+ emit(diagramRemoved(this, ptr));
+ delete ptr;
+ }
+ }
+ } else if (diagrams_.removeAll(diagram)) {
emit(diagramRemoved(this, diagram));
delete diagram;
+ if (diagrams_.size() % 58 == 0) {
+ foreach (Diagram *diag, diagrams_) {
+ ptr = dynamic_cast<DiagramFolioList *>(diag);
+ if (ptr && ptr -> getId() == DiagramFolioList::folioList_quantity-1) {
+ diagrams_.removeAll(ptr);
+ emit(diagramRemoved(this, ptr));
+ delete ptr;
+ break;
+ }
+ }
+ }
}
updateDiagramsFolioData();
Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h 2014-02-08 16:37:45 UTC (rev 2835)
+++ trunk/sources/qetproject.h 2014-02-08 18:17:10 UTC (rev 2836)
@@ -121,7 +121,6 @@
DiagramContext projectProperties();
void setProjectProperties(const DiagramContext &);
QUndoStack* undoStack() {return undo_stack_;}
- bool isFolioListAdded() {return folio_list_added_;}
public slots:
void componentWritten();
@@ -186,8 +185,6 @@
bool modified_;
/// Whether the project is read only
bool read_only_;
- /// Whether folio_list has been added.
- bool folio_list_added_;
/// Filepath for which this project is considered read only
QString read_only_file_path_;
/// Name of the category used when automatically integrating elements within the embedded collection