Minor fix : QetGraphicsTableItem keep his size when model is reseted or when open from xml.

This commit is contained in:
Claveau Joshua
2020-10-10 11:18:21 +02:00
parent 5d47ecd8f6
commit b45c6b453e
3 changed files with 15 additions and 69 deletions

View File

@@ -1,4 +1,4 @@
/*
/*
Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech.
@@ -435,25 +435,11 @@ void QetGraphicsHeaderItem::adjustSize()
emit heightResized();
}
if(m_current_sections_width.size() == m_sections_minimum_width.size())
{
auto old_sections_width = m_current_sections_width;
for (int i=0 ; i<m_current_sections_width.size() ; ++i)
{
if (old_sections_width.at(i) < m_sections_minimum_width.at(i)) {
resizeSection(i, m_sections_minimum_width.at(i));
}
}
}
update();
}
void QetGraphicsHeaderItem::modelReseted()
{
setUpMinimumSectionsSize();
m_current_sections_width.clear();
m_current_sections_width.resize(m_sections_minimum_width.size());
adjustSize();
}

View File

@@ -145,8 +145,6 @@ QetGraphicsTableItem::QetGraphicsTableItem(QGraphicsItem *parent) :
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]()
{
@@ -897,12 +895,6 @@ void QetGraphicsTableItem::handlerMousePressEvent(
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);
}
void QetGraphicsTableItem::handlerMouseMoveEvent(
@@ -933,12 +925,6 @@ void QetGraphicsTableItem::handlerMouseReleaseEvent(
undo->setText(tr("Modifier la géometrie d'un tableau"));
diagram()->undoStack().push(undo);
}
//User finish to resize the table, we can reconnect now
connect(
m_header_item,
&QetGraphicsHeaderItem::sectionResized,
this,
&QetGraphicsTableItem::headerSectionResized);
}
/**
@@ -960,13 +946,6 @@ void QetGraphicsTableItem::adjustColumnsWidth()
auto a = m_current_size.width() - minimumSize().width();
auto b = a/std::max(1,m_model->columnCount()); //avoid divide by 0
//Avoid to resize
disconnect(
m_header_item,
&QetGraphicsHeaderItem::sectionResized,
this,
&QetGraphicsTableItem::headerSectionResized);
int sum_=0;
for(auto i= 0 ; i<m_model->columnCount() ; ++i)
{
@@ -1008,11 +987,7 @@ void QetGraphicsTableItem::adjustColumnsWidth()
m_header_item->sectionSize(last_section)
+ ((m_current_size.width()-sum_)%m_model->columnCount()));
}
connect(
m_header_item,
&QetGraphicsHeaderItem::sectionResized,
this,
&QetGraphicsTableItem::headerSectionResized);
update();
}
@@ -1030,21 +1005,6 @@ void QetGraphicsTableItem::dataChanged(
update();
}
/**
@brief QetGraphicsTableItem::headerSectionResized
Connected to the header signal QetGraphicsTableItem sectionResized
*/
void QetGraphicsTableItem::headerSectionResized()
{
auto header_size = m_header_item->rect().size();
auto size_ = size();
size_.setWidth(header_size.width());
m_current_size = size_;
prepareGeometryChange();
setUpBoundingRect();
}
/**
@brief QetGraphicsTableItem::adjustSize
If needed, this function resize the current height and width of table and/or the size of columns.