mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Add tables to dxf export
This commit is contained in:
@@ -654,7 +654,7 @@ void Createdxf::drawRectangle (const QString &fileName, double x1, double y1, do
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Createdxf::drawRectangle
|
@brief Createdxf::drawRectangle
|
||||||
Conveniance function for draw rectangle
|
Convenience function for draw rectangle
|
||||||
@param filepath
|
@param filepath
|
||||||
@param rect
|
@param rect
|
||||||
@param colorcode
|
@param colorcode
|
||||||
@@ -669,6 +669,26 @@ void Createdxf::drawRectangle(const QString &filepath,
|
|||||||
colorcode);
|
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
|
@brief Createdxf::drawArc
|
||||||
draw arc in dx format
|
draw arc in dx format
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ class Createdxf
|
|||||||
const QRectF &rect,
|
const QRectF &rect,
|
||||||
const int &colorcode);
|
const int &colorcode);
|
||||||
|
|
||||||
|
static void drawPolygon(const QString &filepath,
|
||||||
|
const QPolygonF &poly,
|
||||||
|
const int &colorcode);
|
||||||
|
|
||||||
static void drawLine(const QString &filapath,
|
static void drawLine(const QString &filapath,
|
||||||
double,
|
double,
|
||||||
double,
|
double,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "qetgraphicsitem/independenttextitem.h"
|
#include "qetgraphicsitem/independenttextitem.h"
|
||||||
#include "qetgraphicsitem/diagramimageitem.h"
|
#include "qetgraphicsitem/diagramimageitem.h"
|
||||||
#include "qetgraphicsitem/qetshapeitem.h"
|
#include "qetgraphicsitem/qetshapeitem.h"
|
||||||
|
#include "qetgraphicsitem/ViewItem/qetgraphicstableitem.h"
|
||||||
#include "elementpicturefactory.h"
|
#include "elementpicturefactory.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "dynamicelementtextitem.h"
|
#include "dynamicelementtextitem.h"
|
||||||
@@ -441,9 +442,12 @@ void ExportDialog::generateDxf(Diagram *diagram,
|
|||||||
QList<QRectF *> list_rectangles;
|
QList<QRectF *> list_rectangles;
|
||||||
//QList<QRectF *> list_ellipses;
|
//QList<QRectF *> list_ellipses;
|
||||||
QList <QetShapeItem *> list_shapes;
|
QList <QetShapeItem *> list_shapes;
|
||||||
|
QList <QetGraphicsTableItem *> list_tables;
|
||||||
|
|
||||||
// Determine les elements a "XMLiser"
|
// Determine les elements a "XMLiser"
|
||||||
|
int itm = 0;
|
||||||
foreach(QGraphicsItem *qgi, diagram -> items()) {
|
foreach(QGraphicsItem *qgi, diagram -> items()) {
|
||||||
|
qDebug() << "Item " << itm++ << qgi->type();
|
||||||
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
|
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
|
||||||
list_elements << elmt;
|
list_elements << elmt;
|
||||||
} else if (Conductor *f = qgraphicsitem_cast<Conductor *>(qgi)) {
|
} else if (Conductor *f = qgraphicsitem_cast<Conductor *>(qgi)) {
|
||||||
@@ -456,11 +460,18 @@ void ExportDialog::generateDxf(Diagram *diagram,
|
|||||||
list_shapes << dii;
|
list_shapes << dii;
|
||||||
} else if (DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(qgi)) {
|
} else if (DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(qgi)) {
|
||||||
list_texts << deti;
|
list_texts << deti;
|
||||||
|
} else if (QetGraphicsTableItem *gti = qgraphicsitem_cast<QetGraphicsTableItem *>(qgi)) {
|
||||||
|
list_tables << gti;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (QetShapeItem *qsi, list_shapes) qsi->toDXF(file_path, qsi->pen());
|
foreach (QetShapeItem *qsi, list_shapes) qsi->toDXF(file_path, qsi->pen());
|
||||||
|
|
||||||
|
// Draw tables
|
||||||
|
foreach (QetGraphicsTableItem *gti, list_tables) {
|
||||||
|
gti->toDXF(file_path);
|
||||||
|
}
|
||||||
|
|
||||||
//Draw elements
|
//Draw elements
|
||||||
foreach(Element *elmt, list_elements)
|
foreach(Element *elmt, list_elements)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "qabstractitemmodel.h"
|
#include "qabstractitemmodel.h"
|
||||||
#include "qetxml.h"
|
#include "qetxml.h"
|
||||||
#include "qetutils.h"
|
#include "qetutils.h"
|
||||||
|
#include "createdxf.h"
|
||||||
|
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@@ -139,6 +140,49 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
|||||||
|
|
||||||
painter->restore();
|
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 ; i<m_model->columnCount() ; ++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
|
@brief QetGraphicsHeaderItem::rect
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
|||||||
QDomElement toXml (QDomDocument &document) const;
|
QDomElement toXml (QDomDocument &document) const;
|
||||||
void fromXml(const QDomElement &element);
|
void fromXml(const QDomElement &element);
|
||||||
static QString xmlTagName() {return QString("graphics_header");}
|
static QString xmlTagName() {return QString("graphics_header");}
|
||||||
|
virtual bool toDXF (const QString &filepath);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sectionResized(int logicalIndex, int size);
|
void sectionResized(int logicalIndex, int size);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "elementprovider.h"
|
#include "elementprovider.h"
|
||||||
#include "qetutils.h"
|
#include "qetutils.h"
|
||||||
#include "projectdbmodel.h"
|
#include "projectdbmodel.h"
|
||||||
|
#include "createdxf.h"
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
@@ -579,6 +580,81 @@ void QetGraphicsTableItem::fromXml(const QDomElement &dom_element)
|
|||||||
m_header_item->fromXml(dom_element.firstChildElement(QetGraphicsHeaderItem::xmlTagName()));
|
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 ; i<m_model->columnCount() ; ++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<double>(m_current_size.height())/static_cast<double>(row_count);
|
||||||
|
for(auto i= 1 ; i-1<row_count ; ++i)
|
||||||
|
{
|
||||||
|
QPointF p1(m_header_item->rect().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 ; i<row_count ; ++i)
|
||||||
|
{
|
||||||
|
auto margin_ = QETUtils::marginsFromString(m_model->index(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 ; j<m_model->columnCount() ; ++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<int>(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
|
@brief QetGraphicsTableItem::hoverEnterEvent
|
||||||
Reimplemented from QetGraphicsItem
|
Reimplemented from QetGraphicsItem
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
|||||||
QDomElement toXml(QDomDocument &dom_document) const;
|
QDomElement toXml(QDomDocument &dom_document) const;
|
||||||
void fromXml(const QDomElement &dom_element);
|
void fromXml(const QDomElement &dom_element);
|
||||||
static QString xmlTagName() {return QString("graphics_table");}
|
static QString xmlTagName() {return QString("graphics_table");}
|
||||||
|
virtual bool toDXF (const QString &filepath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user