mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-03 19:10:53 +01:00
Reduce the time spend when nomenclature table is created automatically
This commit is contained in:
@@ -64,10 +64,8 @@ void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram)
|
|||||||
{
|
{
|
||||||
//Add a new diagram after the current one
|
//Add a new diagram after the current one
|
||||||
actual_diagram = project_->addNewDiagram(project_->folioIndex(actual_diagram)+1);
|
actual_diagram = project_->addNewDiagram(project_->folioIndex(actual_diagram)+1);
|
||||||
table_ = newTable(actual_diagram, d.data());
|
table_ = newTable(actual_diagram, d.data(), previous_table);
|
||||||
table_->setTableName(d->tableName() + QString(" %1").arg(table_number));
|
table_->setTableName(d->tableName() + QString(" %1").arg(table_number));
|
||||||
//Set the previous folio of table
|
|
||||||
table_->setPreviousTable(previous_table);
|
|
||||||
//Adjust table
|
//Adjust table
|
||||||
if (d->adjustTableToFolio()) {
|
if (d->adjustTableToFolio()) {
|
||||||
AdjustTableToFolio(table_);
|
AdjustTableToFolio(table_);
|
||||||
@@ -81,27 +79,48 @@ void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QetGraphicsTableItem *QetGraphicsTableFactory::newTable(Diagram *diagram, AddTableDialog *dialog)
|
/**
|
||||||
|
* @brief QetGraphicsTableFactory::newTable
|
||||||
|
* Create a new table .
|
||||||
|
* @param diagram : Diagram where we must add the new table.
|
||||||
|
* @param dialog : dialog conf, it's used to setup the model.
|
||||||
|
* @param previous_table : If you know that the new table will have a previous table and you already now the previous table,
|
||||||
|
* set it now they will improve time needed for creating the new table by avoiding to create a new model.
|
||||||
|
* @return the new table
|
||||||
|
*/
|
||||||
|
QetGraphicsTableItem *QetGraphicsTableFactory::newTable(Diagram *diagram, AddTableDialog *dialog, QetGraphicsTableItem *previous_table)
|
||||||
{
|
{
|
||||||
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();
|
auto table = new QetGraphicsTableItem();
|
||||||
table->setTableName(dialog->tableName());
|
table->setTableName(dialog->tableName());
|
||||||
table->setModel(model);
|
|
||||||
|
if (!previous_table)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
table->setModel(model);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
table->setPreviousTable(previous_table);
|
||||||
|
}
|
||||||
|
|
||||||
diagram->addItem(table);
|
diagram->addItem(table);
|
||||||
table->setPos(50,50);
|
table->setPos(50,50);
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief QetGraphicsTableFactory::AdjustTableToFolio
|
||||||
|
* Adjust @table to fit as better as possible to it's parent diagram.
|
||||||
|
* @param table
|
||||||
|
*/
|
||||||
void QetGraphicsTableFactory::AdjustTableToFolio(QetGraphicsTableItem *table)
|
void QetGraphicsTableFactory::AdjustTableToFolio(QetGraphicsTableItem *table)
|
||||||
{
|
{
|
||||||
auto drawable_rect = table->diagram()->border_and_titleblock.insideBorderRect();
|
auto drawable_rect = table->diagram()->border_and_titleblock.insideBorderRect();
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class QetGraphicsTableFactory
|
|||||||
|
|
||||||
static void createAndAddNomenclature(Diagram *diagram);
|
static void createAndAddNomenclature(Diagram *diagram);
|
||||||
private:
|
private:
|
||||||
static QetGraphicsTableItem *newTable(Diagram *diagram, AddTableDialog *dialog);
|
static QetGraphicsTableItem *newTable(Diagram *diagram, AddTableDialog *dialog, QetGraphicsTableItem *previous_table = nullptr);
|
||||||
static void AdjustTableToFolio(QetGraphicsTableItem *table);
|
static void AdjustTableToFolio(QetGraphicsTableItem *table);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user