mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Fix Coding convention
Please download and use https://qelectrotech.org/wiki_new/_media/doc/qtcreator-qet-style.xml when you write code in Qt
This commit is contained in:
parent
babf3d2cf2
commit
8ee38fab9e
@ -43,7 +43,10 @@
|
||||
@param project Le projet a exporter
|
||||
@param parent Le Widget parent de ce dialogue
|
||||
*/
|
||||
ExportDialog::ExportDialog(QETProject *project, QWidget *parent) : QDialog(parent) {
|
||||
ExportDialog::ExportDialog(
|
||||
QETProject *project,
|
||||
QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
if (!project) return;
|
||||
|
||||
// recupere le projet a exporter
|
||||
@ -105,13 +108,15 @@ ExportDialog::ExportDialog(QETProject *project, QWidget *parent) : QDialog(paren
|
||||
/**
|
||||
Destructeur - ne fait rien
|
||||
*/
|
||||
ExportDialog::~ExportDialog() {
|
||||
ExportDialog::~ExportDialog()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@return le nombre de schemas coches (donc a exporter)
|
||||
*/
|
||||
int ExportDialog::diagramsToExportCount() const {
|
||||
int ExportDialog::diagramsToExportCount() const
|
||||
{
|
||||
int checked_diagrams_count = 0;
|
||||
foreach(ExportDiagramLine *diagram_line, diagram_lines_.values()) {
|
||||
if (diagram_line -> must_export -> isChecked()) ++ checked_diagrams_count;
|
||||
@ -123,7 +128,8 @@ int ExportDialog::diagramsToExportCount() const {
|
||||
Met en place la liste des schemas
|
||||
@return Le widget representant la liste des schemas
|
||||
*/
|
||||
QWidget *ExportDialog::initDiagramsListPart() {
|
||||
QWidget *ExportDialog::initDiagramsListPart()
|
||||
{
|
||||
preview_mapper_ = new QSignalMapper(this);
|
||||
width_mapper_ = new QSignalMapper(this);
|
||||
height_mapper_ = new QSignalMapper(this);
|
||||
@ -186,13 +192,15 @@ QWidget *ExportDialog::initDiagramsListPart() {
|
||||
return(scroll_diagrams_list);
|
||||
}
|
||||
|
||||
void ExportDialog::slot_selectAllClicked() {
|
||||
void ExportDialog::slot_selectAllClicked()
|
||||
{
|
||||
foreach (ExportDiagramLine *diagramLine, diagram_lines_) {
|
||||
diagramLine -> must_export -> setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ExportDialog::slot_deSelectAllClicked() {
|
||||
void ExportDialog::slot_deSelectAllClicked()
|
||||
{
|
||||
foreach (ExportDiagramLine *diagramLine, diagram_lines_) {
|
||||
diagramLine -> must_export -> setChecked(false);
|
||||
}
|
||||
@ -204,7 +212,8 @@ void ExportDialog::slot_deSelectAllClicked() {
|
||||
@param diagram Un schema
|
||||
@return le rapport largeur / hauteur du schema
|
||||
*/
|
||||
qreal ExportDialog::diagramRatio(Diagram *diagram) {
|
||||
qreal ExportDialog::diagramRatio(Diagram *diagram)
|
||||
{
|
||||
QSize diagram_size = diagramSize(diagram);
|
||||
qreal diagram_ratio = (qreal)diagram_size.width() / (qreal)diagram_size.height();
|
||||
return(diagram_ratio);
|
||||
@ -215,7 +224,8 @@ qreal ExportDialog::diagramRatio(Diagram *diagram) {
|
||||
@return les dimensions du schema, en tenant compte du type d'export : cadre
|
||||
ou elements
|
||||
*/
|
||||
QSize ExportDialog::diagramSize(Diagram *diagram) {
|
||||
QSize ExportDialog::diagramSize(Diagram *diagram)
|
||||
{
|
||||
// sauvegarde le parametre useBorder du schema
|
||||
bool state_useBorder = diagram -> useBorder();
|
||||
|
||||
@ -235,7 +245,8 @@ QSize ExportDialog::diagramSize(Diagram *diagram) {
|
||||
activee pour ce schema.
|
||||
@param diagram_id numero du schema concerne
|
||||
*/
|
||||
void ExportDialog::slot_correctWidth(int diagram_id) {
|
||||
void ExportDialog::slot_correctWidth(int diagram_id)
|
||||
{
|
||||
// recupere l'ExportDiagramLine concernee
|
||||
ExportDialog::ExportDiagramLine *current_diagram = diagram_lines_[diagram_id];
|
||||
if (!current_diagram) return;
|
||||
@ -258,7 +269,8 @@ void ExportDialog::slot_correctWidth(int diagram_id) {
|
||||
activee pour ce schema.
|
||||
@param diagram_id numero du schema concerne
|
||||
*/
|
||||
void ExportDialog::slot_correctHeight(int diagram_id) {
|
||||
void ExportDialog::slot_correctHeight(int diagram_id)
|
||||
{
|
||||
// recupere l'ExportDiagramLine concernee
|
||||
ExportDialog::ExportDiagramLine *current_diagram = diagram_lines_[diagram_id];
|
||||
if (!current_diagram) return;
|
||||
@ -280,7 +292,8 @@ void ExportDialog::slot_correctHeight(int diagram_id) {
|
||||
proportions d'un des schemas
|
||||
@param diagram_id numero du schema concerne
|
||||
*/
|
||||
void ExportDialog::slot_keepRatioChanged(int diagram_id) {
|
||||
void ExportDialog::slot_keepRatioChanged(int diagram_id)
|
||||
{
|
||||
// recupere l'ExportDiagramLine concernee
|
||||
ExportDialog::ExportDiagramLine *current_diagram = diagram_lines_[diagram_id];
|
||||
if (!current_diagram) return;
|
||||
@ -303,7 +316,8 @@ void ExportDialog::slot_keepRatioChanged(int diagram_id) {
|
||||
Reinitialise les dimensions d'un des schemas
|
||||
@param diagram_id numero du schema concerne
|
||||
*/
|
||||
void ExportDialog::slot_resetSize(int diagram_id) {
|
||||
void ExportDialog::slot_resetSize(int diagram_id)
|
||||
{
|
||||
// recupere l'ExportDiagramLine concernee
|
||||
ExportDialog::ExportDiagramLine *current_diagram = diagram_lines_[diagram_id];
|
||||
if (!current_diagram) return;
|
||||
@ -328,7 +342,12 @@ void ExportDialog::slot_resetSize(int diagram_id) {
|
||||
@param keep_aspect_ratio True pour conserver le ratio, false sinon
|
||||
@return l'image a exporter
|
||||
*/
|
||||
QImage ExportDialog::generateImage(Diagram *diagram, int width, int height, bool keep_aspect_ratio) {
|
||||
QImage ExportDialog::generateImage(
|
||||
Diagram *diagram,
|
||||
int width,
|
||||
int height,
|
||||
bool keep_aspect_ratio)
|
||||
{
|
||||
saveReloadDiagramParameters(diagram, true);
|
||||
|
||||
QImage image(width, height, QImage::Format_RGB32);
|
||||
@ -370,7 +389,13 @@ void ExportDialog::saveReloadDiagramParameters(Diagram *diagram, bool save) {
|
||||
@param keep_aspect_ratio True pour conserver le ratio, false sinon
|
||||
@param io_device Peripherique de sortie pour le code SVG (souvent : un fichier)
|
||||
*/
|
||||
void ExportDialog::generateSvg(Diagram *diagram, int width, int height, bool keep_aspect_ratio, QIODevice &io_device) {
|
||||
void ExportDialog::generateSvg(
|
||||
Diagram *diagram,
|
||||
int width,
|
||||
int height,
|
||||
bool keep_aspect_ratio,
|
||||
QIODevice &io_device)
|
||||
{
|
||||
saveReloadDiagramParameters(diagram, true);
|
||||
|
||||
// genere une QPicture a partir du schema
|
||||
@ -399,10 +424,12 @@ void ExportDialog::generateSvg(Diagram *diagram, int width, int height, bool kee
|
||||
@param height Hauteur de l'export DXF
|
||||
@param file_path
|
||||
*/
|
||||
void ExportDialog::generateDxf(Diagram *diagram,
|
||||
int width,
|
||||
int height,
|
||||
QString &file_path) {
|
||||
void ExportDialog::generateDxf(
|
||||
Diagram *diagram,
|
||||
int width,
|
||||
int height,
|
||||
QString &file_path)
|
||||
{
|
||||
saveReloadDiagramParameters(diagram, true);
|
||||
|
||||
width -= 2*Diagram::margin;
|
||||
@ -437,7 +464,7 @@ void ExportDialog::generateDxf(Diagram *diagram,
|
||||
QList<QRectF *> list_rectangles;
|
||||
//QList<QRectF *> list_ellipses;
|
||||
QList <QetShapeItem *> list_shapes;
|
||||
QList <QetGraphicsTableItem *> list_tables;
|
||||
QList <QetGraphicsTableItem *> list_tables;
|
||||
|
||||
// Determine les elements a "XMLiser"
|
||||
foreach(QGraphicsItem *qgi, diagram -> items()) {
|
||||
@ -453,17 +480,17 @@ void ExportDialog::generateDxf(Diagram *diagram,
|
||||
list_shapes << dii;
|
||||
} else if (DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(qgi)) {
|
||||
list_texts << deti;
|
||||
} else if (QetGraphicsTableItem *gti = qgraphicsitem_cast<QetGraphicsTableItem *>(qgi)) {
|
||||
list_tables << gti;
|
||||
}
|
||||
} else if (QetGraphicsTableItem *gti = qgraphicsitem_cast<QetGraphicsTableItem *>(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 tables
|
||||
foreach (QetGraphicsTableItem *gti, list_tables) {
|
||||
gti->toDXF(file_path);
|
||||
}
|
||||
|
||||
//Draw elements
|
||||
foreach(Element *elmt, list_elements)
|
||||
@ -598,14 +625,14 @@ void ExportDialog::generateDxf(Diagram *diagram,
|
||||
}
|
||||
|
||||
//Draw conductors
|
||||
foreach(Conductor *cond, list_conductors) {
|
||||
qreal cx = cond->pos().x();
|
||||
qreal cy = cond->pos().y();
|
||||
foreach(ConductorSegment *segment, cond -> segmentsList()) {
|
||||
qreal x1 = (cx + segment -> firstPoint().x()) * Createdxf::xScale;
|
||||
qreal y1 = Createdxf::sheetHeight - ((cy + segment -> firstPoint().y()) * Createdxf::yScale);
|
||||
qreal x2 = (cx + segment -> secondPoint().x()) * Createdxf::xScale;
|
||||
qreal y2 = Createdxf::sheetHeight - ((cy + segment -> secondPoint().y()) * Createdxf::yScale);
|
||||
foreach(Conductor *cond, list_conductors) {
|
||||
qreal cx = cond->pos().x();
|
||||
qreal cy = cond->pos().y();
|
||||
foreach(ConductorSegment *segment, cond -> segmentsList()) {
|
||||
qreal x1 = (cx + segment -> firstPoint().x()) * Createdxf::xScale;
|
||||
qreal y1 = Createdxf::sheetHeight - ((cy + segment -> firstPoint().y()) * Createdxf::yScale);
|
||||
qreal x2 = (cx + segment -> secondPoint().x()) * Createdxf::xScale;
|
||||
qreal y2 = Createdxf::sheetHeight - ((cy + segment -> secondPoint().y()) * Createdxf::yScale);
|
||||
Createdxf::drawLine(file_path, x1, y1, x2, y2, 0);
|
||||
}
|
||||
//Draw conductor text item
|
||||
@ -666,7 +693,7 @@ void ExportDialog::generateDxf(Diagram *diagram,
|
||||
}
|
||||
Createdxf::dxfEnd(file_path);
|
||||
|
||||
saveReloadDiagramParameters(diagram, false);
|
||||
saveReloadDiagramParameters(diagram, false);
|
||||
}
|
||||
|
||||
QPointF ExportDialog::rotation_transformed(qreal px,
|
||||
@ -696,7 +723,8 @@ QPointF ExportDialog::rotation_transformed(qreal px,
|
||||
/**
|
||||
Slot effectuant les exports apres la validation du dialogue.
|
||||
*/
|
||||
void ExportDialog::slot_export() {
|
||||
void ExportDialog::slot_export()
|
||||
{
|
||||
// recupere la liste des schemas a exporter
|
||||
QList<ExportDiagramLine *> diagrams_to_export;
|
||||
foreach(ExportDiagramLine *diagram_line, diagram_lines_.values()) {
|
||||
@ -822,7 +850,8 @@ void ExportDialog::exportDiagram(ExportDiagramLine *diagram_line) {
|
||||
Slot appele lorsque l'utilisateur change la zone du schema qui doit etre
|
||||
exportee. Il faut alors ajuster les dimensions des schemas.
|
||||
*/
|
||||
void ExportDialog::slot_changeUseBorder() {
|
||||
void ExportDialog::slot_changeUseBorder()
|
||||
{
|
||||
// parcourt les schemas a exporter
|
||||
foreach(int diagram_id, diagram_lines_.keys()) {
|
||||
ExportDiagramLine *diagram_line = diagram_lines_[diagram_id];
|
||||
@ -840,7 +869,8 @@ void ExportDialog::slot_changeUseBorder() {
|
||||
schemas coches, et il garde au plus un schema coche si on exporte vers
|
||||
le presse-papier.
|
||||
*/
|
||||
void ExportDialog::slot_checkDiagramsCount() {
|
||||
void ExportDialog::slot_checkDiagramsCount()
|
||||
{
|
||||
QPushButton *export_button = buttons -> button(QDialogButtonBox::Save);
|
||||
export_button -> setEnabled(diagramsToExportCount());
|
||||
}
|
||||
@ -1027,14 +1057,16 @@ ExportDialog::ExportDiagramLine::ExportDiagramLine(Diagram *dia, QSize diagram_s
|
||||
/**
|
||||
Destructeur
|
||||
*/
|
||||
ExportDialog::ExportDiagramLine::~ExportDiagramLine() {
|
||||
ExportDialog::ExportDiagramLine::~ExportDiagramLine()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@return un layout contenant les widgets necessaires a la gestion de la
|
||||
taille d'un schema avant son export.
|
||||
*/
|
||||
QBoxLayout *ExportDialog::ExportDiagramLine::sizeLayout() {
|
||||
QBoxLayout *ExportDialog::ExportDiagramLine::sizeLayout()
|
||||
{
|
||||
QHBoxLayout *layout = new QHBoxLayout();
|
||||
layout -> addWidget(width);
|
||||
layout -> addWidget(x_label);
|
||||
|
@ -30,20 +30,18 @@ class ExportPropertiesWidget;
|
||||
class ExportDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
// constructors, destructor
|
||||
public:
|
||||
// constructors, destructor
|
||||
ExportDialog(QETProject *, QWidget * = nullptr);
|
||||
~ExportDialog() override;
|
||||
|
||||
private:
|
||||
ExportDialog(const ExportDialog &);
|
||||
|
||||
// methods
|
||||
public:
|
||||
int diagramsToExportCount() const;
|
||||
static QPointF rotation_transformed(qreal, qreal, qreal, qreal, qreal);
|
||||
|
||||
private:
|
||||
ExportDialog(const ExportDialog &);
|
||||
|
||||
class ExportDiagramLine {
|
||||
public:
|
||||
ExportDiagramLine(Diagram *, QSize);
|
||||
@ -85,7 +83,6 @@ class ExportDialog : public QDialog {
|
||||
QETProject *project_;
|
||||
|
||||
// methods
|
||||
private:
|
||||
QWidget *initDiagramsListPart();
|
||||
void saveReloadDiagramParameters(Diagram *, bool = true);
|
||||
void generateSvg(Diagram *, int, int, bool, QIODevice &);
|
||||
|
@ -44,7 +44,8 @@ ExportProperties::ExportProperties() :
|
||||
/**
|
||||
Destructeur
|
||||
*/
|
||||
ExportProperties::~ExportProperties() {
|
||||
ExportProperties::~ExportProperties()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +54,8 @@ ExportProperties::~ExportProperties() {
|
||||
@param prefix prefixe a ajouter devant les noms des parametres
|
||||
*/
|
||||
void ExportProperties::toSettings(QSettings &settings,
|
||||
const QString &prefix) const {
|
||||
const QString &prefix) const
|
||||
{
|
||||
settings.setValue(prefix + "path",
|
||||
QDir::toNativeSeparators(
|
||||
destination_directory.absolutePath()));
|
||||
|
@ -31,7 +31,7 @@ static int no_model_width = 40;
|
||||
@param parent
|
||||
*/
|
||||
QetGraphicsHeaderItem::QetGraphicsHeaderItem(QGraphicsItem *parent) :
|
||||
QGraphicsObject(parent)
|
||||
QGraphicsObject(parent)
|
||||
{}
|
||||
|
||||
/**
|
||||
@ -44,17 +44,23 @@ QetGraphicsHeaderItem::QetGraphicsHeaderItem(QGraphicsItem *parent) :
|
||||
void QetGraphicsHeaderItem::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
if (m_model) {
|
||||
disconnect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::headerDataChanged,
|
||||
this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset,
|
||||
this, &QetGraphicsHeaderItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::columnsInserted,
|
||||
this, &QetGraphicsHeaderItem::modelReseted);
|
||||
}
|
||||
|
||||
m_model = model;
|
||||
m_model = model;
|
||||
if (m_model)
|
||||
{
|
||||
connect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::headerDataChanged,
|
||||
this, &QetGraphicsHeaderItem::headerDataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this,
|
||||
&QetGraphicsHeaderItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::columnsInserted,
|
||||
this, &QetGraphicsHeaderItem::modelReseted);
|
||||
setUpMinimumSectionsSize();
|
||||
m_current_sections_width.clear();
|
||||
m_current_sections_width.resize(m_sections_minimum_width.size());
|
||||
@ -69,7 +75,8 @@ void QetGraphicsHeaderItem::setModel(QAbstractItemModel *model)
|
||||
@brief QetGraphicsHeaderItem::model
|
||||
@return the model that this item is presenting
|
||||
*/
|
||||
QAbstractItemModel *QetGraphicsHeaderItem::model() const {
|
||||
QAbstractItemModel *QetGraphicsHeaderItem::model() const
|
||||
{
|
||||
return m_model;
|
||||
}
|
||||
|
||||
@ -78,7 +85,8 @@ QAbstractItemModel *QetGraphicsHeaderItem::model() const {
|
||||
Reimplemented from QGraphicsObject::boundingRect() const;
|
||||
@return
|
||||
*/
|
||||
QRectF QetGraphicsHeaderItem::boundingRect() const {
|
||||
QRectF QetGraphicsHeaderItem::boundingRect() const
|
||||
{
|
||||
return m_bounding_rect;
|
||||
}
|
||||
|
||||
@ -89,7 +97,10 @@ QRectF QetGraphicsHeaderItem::boundingRect() const {
|
||||
@param option
|
||||
@param widget
|
||||
*/
|
||||
void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
void QetGraphicsHeaderItem::paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
@ -113,9 +124,13 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
painter->setFont(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value<QFont>());
|
||||
painter->setFont(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::FontRole).value<QFont>());
|
||||
|
||||
//Draw vertical lines
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
for(auto size : m_current_sections_width)
|
||||
{
|
||||
@ -125,15 +140,33 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||
offset += size;
|
||||
}
|
||||
|
||||
//Write text of each cell
|
||||
auto margins_ = QETUtils::marginsFromString(m_model->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString());
|
||||
//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());
|
||||
painter->drawText(QRectF(top_left, size),
|
||||
m_model->headerData(0, Qt::Horizontal, Qt::TextAlignmentRole).toInt(),
|
||||
m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
QSize size(
|
||||
m_current_sections_width.at(i)
|
||||
- margins_.left()
|
||||
- margins_.right(),
|
||||
|
||||
m_section_height
|
||||
- margins_.top()
|
||||
- margins_.bottom());
|
||||
painter->drawText(
|
||||
QRectF(top_left, size),
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::TextAlignmentRole).toInt(),
|
||||
m_model->headerData(
|
||||
i,
|
||||
Qt::Horizontal,
|
||||
Qt::DisplayRole).toString());
|
||||
|
||||
top_left.setX(top_left.x() + m_current_sections_width.at(i));
|
||||
}
|
||||
@ -141,54 +174,71 @@ 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
|
||||
@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);
|
||||
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;
|
||||
}
|
||||
//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());
|
||||
//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;
|
||||
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;
|
||||
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);
|
||||
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;
|
||||
top_left.setX(top_left.x() + m_current_sections_width.at(i));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetGraphicsHeaderItem::rect
|
||||
@return the current rect of the item aka the size of rectangle painted.
|
||||
*/
|
||||
QRect QetGraphicsHeaderItem::rect() const {
|
||||
QRect QetGraphicsHeaderItem::rect() const
|
||||
{
|
||||
return m_current_rect;
|
||||
}
|
||||
|
||||
@ -223,7 +273,11 @@ void QetGraphicsHeaderItem::resizeSection(int logicalIndex, int size)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_current_sections_width.replace(logicalIndex, size);
|
||||
m_current_rect.setWidth(std::accumulate(m_current_sections_width.begin(), m_current_sections_width.end(), 0));
|
||||
m_current_rect.setWidth(
|
||||
std::accumulate(
|
||||
m_current_sections_width.begin(),
|
||||
m_current_sections_width.end(),
|
||||
0));
|
||||
setUpBoundingRect();
|
||||
update();
|
||||
emit sectionResized(logicalIndex, size);
|
||||
@ -254,7 +308,14 @@ QDomElement QetGraphicsHeaderItem::toXml(QDomDocument &document) const
|
||||
{
|
||||
auto dom_element = document.createElement(xmlTagName());
|
||||
if (m_model) {
|
||||
dom_element.appendChild(QETXML::marginsToXml(document, QETUtils::marginsFromString(m_model->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString())));
|
||||
dom_element.appendChild(
|
||||
QETXML::marginsToXml(
|
||||
document,
|
||||
QETUtils::marginsFromString(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::UserRole+1).toString())));
|
||||
}
|
||||
|
||||
return dom_element;
|
||||
@ -271,8 +332,16 @@ void QetGraphicsHeaderItem::fromXml(const QDomElement &element)
|
||||
return;
|
||||
}
|
||||
|
||||
auto margins_ = QETUtils::marginsToString(QETXML::marginsFromXml(element.firstChildElement("margins")));
|
||||
m_model->setHeaderData(0, Qt::Horizontal, QETUtils::marginsToString(QETXML::marginsFromXml(element.firstChildElement("margins"))), Qt::UserRole+1);
|
||||
auto margins_ = QETUtils::marginsToString(
|
||||
QETXML::marginsFromXml(
|
||||
element.firstChildElement("margins")));
|
||||
m_model->setHeaderData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
QETUtils::marginsToString(
|
||||
QETXML::marginsFromXml(
|
||||
element.firstChildElement("margins"))),
|
||||
Qt::UserRole+1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,10 +360,19 @@ void QetGraphicsHeaderItem::setUpMinimumSectionsSize()
|
||||
return;
|
||||
}
|
||||
|
||||
QFontMetrics metrics(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value<QFont>());
|
||||
auto margins_ = QETUtils::marginsFromString(m_model->headerData(0, Qt::Horizontal, Qt::UserRole+1).toString());
|
||||
QFontMetrics metrics(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::FontRole).value<QFont>());
|
||||
auto margins_ = QETUtils::marginsFromString(
|
||||
m_model->headerData(
|
||||
0,
|
||||
Qt::Horizontal,
|
||||
Qt::UserRole+1).toString());
|
||||
//Set the height of row;
|
||||
m_minimum_section_height = metrics.boundingRect("HEIGHT TEST").height() + margins_.top() + margins_.bottom();
|
||||
m_minimum_section_height = metrics.boundingRect("HEIGHT TEST").height()
|
||||
+ margins_.top() + margins_.bottom();
|
||||
|
||||
m_sections_minimum_width.clear();
|
||||
m_sections_minimum_width.resize(m_model->columnCount());
|
||||
@ -302,17 +380,25 @@ void QetGraphicsHeaderItem::setUpMinimumSectionsSize()
|
||||
for (auto i= 0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
auto str = m_model->headerData(i, Qt::Horizontal).toString();
|
||||
m_sections_minimum_width.replace(i, metrics.boundingRect(str).width() + margins_.left() + margins_.right());
|
||||
m_sections_minimum_width.replace(
|
||||
i,
|
||||
metrics.boundingRect(str).width()
|
||||
+ margins_.left()
|
||||
+ margins_.right());
|
||||
}
|
||||
|
||||
m_minimum_width = std::accumulate(m_sections_minimum_width.begin(), m_sections_minimum_width.end(), 0);
|
||||
m_minimum_width = std::accumulate(
|
||||
m_sections_minimum_width.begin(),
|
||||
m_sections_minimum_width.end(),
|
||||
0);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetGraphicsHeaderItem::setUpBoundingRect
|
||||
Setup the bounding rect of the item
|
||||
*/
|
||||
void QetGraphicsHeaderItem::setUpBoundingRect() {
|
||||
void QetGraphicsHeaderItem::setUpBoundingRect()
|
||||
{
|
||||
m_bounding_rect = m_current_rect.adjusted(-10, -10, 10, 10);
|
||||
}
|
||||
|
||||
@ -323,7 +409,8 @@ void QetGraphicsHeaderItem::setUpBoundingRect() {
|
||||
@param first
|
||||
@param last
|
||||
*/
|
||||
void QetGraphicsHeaderItem::headerDataChanged(Qt::Orientations orientation, int first, int last)
|
||||
void QetGraphicsHeaderItem::headerDataChanged(
|
||||
Qt::Orientations orientation, int first, int last)
|
||||
{
|
||||
Q_UNUSED(orientation)
|
||||
Q_UNUSED(first)
|
||||
|
@ -51,17 +51,22 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
||||
QAbstractItemModel *model() const;
|
||||
|
||||
virtual QRectF boundingRect() const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
virtual void paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget) override;
|
||||
QRect rect() const;
|
||||
void resizeSection(int logicalIndex, int size);
|
||||
int sectionSize(int logical_index) const;
|
||||
QVector<int> minimumSectionWidth() const {return m_sections_minimum_width;}
|
||||
int minimumWidth() const {return m_minimum_width;}
|
||||
QVector<int> minimumSectionWidth() const
|
||||
{return m_sections_minimum_width;}
|
||||
int minimumWidth() const
|
||||
{return m_minimum_width;}
|
||||
|
||||
QDomElement toXml (QDomDocument &document) const;
|
||||
void fromXml(const QDomElement &element);
|
||||
static QString xmlTagName() {return QString("graphics_header");}
|
||||
virtual bool toDXF (const QString &filepath);
|
||||
virtual bool toDXF (const QString &filepath);
|
||||
|
||||
signals:
|
||||
void sectionResized(int logicalIndex, int size);
|
||||
@ -70,19 +75,25 @@ class QetGraphicsHeaderItem : public QGraphicsObject
|
||||
private:
|
||||
void setUpMinimumSectionsSize();
|
||||
void setUpBoundingRect();
|
||||
void headerDataChanged(Qt::Orientations orientation, int first, int last);
|
||||
void headerDataChanged(
|
||||
Qt::Orientations orientation,
|
||||
int first,
|
||||
int last);
|
||||
void adjustSize();
|
||||
void modelReseted();
|
||||
|
||||
private:
|
||||
QRect m_current_rect;
|
||||
QRectF m_bounding_rect;
|
||||
QAbstractItemModel *m_model = nullptr;
|
||||
QVector<int> m_sections_minimum_width,
|
||||
m_current_sections_width;
|
||||
int m_section_height=1,
|
||||
m_minimum_section_height=1;
|
||||
int m_minimum_width=1;
|
||||
QRect m_current_rect;
|
||||
|
||||
QVector<int>
|
||||
m_sections_minimum_width,
|
||||
m_current_sections_width;
|
||||
|
||||
int
|
||||
m_section_height=1,
|
||||
m_minimum_section_height=1,
|
||||
m_minimum_width=1;
|
||||
};
|
||||
|
||||
#endif // QETGRAPHICSHEADERITEM_H
|
||||
|
@ -40,24 +40,29 @@ static int no_model_width = 40;
|
||||
@param table : table to adjust
|
||||
@param margins : margins between table and folio.
|
||||
*/
|
||||
void QetGraphicsTableItem::adjustTableToFolio(QetGraphicsTableItem *table,
|
||||
QMargins margins)
|
||||
void QetGraphicsTableItem::adjustTableToFolio(
|
||||
QetGraphicsTableItem *table,
|
||||
QMargins margins)
|
||||
{
|
||||
if (!table->diagram()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto drawable_rect = table->diagram()->border_and_titleblock.insideBorderRect();
|
||||
table->setPos(drawable_rect.topLeft().x() + margins.left(), drawable_rect.topLeft().y() + margins.top() + table->headerItem()->rect().height());
|
||||
table->setPos(
|
||||
drawable_rect.topLeft().x() + margins.left(),
|
||||
drawable_rect.topLeft().y()
|
||||
+ margins.top()
|
||||
+ table->headerItem()->rect().height());
|
||||
|
||||
auto size_ = table->size();
|
||||
size_.setWidth(int(drawable_rect.width() - (margins.left() + margins.right())));
|
||||
//Size must be a multiple of 10, because the table adjust itself by step of 10.
|
||||
//Size must be a multiple of 10, because the table adjust itself by step of 10.
|
||||
while (size_.width()%10) {
|
||||
--size_.rwidth(); }
|
||||
table->setSize(size_);
|
||||
|
||||
//Calcul the maximum row to display to fit the nomenclature into diagram
|
||||
//Calcul the maximum row to display to fit the nomenclature into diagram
|
||||
auto available_height = drawable_rect.height() - table->pos().y();
|
||||
auto min_row_height = table->minimumRowHeigth();
|
||||
table->setDisplayNRow(int(floor(available_height/min_row_height))); //Convert a double to int, but max_row_to_display is already rounded an integer so we assume everything is ok
|
||||
@ -130,16 +135,21 @@ QetGraphicsTableItem::QetGraphicsTableItem(QGraphicsItem *parent) :
|
||||
setAcceptHoverEvents(true);
|
||||
setUpHandler();
|
||||
|
||||
//A litle bounding rect before model is set,
|
||||
//then user can already grab this item, even if model is not already set
|
||||
//A litle bounding rect before model is set,
|
||||
//then user can already grab this item, even if model is not already set
|
||||
m_bounding_rect.setRect(m_br_margin/-2, m_br_margin/-2, 50, 50);
|
||||
|
||||
connect(this, &QetGraphicsTableItem::xChanged, this, &QetGraphicsTableItem::adjustHandlerPos);
|
||||
connect(this, &QetGraphicsTableItem::yChanged, this, &QetGraphicsTableItem::adjustHandlerPos);
|
||||
connect(this, &QetGraphicsTableItem::xChanged,
|
||||
this, &QetGraphicsTableItem::adjustHandlerPos);
|
||||
connect(this, &QetGraphicsTableItem::yChanged,
|
||||
this, &QetGraphicsTableItem::adjustHandlerPos);
|
||||
|
||||
m_header_item = new QetGraphicsHeaderItem(this);
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::heightResized, this, [this]() {
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::sectionResized,
|
||||
this, &QetGraphicsTableItem::headerSectionResized);
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::heightResized,
|
||||
this, [this]()
|
||||
{
|
||||
m_header_item->setPos(0, 0-m_header_item->rect().height());
|
||||
});
|
||||
//Init the size of table without a model
|
||||
@ -160,8 +170,10 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
if (m_model)
|
||||
{
|
||||
disconnect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted);
|
||||
disconnect(m_model, &QAbstractItemModel::dataChanged,
|
||||
this, &QetGraphicsTableItem::dataChanged);
|
||||
disconnect(m_model, &QAbstractItemModel::modelReset,
|
||||
this, &QetGraphicsTableItem::modelReseted);
|
||||
}
|
||||
m_model = model;
|
||||
m_header_item->setModel(model);
|
||||
@ -172,8 +184,10 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
m_header_item->setPos(0, -m_header_item->rect().height());
|
||||
if (m_model)
|
||||
{
|
||||
connect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted);
|
||||
connect(m_model, &QAbstractItemModel::dataChanged,
|
||||
this, &QetGraphicsTableItem::dataChanged);
|
||||
connect(m_model, &QAbstractItemModel::modelReset,
|
||||
this, &QetGraphicsTableItem::modelReseted);
|
||||
}
|
||||
|
||||
if (m_next_table) {
|
||||
@ -185,7 +199,8 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model)
|
||||
@brief QetGraphicsTableItem::model
|
||||
@return The model that this item is presenting
|
||||
*/
|
||||
QAbstractItemModel *QetGraphicsTableItem::model() const {
|
||||
QAbstractItemModel *QetGraphicsTableItem::model() const
|
||||
{
|
||||
return m_model;
|
||||
}
|
||||
|
||||
@ -194,7 +209,8 @@ QAbstractItemModel *QetGraphicsTableItem::model() const {
|
||||
Reimplemented from QGraphicsObject
|
||||
@return
|
||||
*/
|
||||
QRectF QetGraphicsTableItem::boundingRect() const {
|
||||
QRectF QetGraphicsTableItem::boundingRect() const
|
||||
{
|
||||
return m_bounding_rect;
|
||||
}
|
||||
|
||||
@ -205,7 +221,10 @@ QRectF QetGraphicsTableItem::boundingRect() const {
|
||||
@param option
|
||||
@param widget
|
||||
*/
|
||||
void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
void QetGraphicsTableItem::paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
@ -236,7 +255,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
}
|
||||
painter->setFont(m_model->data(m_model->index(0,0), Qt::FontRole).value<QFont>());
|
||||
|
||||
//Draw vertical lines
|
||||
//Draw vertical lines
|
||||
auto offset= 0;
|
||||
for(auto i=0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
@ -246,7 +265,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
offset += m_header_item->sectionSize(i);
|
||||
}
|
||||
|
||||
//Calcule the number of rows to display.
|
||||
//Calcule 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
|
||||
@ -255,7 +274,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
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
|
||||
//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)
|
||||
{
|
||||
@ -264,7 +283,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
painter->drawLine(p1, p2);
|
||||
}
|
||||
|
||||
//Write text of each cell
|
||||
//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());
|
||||
@ -272,16 +291,23 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
|
||||
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
|
||||
//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;
|
||||
painter->drawText(QRectF(top_left, size),
|
||||
m_model->data(m_model->index(0,0), Qt::TextAlignmentRole).toInt() | Qt::AlignVCenter,
|
||||
m_model->index(index_row, j).data().toString());
|
||||
painter->drawText(
|
||||
QRectF(top_left, size),
|
||||
m_model->data(
|
||||
m_model->index(0,0),
|
||||
Qt::TextAlignmentRole
|
||||
).toInt()
|
||||
| Qt::AlignVCenter,
|
||||
m_model->index(index_row, j)
|
||||
.data().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,7 +322,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt
|
||||
void QetGraphicsTableItem::setSize(const QSize &size)
|
||||
{
|
||||
auto new_size = size;
|
||||
if (new_size.width() < minimumSize().width()) {
|
||||
if (new_size.width() < minimumSize().width()) {
|
||||
new_size.setWidth(minimumSize().width());
|
||||
}
|
||||
if (new_size.height() < minimumSize().height()) {
|
||||
@ -325,7 +351,8 @@ QSize QetGraphicsTableItem::size() const
|
||||
/**
|
||||
@brief QetGraphicsTableItem::minimumSize
|
||||
@return the minimum size the table can be
|
||||
The returned size take care of the table's minimum width, but also the header item's minimum width
|
||||
The returned size take care of the table's minimum width,
|
||||
but also the header item's minimum width
|
||||
*/
|
||||
QSize QetGraphicsTableItem::minimumSize() const
|
||||
{
|
||||
@ -342,9 +369,14 @@ QSize QetGraphicsTableItem::minimumSize() const
|
||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
||||
|
||||
|
||||
//m_minimum_column_width already take in count the minimum size of header
|
||||
QSize size_(std::accumulate(m_minimum_column_width.begin(), m_minimum_column_width.end(), 0), m_minimum_row_height*row_count);
|
||||
//make sure that the width is a multiple of 10
|
||||
//m_minimum_column_width already take in count the minimum size of header
|
||||
QSize size_(
|
||||
std::accumulate(
|
||||
m_minimum_column_width.begin(),
|
||||
m_minimum_column_width.end(),
|
||||
0),
|
||||
m_minimum_row_height*row_count);
|
||||
//make sure that the width is a multiple of 10
|
||||
while (size_.width()%10) {
|
||||
size_.rwidth()++;
|
||||
}
|
||||
@ -356,7 +388,8 @@ QSize QetGraphicsTableItem::minimumSize() const
|
||||
Limit the number of row to display
|
||||
@param number : set to 0 or less to disabled the limit of row to display
|
||||
*/
|
||||
void QetGraphicsTableItem::setDisplayNRow(const int &number) {
|
||||
void QetGraphicsTableItem::setDisplayNRow(const int &number)
|
||||
{
|
||||
m_number_of_displayed_row = number;
|
||||
setToMinimumHeight();
|
||||
if (m_next_table)
|
||||
@ -368,7 +401,8 @@ void QetGraphicsTableItem::setDisplayNRow(const int &number) {
|
||||
@return the number of row displayed.
|
||||
A value of 0 or less mean there is no limit
|
||||
*/
|
||||
int QetGraphicsTableItem::displayNRow() const {
|
||||
int QetGraphicsTableItem::displayNRow() const
|
||||
{
|
||||
return m_number_of_displayed_row;
|
||||
}
|
||||
|
||||
@ -439,11 +473,13 @@ void QetGraphicsTableItem::setNextTable(QetGraphicsTableItem *table)
|
||||
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::setTableName(const QString &name) {
|
||||
void QetGraphicsTableItem::setTableName(const QString &name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QString QetGraphicsTableItem::tableName() const {
|
||||
QString QetGraphicsTableItem::tableName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
@ -461,11 +497,13 @@ int QetGraphicsTableItem::displayNRowOffset() const
|
||||
return offset_;
|
||||
}
|
||||
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const {
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const
|
||||
{
|
||||
return m_previous_table;
|
||||
}
|
||||
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::nextTable() const {
|
||||
QetGraphicsTableItem *QetGraphicsTableItem::nextTable() const
|
||||
{
|
||||
return m_next_table;
|
||||
}
|
||||
|
||||
@ -498,7 +536,8 @@ void QetGraphicsTableItem::initLink()
|
||||
@brief QetGraphicsTableItem::minimumRowHeigth
|
||||
@return the minimum height of a row
|
||||
*/
|
||||
int QetGraphicsTableItem::minimumRowHeigth() const {
|
||||
int QetGraphicsTableItem::minimumRowHeigth() const
|
||||
{
|
||||
return m_minimum_row_height;
|
||||
}
|
||||
|
||||
@ -554,103 +593,139 @@ void QetGraphicsTableItem::fromXml(const QDomElement &dom_element)
|
||||
return;
|
||||
}
|
||||
|
||||
this->setPos(dom_element.attribute("x", QString::number(10)).toDouble(),
|
||||
dom_element.attribute("y", QString::number(10)).toDouble());
|
||||
//Size is not set now because will change during the whole process of opening a project from the xml
|
||||
m_pending_size = QSize(dom_element.attribute("width", QString::number(no_model_width)).toInt(),
|
||||
dom_element.attribute("height", QString::number(no_model_height)).toInt());
|
||||
this->setPos(
|
||||
dom_element.attribute(
|
||||
"x",
|
||||
QString::number(10)).toDouble(),
|
||||
dom_element.attribute(
|
||||
"y",
|
||||
QString::number(10)).toDouble());
|
||||
//Size is not set now because will change during the whole process of opening a project from the xml
|
||||
m_pending_size = QSize(
|
||||
dom_element.attribute(
|
||||
"width",
|
||||
QString::number(no_model_width)).toInt(),
|
||||
dom_element.attribute(
|
||||
"height",
|
||||
QString::number(no_model_height)).toInt());
|
||||
|
||||
m_uuid = QUuid(dom_element.attribute("uuid", QUuid::createUuid().toString()));
|
||||
m_uuid = QUuid(
|
||||
dom_element.attribute(
|
||||
"uuid",
|
||||
QUuid::createUuid().toString()));
|
||||
m_name = dom_element.attribute("name");
|
||||
m_number_of_displayed_row = dom_element.attribute("display_n_row", QString::number(0)).toInt();
|
||||
m_number_of_displayed_row = dom_element.attribute(
|
||||
"display_n_row",
|
||||
QString::number(0)).toInt();
|
||||
|
||||
auto vector_ = QETXML::directChild(dom_element, "previous_table");
|
||||
if (vector_.size()) { //Table have a previous table
|
||||
m_pending_previous_table_uuid = QUuid(vector_.first().attribute("uuid"));
|
||||
m_pending_previous_table_uuid = QUuid(
|
||||
vector_.first().attribute("uuid"));
|
||||
}
|
||||
else if (this->diagram()) //The table haven't got a previous table, so there should be a model save to xml
|
||||
{
|
||||
//Get table
|
||||
auto model_ = new ProjectDBModel(this->diagram()->project(), this->diagram()->project());
|
||||
model_->fromXml(dom_element.firstChildElement("model").firstChildElement(ProjectDBModel::xmlTagName()));
|
||||
//Get table
|
||||
auto model_ = new ProjectDBModel(
|
||||
this->diagram()->project(),
|
||||
this->diagram()->project());
|
||||
model_->fromXml(
|
||||
dom_element
|
||||
.firstChildElement("model")
|
||||
.firstChildElement(
|
||||
ProjectDBModel::xmlTagName()));
|
||||
this->setModel(model_);
|
||||
}
|
||||
|
||||
//Restore the header from xml
|
||||
m_header_item->fromXml(dom_element.firstChildElement(QetGraphicsHeaderItem::xmlTagName()));
|
||||
//Restore the header from xml
|
||||
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
|
||||
@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);
|
||||
// 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);
|
||||
//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);
|
||||
offset += m_header_item->sectionSize(i);
|
||||
}
|
||||
//Calculate the number of rows to display.
|
||||
auto row_count = m_model->rowCount();
|
||||
//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);
|
||||
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_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);
|
||||
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);
|
||||
}
|
||||
//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);
|
||||
}
|
||||
|
||||
//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());
|
||||
//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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
Createdxf::drawTextAligned(
|
||||
filepath,
|
||||
m_model->index(index_row, j).data().toString(),
|
||||
x,y,h1,0,0,0,valign,x,0,0);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -719,7 +794,8 @@ bool QetGraphicsTableItem::sceneEventFilter(QGraphicsItem *watched, QEvent *even
|
||||
@param value
|
||||
@return
|
||||
*/
|
||||
QVariant QetGraphicsTableItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
QVariant QetGraphicsTableItem::itemChange(
|
||||
QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
//item was removed from scene, we remove the handler
|
||||
if (change == ItemSceneHasChanged) {
|
||||
@ -731,7 +807,8 @@ QVariant QetGraphicsTableItem::itemChange(QGraphicsItem::GraphicsItemChange chan
|
||||
return QetGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::modelReseted() {
|
||||
void QetGraphicsTableItem::modelReseted()
|
||||
{
|
||||
dataChanged(m_model->index(0,0), m_model->index(0,0), QVector<int>());
|
||||
setToMinimumHeight();
|
||||
|
||||
@ -768,7 +845,11 @@ void QetGraphicsTableItem::setUpColumnAndRowMinimumSize()
|
||||
{
|
||||
auto index = m_model->index(row, col);
|
||||
auto width = metrics.boundingRect(index.data().toString()).width();
|
||||
m_minimum_column_width.replace(col, std::max(m_minimum_column_width.at(col), width + margin_.left() + margin_.right()));
|
||||
m_minimum_column_width.replace(
|
||||
col,
|
||||
std::max(
|
||||
m_minimum_column_width.at(col),
|
||||
width + margin_.left() + margin_.right()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -779,15 +860,24 @@ void QetGraphicsTableItem::setUpColumnAndRowMinimumSize()
|
||||
void QetGraphicsTableItem::setUpBoundingRect()
|
||||
{
|
||||
QSize header_size = m_header_item->rect().size();
|
||||
QRect rect(0, -header_size.height(), header_size.width(), m_current_size.height() + header_size.height());
|
||||
m_bounding_rect = rect.adjusted(-m_br_margin, -m_br_margin, m_br_margin, m_br_margin);
|
||||
QRect rect(
|
||||
0,
|
||||
-header_size.height(),
|
||||
header_size.width(),
|
||||
m_current_size.height() + header_size.height());
|
||||
m_bounding_rect = rect.adjusted(
|
||||
-m_br_margin,
|
||||
-m_br_margin,
|
||||
m_br_margin,
|
||||
m_br_margin);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetGraphicsTableItem::adjustHandlerPos
|
||||
Adjust the pos of the handler item
|
||||
*/
|
||||
void QetGraphicsTableItem::adjustHandlerPos() {
|
||||
void QetGraphicsTableItem::adjustHandlerPos()
|
||||
{
|
||||
m_handler_item.setPos(mapToScene(QRect(QPoint(0,0), size()).bottomRight()));
|
||||
}
|
||||
|
||||
@ -800,23 +890,30 @@ void QetGraphicsTableItem::setUpHandler()
|
||||
m_handler_item.setZValue(this->zValue() + 1);
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::handlerMousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
void QetGraphicsTableItem::handlerMousePressEvent(
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
diagram()->clearSelection();
|
||||
this->setSelected(true);
|
||||
m_old_size = size();
|
||||
//User start to resize the table, disconnect the signal to avoid double paint.
|
||||
disconnect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
|
||||
//User start to resize the table, disconnect the signal to avoid double paint.
|
||||
disconnect(
|
||||
m_header_item,
|
||||
&QetGraphicsHeaderItem::sectionResized,
|
||||
this,
|
||||
&QetGraphicsTableItem::headerSectionResized);
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::handlerMouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
void QetGraphicsTableItem::handlerMouseMoveEvent(
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
auto new_handler_pos = Diagram::snapToGrid(event->scenePos());
|
||||
QSize size_ = QRectF(QPointF(0,0), mapFromScene(new_handler_pos)).size().toSize();
|
||||
|
||||
QPoint new_pos(std::max(minimumSize().width(), size_.width()),
|
||||
std::max(minimumSize().height(), size_.height()));
|
||||
QPoint new_pos(
|
||||
std::max(minimumSize().width(), size_.width()),
|
||||
std::max(minimumSize().height(), size_.height()));
|
||||
m_handler_item.setPos(mapToScene(new_pos));
|
||||
|
||||
QSize new_size(new_pos.x(), new_pos.y());
|
||||
@ -825,7 +922,8 @@ void QetGraphicsTableItem::handlerMouseMoveEvent(QGraphicsSceneMouseEvent *event
|
||||
}
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::handlerMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
void QetGraphicsTableItem::handlerMouseReleaseEvent(
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (diagram())
|
||||
@ -836,12 +934,17 @@ void QetGraphicsTableItem::handlerMouseReleaseEvent(QGraphicsSceneMouseEvent *ev
|
||||
diagram()->undoStack().push(undo);
|
||||
}
|
||||
//User finish to resize the table, we can reconnect now
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
|
||||
connect(
|
||||
m_header_item,
|
||||
&QetGraphicsHeaderItem::sectionResized,
|
||||
this,
|
||||
&QetGraphicsTableItem::headerSectionResized);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetGraphicsTableItem::adjustColumnsWidth
|
||||
Adjust the size of each column according to the current table width by setting the sectionSize of the header item
|
||||
Adjust the size of each column according to the current table width
|
||||
by setting the sectionSize of the header item
|
||||
*/
|
||||
void QetGraphicsTableItem::adjustColumnsWidth()
|
||||
{
|
||||
@ -857,38 +960,59 @@ void QetGraphicsTableItem::adjustColumnsWidth()
|
||||
auto a = m_current_size.width() - minimumSize().width();
|
||||
auto b = a/std::max(1,m_model->columnCount()); //avoid divide by 0
|
||||
|
||||
disconnect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized); //Avoid to resize
|
||||
//Avoid to resize
|
||||
disconnect(
|
||||
m_header_item,
|
||||
&QetGraphicsHeaderItem::sectionResized,
|
||||
this,
|
||||
&QetGraphicsTableItem::headerSectionResized);
|
||||
|
||||
int sum_=0;
|
||||
for(auto i= 0 ; i<m_model->columnCount() ; ++i)
|
||||
{
|
||||
auto at_a = std::min(m_minimum_column_width.size()-1, i); //In case of the I is higher than m_minimum_column_width or
|
||||
auto at_b = std::min(m_header_item->minimumSectionWidth().size()-1, i); //m_header_item->minimumSectionWidth().size()
|
||||
m_header_item->resizeSection(i, std::max(m_minimum_column_width.at(at_a),
|
||||
m_header_item->minimumSectionWidth().at(at_b))+b);
|
||||
m_header_item->resizeSection(
|
||||
i,
|
||||
std::max(
|
||||
m_minimum_column_width.at(at_a),
|
||||
m_header_item->minimumSectionWidth().at(at_b))+b);
|
||||
sum_+= m_header_item->sectionSize(i);
|
||||
}
|
||||
|
||||
|
||||
//The sum of the header sections width can be less than width of @m_current_size we adjust it in order to have the same width
|
||||
//The sum of the header sections width can be less than width of
|
||||
// @m_current_size we adjust it in order to have the same width
|
||||
if (m_model->columnCount() > 0 &&
|
||||
sum_ < m_current_size.width())
|
||||
{
|
||||
//add the quotient of the division to each columns
|
||||
//add the quotient of the division to each columns
|
||||
auto result = (m_current_size.width()-sum_)/m_model->columnCount();
|
||||
for(auto i= 0 ; i<m_model->columnCount() ; ++i) {
|
||||
m_header_item->resizeSection(i, m_header_item->sectionSize(i) + result);
|
||||
m_header_item->resizeSection(
|
||||
i,
|
||||
m_header_item->sectionSize(i) + result);
|
||||
}
|
||||
|
||||
//add the rest of the division to the last column
|
||||
auto last_section = m_model->columnCount()-1;
|
||||
m_header_item->resizeSection(last_section, m_header_item->sectionSize(last_section) + ((m_current_size.width()-sum_)%m_model->columnCount()));
|
||||
m_header_item->resizeSection(
|
||||
last_section,
|
||||
m_header_item->sectionSize(last_section)
|
||||
+ ((m_current_size.width()-sum_)%m_model->columnCount()));
|
||||
}
|
||||
connect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized);
|
||||
connect(
|
||||
m_header_item,
|
||||
&QetGraphicsHeaderItem::sectionResized,
|
||||
this,
|
||||
&QetGraphicsTableItem::headerSectionResized);
|
||||
update();
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
void QetGraphicsTableItem::dataChanged(
|
||||
const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QVector<int> &roles)
|
||||
{
|
||||
Q_UNUSED(topLeft)
|
||||
Q_UNUSED(bottomRight)
|
||||
@ -947,7 +1071,8 @@ void QetGraphicsTableItem::adjustSize()
|
||||
}
|
||||
}
|
||||
|
||||
void QetGraphicsTableItem::previousTableDisplayRowChanged() {
|
||||
void QetGraphicsTableItem::previousTableDisplayRowChanged()
|
||||
{
|
||||
setToMinimumHeight();
|
||||
if (m_next_table) {
|
||||
m_next_table->previousTableDisplayRowChanged();
|
||||
|
@ -47,11 +47,13 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
Q_PROPERTY(int displayNRow READ displayNRow WRITE setDisplayNRow)
|
||||
|
||||
public :
|
||||
static void adjustTableToFolio(QetGraphicsTableItem *table, QMargins margins = QMargins(20,20,20,0));
|
||||
static void checkInsufficientRowsCount(QetGraphicsTableItem *first_table);
|
||||
static void adjustTableToFolio(
|
||||
QetGraphicsTableItem *table,
|
||||
QMargins margins = QMargins(20,20,20,0));
|
||||
static void checkInsufficientRowsCount(
|
||||
QetGraphicsTableItem *first_table);
|
||||
|
||||
public:
|
||||
QetGraphicsTableItem(QGraphicsItem *parent= nullptr);
|
||||
QetGraphicsTableItem(QGraphicsItem *parent= nullptr);
|
||||
virtual ~QetGraphicsTableItem() override;
|
||||
|
||||
enum { Type = UserType + 1300 };
|
||||
@ -61,8 +63,12 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
QAbstractItemModel *model() const;
|
||||
|
||||
virtual QRectF boundingRect() const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
QetGraphicsHeaderItem *headerItem() const {return m_header_item;}
|
||||
virtual void paint(
|
||||
QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget) override;
|
||||
QetGraphicsHeaderItem *headerItem() const
|
||||
{return m_header_item;}
|
||||
void setSize(const QSize &size);
|
||||
QSize size() const;
|
||||
QSize minimumSize() const;
|
||||
@ -83,16 +89,22 @@ 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);
|
||||
virtual bool toDXF (const QString &filepath);
|
||||
|
||||
protected:
|
||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
virtual void hoverEnterEvent(
|
||||
QGraphicsSceneHoverEvent *event) override;
|
||||
virtual void hoverLeaveEvent(
|
||||
QGraphicsSceneHoverEvent *event) override;
|
||||
virtual bool sceneEventFilter(
|
||||
QGraphicsItem *watched,
|
||||
QEvent *event) override;
|
||||
virtual QVariant itemChange(
|
||||
GraphicsItemChange change,
|
||||
const QVariant &value) override;
|
||||
|
||||
private:
|
||||
void modelReseted();
|
||||
private:
|
||||
void modelReseted();
|
||||
void setUpColumnAndRowMinimumSize();
|
||||
void setUpBoundingRect();
|
||||
void adjustHandlerPos();
|
||||
@ -101,33 +113,40 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
||||
void handlerMouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
||||
void handlerMouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
||||
void adjustColumnsWidth();
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
||||
void dataChanged(
|
||||
const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QVector<int> &roles);
|
||||
void headerSectionResized();
|
||||
void adjustSize();
|
||||
void previousTableDisplayRowChanged();
|
||||
|
||||
private:
|
||||
QAbstractItemModel *m_model= nullptr;
|
||||
QAbstractItemModel *m_model= nullptr;
|
||||
|
||||
QVector<int> m_minimum_column_width;
|
||||
int m_minimum_row_height;
|
||||
int m_number_of_displayed_row = 0;
|
||||
QSize m_current_size,
|
||||
m_old_size,
|
||||
m_pending_size;
|
||||
int
|
||||
m_minimum_row_height,
|
||||
m_number_of_displayed_row = 0,
|
||||
m_br_margin = 10;
|
||||
|
||||
QSize
|
||||
m_current_size,
|
||||
m_old_size,
|
||||
m_pending_size;
|
||||
|
||||
int m_br_margin= 10;
|
||||
QRectF m_bounding_rect;
|
||||
|
||||
QetGraphicsHandlerItem m_handler_item;
|
||||
QetGraphicsHeaderItem *m_header_item = nullptr;
|
||||
|
||||
QetGraphicsTableItem *m_previous_table = nullptr,
|
||||
*m_next_table = nullptr;
|
||||
QetGraphicsTableItem
|
||||
*m_previous_table = nullptr,
|
||||
*m_next_table = nullptr;
|
||||
|
||||
QString m_name;
|
||||
QUuid m_uuid = QUuid::createUuid(),
|
||||
m_pending_previous_table_uuid;
|
||||
QUuid
|
||||
m_uuid = QUuid::createUuid(),
|
||||
m_pending_previous_table_uuid;
|
||||
};
|
||||
|
||||
#endif // QetGraphicsTableItem_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user