mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 17:50:52 +01:00
Add nomenclature dialog : enable option "add new folio and table if needed"
This commit is contained in:
@@ -44,39 +44,76 @@ void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram)
|
||||
|
||||
if (d->exec())
|
||||
{
|
||||
auto model = new NomenclatureModel(diagram->project(), diagram->project());
|
||||
model->query(d->queryStr());
|
||||
model->autoHeaders();
|
||||
model->setData(model->index(0,0), int(d->tableAlignment()), Qt::TextAlignmentRole);
|
||||
model->setData(model->index(0,0), d->tableFont(), Qt::FontRole);
|
||||
model->setData(model->index(0,0), QETUtils::marginsToString(d->headerMargins()), Qt::UserRole+1);
|
||||
model->setHeaderData(0, Qt::Horizontal, int(d->headerAlignment()), Qt::TextAlignmentRole);
|
||||
model->setHeaderData(0, Qt::Horizontal, d->headerFont(), Qt::FontRole);
|
||||
model->setHeaderData(0, Qt::Horizontal, QETUtils::marginsToString(d->headerMargins()), Qt::UserRole+1);
|
||||
|
||||
auto table = new QetGraphicsTableItem();
|
||||
table->setTableName(d->tableName());
|
||||
table->setModel(model);
|
||||
diagram->addItem(table);
|
||||
table->setPos(50,50);
|
||||
auto table_ = newTable(diagram, d.data());
|
||||
if (d->adjustTableToFolio()) {
|
||||
AdjustTableToFolio(table_);
|
||||
}
|
||||
|
||||
|
||||
if (d->adjustTableToFolio())
|
||||
if (d->addNewTableToNewDiagram() && table_->model()->rowCount() > table_->displayNRow())
|
||||
{
|
||||
auto drawable_rect = diagram->border_and_titleblock.insideBorderRect();
|
||||
table->setPos(drawable_rect.topLeft().x() + 20, drawable_rect.topLeft().y() + 20 + table->headerItem()->rect().height());
|
||||
auto already_displayed_rows = table_->displayNRow();
|
||||
auto project_ = diagram->project();
|
||||
auto actual_diagram = diagram;
|
||||
auto previous_table = table_;
|
||||
|
||||
auto size_ = table->size();
|
||||
size_.setWidth(int(drawable_rect.width() - 40));
|
||||
//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
|
||||
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
|
||||
int i = 2;
|
||||
while (already_displayed_rows < table_->model()->rowCount())
|
||||
{
|
||||
//Add a new diagram after the current one
|
||||
actual_diagram = project_->addNewDiagram(project_->folioIndex(actual_diagram)+1);
|
||||
table_ = newTable(actual_diagram, d.data());
|
||||
table_->setTableName(d->tableName() + QString(" %1").arg(i));
|
||||
//Set the previous folio of table
|
||||
table_->setPreviousTable(previous_table);
|
||||
//Adjust table
|
||||
if (d->adjustTableToFolio()) {
|
||||
AdjustTableToFolio(table_);
|
||||
}
|
||||
//Update some variable for the next loop
|
||||
already_displayed_rows += table_->displayNRow();
|
||||
previous_table = table_;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QetGraphicsTableItem *QetGraphicsTableFactory::newTable(Diagram *diagram, AddTableDialog *dialog)
|
||||
{
|
||||
auto model = new NomenclatureModel(diagram->project(), diagram->project());
|
||||
model->query(dialog->queryStr());
|
||||
model->autoHeaders();
|
||||
model->setData(model->index(0,0), int(dialog->tableAlignment()), Qt::TextAlignmentRole);
|
||||
model->setData(model->index(0,0), dialog->tableFont(), Qt::FontRole);
|
||||
model->setData(model->index(0,0), QETUtils::marginsToString(dialog->headerMargins()), Qt::UserRole+1);
|
||||
model->setHeaderData(0, Qt::Horizontal, int(dialog->headerAlignment()), Qt::TextAlignmentRole);
|
||||
model->setHeaderData(0, Qt::Horizontal, dialog->headerFont(), Qt::FontRole);
|
||||
model->setHeaderData(0, Qt::Horizontal, QETUtils::marginsToString(dialog->headerMargins()), Qt::UserRole+1);
|
||||
|
||||
auto table = new QetGraphicsTableItem();
|
||||
table->setTableName(dialog->tableName());
|
||||
table->setModel(model);
|
||||
diagram->addItem(table);
|
||||
table->setPos(50,50);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
void QetGraphicsTableFactory::AdjustTableToFolio(QetGraphicsTableItem *table)
|
||||
{
|
||||
auto drawable_rect = table->diagram()->border_and_titleblock.insideBorderRect();
|
||||
table->setPos(drawable_rect.topLeft().x() + 20, drawable_rect.topLeft().y() + 20 + table->headerItem()->rect().height());
|
||||
|
||||
auto size_ = table->size();
|
||||
size_.setWidth(int(drawable_rect.width() - 40));
|
||||
//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
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user