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:
@@ -43,27 +43,66 @@ void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram)
|
|||||||
d->setWindowTitle(QObject::tr("Ajouter une nomenclature"));
|
d->setWindowTitle(QObject::tr("Ajouter une nomenclature"));
|
||||||
|
|
||||||
if (d->exec())
|
if (d->exec())
|
||||||
|
{
|
||||||
|
auto table_ = newTable(diagram, d.data());
|
||||||
|
if (d->adjustTableToFolio()) {
|
||||||
|
AdjustTableToFolio(table_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (d->addNewTableToNewDiagram() && table_->model()->rowCount() > table_->displayNRow())
|
||||||
|
{
|
||||||
|
auto already_displayed_rows = table_->displayNRow();
|
||||||
|
auto project_ = diagram->project();
|
||||||
|
auto actual_diagram = diagram;
|
||||||
|
auto previous_table = table_;
|
||||||
|
|
||||||
|
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());
|
auto model = new NomenclatureModel(diagram->project(), diagram->project());
|
||||||
model->query(d->queryStr());
|
model->query(dialog->queryStr());
|
||||||
model->autoHeaders();
|
model->autoHeaders();
|
||||||
model->setData(model->index(0,0), int(d->tableAlignment()), Qt::TextAlignmentRole);
|
model->setData(model->index(0,0), int(dialog->tableAlignment()), Qt::TextAlignmentRole);
|
||||||
model->setData(model->index(0,0), d->tableFont(), Qt::FontRole);
|
model->setData(model->index(0,0), dialog->tableFont(), Qt::FontRole);
|
||||||
model->setData(model->index(0,0), QETUtils::marginsToString(d->headerMargins()), Qt::UserRole+1);
|
model->setData(model->index(0,0), QETUtils::marginsToString(dialog->headerMargins()), Qt::UserRole+1);
|
||||||
model->setHeaderData(0, Qt::Horizontal, int(d->headerAlignment()), Qt::TextAlignmentRole);
|
model->setHeaderData(0, Qt::Horizontal, int(dialog->headerAlignment()), Qt::TextAlignmentRole);
|
||||||
model->setHeaderData(0, Qt::Horizontal, d->headerFont(), Qt::FontRole);
|
model->setHeaderData(0, Qt::Horizontal, dialog->headerFont(), Qt::FontRole);
|
||||||
model->setHeaderData(0, Qt::Horizontal, QETUtils::marginsToString(d->headerMargins()), Qt::UserRole+1);
|
model->setHeaderData(0, Qt::Horizontal, QETUtils::marginsToString(dialog->headerMargins()), Qt::UserRole+1);
|
||||||
|
|
||||||
auto table = new QetGraphicsTableItem();
|
auto table = new QetGraphicsTableItem();
|
||||||
table->setTableName(d->tableName());
|
table->setTableName(dialog->tableName());
|
||||||
table->setModel(model);
|
table->setModel(model);
|
||||||
diagram->addItem(table);
|
diagram->addItem(table);
|
||||||
table->setPos(50,50);
|
table->setPos(50,50);
|
||||||
|
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
if (d->adjustTableToFolio())
|
void QetGraphicsTableFactory::AdjustTableToFolio(QetGraphicsTableItem *table)
|
||||||
{
|
{
|
||||||
auto drawable_rect = diagram->border_and_titleblock.insideBorderRect();
|
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());
|
table->setPos(drawable_rect.topLeft().x() + 20, drawable_rect.topLeft().y() + 20 + table->headerItem()->rect().height());
|
||||||
|
|
||||||
auto size_ = table->size();
|
auto size_ = table->size();
|
||||||
@@ -78,5 +117,3 @@ void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram)
|
|||||||
auto min_row_height = table->minimumRowHeigth();
|
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
|
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
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#define QETGRAPHICSTABLEFACTORY_H
|
#define QETGRAPHICSTABLEFACTORY_H
|
||||||
|
|
||||||
class Diagram;
|
class Diagram;
|
||||||
|
class QetGraphicsTableItem;
|
||||||
|
class AddTableDialog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The QetGraphicsTableFactory class
|
* @brief The QetGraphicsTableFactory class
|
||||||
@@ -29,6 +31,9 @@ class QetGraphicsTableFactory
|
|||||||
QetGraphicsTableFactory();
|
QetGraphicsTableFactory();
|
||||||
|
|
||||||
static void createAndAddNomenclature(Diagram *diagram);
|
static void createAndAddNomenclature(Diagram *diagram);
|
||||||
|
private:
|
||||||
|
static QetGraphicsTableItem *newTable(Diagram *diagram, AddTableDialog *dialog);
|
||||||
|
static void AdjustTableToFolio(QetGraphicsTableItem *table);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QETGRAPHICSTABLEFACTORY_H
|
#endif // QETGRAPHICSTABLEFACTORY_H
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="m_add_table_and_folio">
|
<widget class="QCheckBox" name="m_add_table_and_folio">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Ajouter de nouveau folio et tableau si nécessaire.</string>
|
<string>Ajouter de nouveau folio et tableau si nécessaire.</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user