diff --git a/sources/createdxf.cpp b/sources/createdxf.cpp index 8f5ea7523..bb5b090a2 100644 --- a/sources/createdxf.cpp +++ b/sources/createdxf.cpp @@ -654,7 +654,7 @@ void Createdxf::drawRectangle (const QString &fileName, double x1, double y1, do /** @brief Createdxf::drawRectangle - Conveniance function for draw rectangle + Convenience function for draw rectangle @param filepath @param rect @param colorcode @@ -669,6 +669,26 @@ void Createdxf::drawRectangle(const QString &filepath, colorcode); } +/** + @brief Createdxf::drawPolygon + Convenience function for draw polygon + @param filepath + @param poly + @param colorcode +*/ +void Createdxf::drawPolygon(const QString &filepath, + const QPolygonF &poly, + const int &colorcode) { + int lc = 0; + QPointF plast; + foreach(QPointF p, poly) { + if(lc++) { + QLineF ql(plast,p); + drawLine(filepath,ql,colorcode); + } + plast = p; + } +} /** @brief Createdxf::drawArc draw arc in dx format diff --git a/sources/createdxf.h b/sources/createdxf.h index 29554733a..5a2fc1afe 100644 --- a/sources/createdxf.h +++ b/sources/createdxf.h @@ -71,6 +71,10 @@ class Createdxf const QRectF &rect, const int &colorcode); + static void drawPolygon(const QString &filepath, + const QPolygonF &poly, + const int &colorcode); + static void drawLine(const QString &filapath, double, double, diff --git a/sources/exportdialog.cpp b/sources/exportdialog.cpp index d38a5ddbd..58787f62a 100644 --- a/sources/exportdialog.cpp +++ b/sources/exportdialog.cpp @@ -31,6 +31,7 @@ #include "qetgraphicsitem/independenttextitem.h" #include "qetgraphicsitem/diagramimageitem.h" #include "qetgraphicsitem/qetshapeitem.h" +#include "qetgraphicsitem/ViewItem/qetgraphicstableitem.h" #include "elementpicturefactory.h" #include "element.h" #include "dynamicelementtextitem.h" @@ -441,9 +442,12 @@ void ExportDialog::generateDxf(Diagram *diagram, QList list_rectangles; //QList list_ellipses; QList list_shapes; + QList list_tables; // Determine les elements a "XMLiser" + int itm = 0; foreach(QGraphicsItem *qgi, diagram -> items()) { + qDebug() << "Item " << itm++ << qgi->type(); if (Element *elmt = qgraphicsitem_cast(qgi)) { list_elements << elmt; } else if (Conductor *f = qgraphicsitem_cast(qgi)) { @@ -456,11 +460,18 @@ void ExportDialog::generateDxf(Diagram *diagram, list_shapes << dii; } else if (DynamicElementTextItem *deti = qgraphicsitem_cast(qgi)) { list_texts << deti; - } + } else if (QetGraphicsTableItem *gti = qgraphicsitem_cast(qgi)) { + list_tables << gti; + } } foreach (QetShapeItem *qsi, list_shapes) qsi->toDXF(file_path, qsi->pen()); + // Draw tables + foreach (QetGraphicsTableItem *gti, list_tables) { + gti->toDXF(file_path); + } + //Draw elements foreach(Element *elmt, list_elements) { diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 1860838e9..3d88e9541 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1543,7 +1543,7 @@ void QETDiagramEditor::slot_updateComplexActions() for(DiagramTextItem *dti : texts) { if(dti->type() == ConductorTextItem::Type) - selected_conductor_texts++; + selected_conductor_texts++; } int selected_dynamic_elmt_text = 0; for(DiagramTextItem *dti : texts) diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp index d4ffa3074..bc9d633b8 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp @@ -19,6 +19,7 @@ #include "qabstractitemmodel.h" #include "qetxml.h" #include "qetutils.h" +#include "createdxf.h" #include #include @@ -139,6 +140,49 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI painter->restore(); } +/** + @brief QetGraphicsHeaderItem::toDXF + Draw this table to the dxf document + @param filepath file path of the the dxf document + @return true if draw success +*/ +bool QetGraphicsHeaderItem::toDXF(const QString &filepath) +{ + QRectF rect = m_current_rect; + QPolygonF poly(rect); + Createdxf::drawPolygon(filepath,mapToScene(poly),0); + + //Draw vertical lines + auto offset= 0; + for(auto size : m_current_sections_width) + { + QPointF p1(offset+size, m_current_rect.top()); + QPointF p2(offset+size, m_current_rect.bottom()); + Createdxf::drawLine(filepath,QLineF(mapToScene(p1),mapToScene(p2)),0); + offset += size; + } + + //Write text of each cell + auto margins_ = QETUtils::marginsFromString(m_model->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString()); + QPointF top_left(margins_.left(), margins_.top()); + for (auto i= 0 ; icolumnCount() ; ++i) + { + QSize size(m_current_sections_width.at(i) - margins_.left() - margins_.right(), m_section_height - margins_.top() - margins_.bottom()); + + QPointF qm = mapToScene(top_left); + qreal h = size.height();// * Createdxf::yScale; + qreal x = qm.x() * Createdxf::xScale; + qreal y = Createdxf::sheetHeight - ((qm.y() + h/2) * Createdxf::yScale); + qreal h1 = h * 0.5 * Createdxf::yScale; + + int valign = 2; + + Createdxf::drawTextAligned(filepath,m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(),x,y,h1,0,0,0,valign,x,0,0); + + top_left.setX(top_left.x() + m_current_sections_width.at(i)); + } + return true; +} /** @brief QetGraphicsHeaderItem::rect diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h index 2391c6b92..2ad97f219 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h @@ -61,6 +61,7 @@ class QetGraphicsHeaderItem : public QGraphicsObject QDomElement toXml (QDomDocument &document) const; void fromXml(const QDomElement &element); static QString xmlTagName() {return QString("graphics_header");} + virtual bool toDXF (const QString &filepath); signals: void sectionResized(int logicalIndex, int size); diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp index fec02a9ff..faa8feddd 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp @@ -23,6 +23,7 @@ #include "elementprovider.h" #include "qetutils.h" #include "projectdbmodel.h" +#include "createdxf.h" #include #include @@ -579,6 +580,81 @@ void QetGraphicsTableItem::fromXml(const QDomElement &dom_element) m_header_item->fromXml(dom_element.firstChildElement(QetGraphicsHeaderItem::xmlTagName())); } +/** + @brief QetGraphicsTableItem::toDXF + Draw this table to the dxf document + @param filepath file path of the the dxf document + @return true if draw success +*/ +bool QetGraphicsTableItem::toDXF(const QString &filepath) +{ + // Header + m_header_item->toDXF(filepath); + + //QRectF rect = boundingRect(); + QRectF rect(0,0, m_header_item->rect().width(), m_current_size.height()); + QPolygonF poly(rect); + Createdxf::drawPolygon(filepath,mapToScene(poly),0); + + //Draw vertical lines + auto offset= 0; + for(auto i=0 ; icolumnCount() ; ++i) + { + QPointF p1(offset+m_header_item->sectionSize(i), 0); + QPointF p2(offset+m_header_item->sectionSize(i), m_current_size.height()); + Createdxf::drawLine(filepath,QLineF(mapToScene(p1),mapToScene(p2)),0); +// painter->drawLine(p1, p2); + offset += m_header_item->sectionSize(i); + } + //Calculate the number of rows to display. + auto row_count = m_model->rowCount(); + + if (m_previous_table) //Remove the number of row already displayed by previous tables + row_count -= m_previous_table->displayNRowOffset(); + + if (m_number_of_displayed_row > 0) //User override the number of row to display + row_count = std::min(row_count, m_number_of_displayed_row); + + //Draw horizontal lines + auto cell_height = static_cast(m_current_size.height())/static_cast(row_count); + for(auto i= 1 ; i-1rect().left(), cell_height*i); + QPointF p2(m_header_item->rect().right(), cell_height*i); + Createdxf::drawLine(filepath,QLineF(mapToScene(p1),mapToScene(p2)),0); + //painter->drawLine(p1, p2); + } + + //Write text of each cell + for (auto i=0 ; iindex(0,0).data(Qt::UserRole+1).toString()); + QPointF top_left(margin_.left(), i==0? margin_.top() : cell_height*i + margin_.top()); + + for(auto j= 0 ; jcolumnCount() ; ++j) + { + //In first iteration the top left X is margin left, in all other iteration the top left X is stored in m_column_size + if (j>0) { + top_left.setX(top_left.x() + m_header_item->sectionSize(j-1)); + } + QSize size(m_header_item->sectionSize(j) - margin_.left() - margin_.right(), + static_cast(cell_height) - margin_.top() - margin_.bottom()); + auto index_row = m_previous_table ? i + m_previous_table->displayNRowOffset() : i; + + QPointF qm = mapToScene(top_left); + qreal h = size.height();// * Createdxf::yScale; + qreal x = qm.x() * Createdxf::xScale; + qreal y = Createdxf::sheetHeight - ((qm.y() + h/2) * Createdxf::yScale); + qreal h1 = h * 0.5 * Createdxf::yScale; + + int valign = 2; + + Createdxf::drawTextAligned(filepath,m_model->index(index_row, j).data().toString(),x,y,h1,0,0,0,valign,x,0,0); + } + } + return true; +} + /** @brief QetGraphicsTableItem::hoverEnterEvent Reimplemented from QetGraphicsItem diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h index 753e36f1a..0ffeca847 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h @@ -83,6 +83,7 @@ class QetGraphicsTableItem : public QetGraphicsItem QDomElement toXml(QDomDocument &dom_document) const; void fromXml(const QDomElement &dom_element); static QString xmlTagName() {return QString("graphics_table");} + virtual bool toDXF (const QString &filepath); protected: virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;