mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Remove table useless qetgraphicstableitem when model is reseted
When the model of a qetgraphicstableitem is reseted (for exemple when the sql query is modified) we check if there is useless tables (table with 0 row displayed) and remove it.
This commit is contained in:
@@ -280,8 +280,8 @@ void QetGraphicsTableItem::paint(
|
|||||||
if (m_previous_table) //Remove the number of row already displayed by previous tables
|
if (m_previous_table) //Remove the number of row already displayed by previous tables
|
||||||
row_count -= m_previous_table->displayNRowOffset();
|
row_count -= m_previous_table->displayNRowOffset();
|
||||||
|
|
||||||
if (m_number_of_displayed_row > 0) //User override the number of row to display
|
if (m_number_of_row_to_display > 0) //User override the number of row to display
|
||||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
row_count = std::min(row_count, m_number_of_row_to_display);
|
||||||
|
|
||||||
//Draw horizontal lines
|
//Draw horizontal lines
|
||||||
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(row_count);
|
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(row_count);
|
||||||
@@ -374,8 +374,8 @@ QSize QetGraphicsTableItem::minimumSize() const
|
|||||||
row_count -= m_previous_table->displayNRowOffset();
|
row_count -= m_previous_table->displayNRowOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_number_of_displayed_row > 0)
|
if (m_number_of_row_to_display > 0)
|
||||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
row_count = std::min(row_count, m_number_of_row_to_display);
|
||||||
|
|
||||||
|
|
||||||
//m_minimum_column_width already take in count the minimum size of header
|
//m_minimum_column_width already take in count the minimum size of header
|
||||||
@@ -399,7 +399,7 @@ QSize QetGraphicsTableItem::minimumSize() const
|
|||||||
*/
|
*/
|
||||||
void QetGraphicsTableItem::setDisplayNRow(const int &number)
|
void QetGraphicsTableItem::setDisplayNRow(const int &number)
|
||||||
{
|
{
|
||||||
m_number_of_displayed_row = number;
|
m_number_of_row_to_display = number;
|
||||||
setToMinimumHeight();
|
setToMinimumHeight();
|
||||||
if (m_next_table)
|
if (m_next_table)
|
||||||
m_next_table->previousTableDisplayRowChanged();
|
m_next_table->previousTableDisplayRowChanged();
|
||||||
@@ -412,7 +412,7 @@ void QetGraphicsTableItem::setDisplayNRow(const int &number)
|
|||||||
*/
|
*/
|
||||||
int QetGraphicsTableItem::displayNRow() const
|
int QetGraphicsTableItem::displayNRow() const
|
||||||
{
|
{
|
||||||
return m_number_of_displayed_row;
|
return m_number_of_row_to_display;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -499,13 +499,31 @@ QString QetGraphicsTableItem::tableName() const
|
|||||||
*/
|
*/
|
||||||
int QetGraphicsTableItem::displayNRowOffset() const
|
int QetGraphicsTableItem::displayNRowOffset() const
|
||||||
{
|
{
|
||||||
auto offset_ = m_number_of_displayed_row;
|
auto offset_ = m_number_of_row_to_display;
|
||||||
if(m_previous_table)
|
if(m_previous_table)
|
||||||
offset_ += m_previous_table->displayNRowOffset();
|
offset_ += m_previous_table->displayNRowOffset();
|
||||||
|
|
||||||
return offset_;
|
return offset_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief QetGraphicsTableItem::displayedRowCount
|
||||||
|
* @return the number of row displayed by this table
|
||||||
|
*/
|
||||||
|
int QetGraphicsTableItem::displayedRowCount() const
|
||||||
|
{
|
||||||
|
//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
|
||||||
|
row_count -= m_previous_table->displayNRowOffset();
|
||||||
|
|
||||||
|
if (m_number_of_row_to_display > 0) //User override the number of row to display
|
||||||
|
row_count = std::min(row_count, m_number_of_row_to_display);
|
||||||
|
|
||||||
|
return row_count;
|
||||||
|
}
|
||||||
|
|
||||||
QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const
|
QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const
|
||||||
{
|
{
|
||||||
return m_previous_table;
|
return m_previous_table;
|
||||||
@@ -565,7 +583,7 @@ QDomElement QetGraphicsTableItem::toXml(QDomDocument &dom_document) const
|
|||||||
dom_table.setAttribute("height", QString::number(m_current_size.height()));
|
dom_table.setAttribute("height", QString::number(m_current_size.height()));
|
||||||
dom_table.setAttribute("uuid", m_uuid.toString());
|
dom_table.setAttribute("uuid", m_uuid.toString());
|
||||||
dom_table.setAttribute("name", m_name);
|
dom_table.setAttribute("name", m_name);
|
||||||
dom_table.setAttribute("display_n_row", QString::number(m_number_of_displayed_row));
|
dom_table.setAttribute("display_n_row", QString::number(m_number_of_row_to_display));
|
||||||
|
|
||||||
//Add the header xml
|
//Add the header xml
|
||||||
dom_table.appendChild(m_header_item->toXml(dom_document));
|
dom_table.appendChild(m_header_item->toXml(dom_document));
|
||||||
@@ -623,7 +641,7 @@ void QetGraphicsTableItem::fromXml(const QDomElement &dom_element)
|
|||||||
"uuid",
|
"uuid",
|
||||||
QUuid::createUuid().toString()));
|
QUuid::createUuid().toString()));
|
||||||
m_name = dom_element.attribute("name");
|
m_name = dom_element.attribute("name");
|
||||||
m_number_of_displayed_row = dom_element.attribute(
|
m_number_of_row_to_display = dom_element.attribute(
|
||||||
"display_n_row",
|
"display_n_row",
|
||||||
QString::number(0)).toInt();
|
QString::number(0)).toInt();
|
||||||
|
|
||||||
@@ -688,8 +706,8 @@ bool QetGraphicsTableItem::toDXF(const QString &filepath)
|
|||||||
if (m_previous_table) //Remove the number of row already displayed by previous tables
|
if (m_previous_table) //Remove the number of row already displayed by previous tables
|
||||||
row_count -= m_previous_table->displayNRowOffset();
|
row_count -= m_previous_table->displayNRowOffset();
|
||||||
|
|
||||||
if (m_number_of_displayed_row > 0) //User override the number of row to display
|
if (m_number_of_row_to_display > 0) //User override the number of row to display
|
||||||
row_count = std::min(row_count, m_number_of_displayed_row);
|
row_count = std::min(row_count, m_number_of_row_to_display);
|
||||||
|
|
||||||
//Draw horizontal lines
|
//Draw horizontal lines
|
||||||
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(row_count);
|
auto cell_height = static_cast<double>(m_current_size.height())/static_cast<double>(row_count);
|
||||||
@@ -816,13 +834,18 @@ QVariant QetGraphicsTableItem::itemChange(
|
|||||||
return QetGraphicsItem::itemChange(change, value);
|
return QetGraphicsItem::itemChange(change, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief QetGraphicsTableItem::modelReseted
|
||||||
|
*/
|
||||||
void QetGraphicsTableItem::modelReseted()
|
void QetGraphicsTableItem::modelReseted()
|
||||||
{
|
{
|
||||||
dataChanged(m_model->index(0,0), m_model->index(0,0), QVector<int>());
|
dataChanged(m_model->index(0,0), m_model->index(0,0), QVector<int>());
|
||||||
setToMinimumHeight();
|
setToMinimumHeight();
|
||||||
|
|
||||||
if (!previousTable()) { //this is the head table
|
if (!previousTable()) //this is the head table
|
||||||
|
{
|
||||||
checkInsufficientRowsCount(this);
|
checkInsufficientRowsCount(this);
|
||||||
|
removeUselessNextTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1056,3 +1079,24 @@ void QetGraphicsTableItem::previousTableDisplayRowChanged()
|
|||||||
m_next_table->previousTableDisplayRowChanged();
|
m_next_table->previousTableDisplayRowChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief QetGraphicsTableItem::removeUselessNextTable
|
||||||
|
* Remove next table if useless, an useless table with 0 row displayed.
|
||||||
|
* If \p recursive is true check and remove for all sub next table.
|
||||||
|
* @param recursive
|
||||||
|
*/
|
||||||
|
void QetGraphicsTableItem::removeUselessNextTable(bool recursive)
|
||||||
|
{
|
||||||
|
if (!m_next_table) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recursive) {
|
||||||
|
m_next_table->removeUselessNextTable();
|
||||||
|
}
|
||||||
|
if (m_next_table->displayedRowCount() <= 0) {
|
||||||
|
delete m_next_table;
|
||||||
|
m_next_table = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
|||||||
void setTableName(const QString &name);
|
void setTableName(const QString &name);
|
||||||
QString tableName() const;
|
QString tableName() const;
|
||||||
int displayNRowOffset() const;
|
int displayNRowOffset() const;
|
||||||
|
int displayedRowCount() const;
|
||||||
QetGraphicsTableItem *previousTable() const;
|
QetGraphicsTableItem *previousTable() const;
|
||||||
QetGraphicsTableItem *nextTable() const;
|
QetGraphicsTableItem *nextTable() const;
|
||||||
void setToMinimumHeight();
|
void setToMinimumHeight();
|
||||||
@@ -120,13 +121,14 @@ class QetGraphicsTableItem : public QetGraphicsItem
|
|||||||
void headerSectionResized();
|
void headerSectionResized();
|
||||||
void adjustSize();
|
void adjustSize();
|
||||||
void previousTableDisplayRowChanged();
|
void previousTableDisplayRowChanged();
|
||||||
|
void removeUselessNextTable(bool recursive = true);
|
||||||
|
|
||||||
QAbstractItemModel *m_model= nullptr;
|
QAbstractItemModel *m_model= nullptr;
|
||||||
|
|
||||||
QVector<int> m_minimum_column_width;
|
QVector<int> m_minimum_column_width;
|
||||||
int
|
int
|
||||||
m_minimum_row_height,
|
m_minimum_row_height,
|
||||||
m_number_of_displayed_row = 0,
|
m_number_of_row_to_display = 0,
|
||||||
m_br_margin = 10;
|
m_br_margin = 10;
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
|
|||||||
Reference in New Issue
Block a user