19 #include <QTreeWidgetItem> 33 first_activation_(true)
36 setIconSize(QSize(50, 50));
49 QTreeWidgetItem *current_qtwi = currentItem();
50 if (!current_qtwi)
return(0);
51 return(current_qtwi -> type());
56 return(valueForItem<QETProject *>(item));
67 return(valueForItem<Diagram *>(item));
77 return(valueForItem<TitleBlockTemplateLocation>(item));
107 if (!project)
return(
nullptr);
108 bool creation_required;
112 reparent(project_qtwi, parent_item);
115 return(project_qtwi);
124 if (!project)
return(
nullptr);
125 return(
projects_.value(project,
nullptr));
137 if (!project)
return(
nullptr);
139 QTreeWidgetItem *project_qtwi =
projects_.value(project,
nullptr);
141 if (created) *created =
false;
142 return(project_qtwi);
146 if (created) *created =
true;
147 return(project_qtwi);
155 if (!project_qtwi || !project)
return(
nullptr);
157 if (freshly_created) {
166 project, SIGNAL(readOnlyChanged(
QETProject *,
bool)),
172 project_qtwi -> setText(0, project -> pathNameTitle());
174 QString final_tooltip = QDir::toNativeSeparators(project -> filePath());
175 if (final_tooltip.isEmpty()) {
178 "tooltip for a file-less project in the element panel" 181 project_qtwi -> setToolTip(0, final_tooltip);
182 QString project_whatsthis =
tr(
"Ceci est un projet QElectroTech, c'est-à-dire un fichier d'extension .qet regroupant plusieurs folios. Il embarque également les éléments et modèles de cartouches utilisés dans ces folios.",
"\"What's this\" tip");
183 project_qtwi -> setWhatsThis(0, project_whatsthis);
184 return(
updateItem(project_qtwi, options, freshly_created));
191 if (!project_qtwi || !project)
return(
nullptr);
195 if (freshly_created) {
213 foreach (
Diagram *diagram, project -> diagrams()) {
214 QTreeWidgetItem *diagram_qtwi =
addDiagram(diagram,
nullptr, options);
215 project_qtwi -> insertChild(index, diagram_qtwi);
221 if (freshly_created) {
228 project -> embeddedTitleBlockTemplatesCollection(),
234 return(
fillItem(project_qtwi, options, freshly_created));
242 if (!diagram)
return(
nullptr);
244 bool creation_required;
248 reparent(diagram_qtwi, parent_item);
251 return(diagram_qtwi);
258 if (!diagram)
return(
nullptr);
260 QTreeWidgetItem *diagram_qtwi =
diagrams_.value(diagram,
nullptr);
262 if (created) *created =
false;
263 return(diagram_qtwi);
267 if (created) *created =
true;
268 return(diagram_qtwi);
276 if (!diagram || !diagram_qtwi)
return(
nullptr);
279 QString displayed_title = diagram -> title();
280 if (displayed_title.isEmpty())
282 displayed_title =
tr(
"Folio sans titre",
"Fallback label when a diagram has no title");
285 if (settings.value(
"genericpanel/folio",
true).toBool())
288 int diagram_folio_idx = diagram -> folioIndex();
289 if (diagram_folio_idx != -1)
291 displayed_label = QString(
294 "label displayed for a diagram in the panel ; %1 is the folio index, %2 is the diagram title" 296 ).arg(displayed_label).arg(displayed_title);
297 diagram_qtwi -> setText(0, displayed_label);
303 QString displayed_label;
304 int diagram_folio_idx = diagram -> folioIndex();
305 if (diagram_folio_idx != -1)
307 displayed_label = QString(
310 "label displayed for a diagram in the panel ; %1 is the folio index, %2 is the diagram title" 312 ).arg(diagram_folio_idx + 1).arg(displayed_title);
315 diagram_qtwi -> setText(0, displayed_label);
326 return(
updateItem(diagram_qtwi, options, freshly_created));
337 Q_UNUSED(freshly_created)
338 return(
fillItem(diagram_qtwi, options, freshly_created));
345 if (!tbt_collection)
return(
nullptr);
346 bool creation_required;
350 reparent(tbt_collection_qtwi, parent_item);
353 return(tbt_collection_qtwi);
360 if (!tbt_collection)
return(
nullptr);
361 return(
tb_templates_.value(tbt_collection -> location(),
nullptr));
368 if (!tbt_collection)
return(
nullptr);
369 QTreeWidgetItem *tbt_collection_item =
tb_templates_.value(tbt_collection -> location(),
nullptr);
370 if (tbt_collection_item) {
371 if (created) *created =
false;
372 return(tbt_collection_item);
376 if (created) *created =
true;
377 return(tbt_collection_item);
385 QString label = tbt_collection -> title();
386 if (label.isEmpty()) label =
tr(
"Modèles de cartouche");
388 tbt_collection_qtwi -> setText(0, label);
389 tbt_collection_qtwi -> setToolTip(0, tbt_collection -> location().toString());
391 if (freshly_created) {
392 tbt_collection_qtwi -> setData(0,
GenericPanel::Item, qVariantFromValue(tbt_collection -> location()));
393 tb_templates_.insert(tbt_collection -> location(), tbt_collection_qtwi);
396 return(
updateItem(tbt_collection_qtwi, options, freshly_created));
403 if (!tbt_collection_qtwi || !tbt_collection)
return(tbt_collection_qtwi);
406 if (freshly_created) {
411 if (
QETProject *project = tbt_collection -> parentProject()) {
423 foreach (QString template_name, tbt_collection -> templates()) {
424 QTreeWidgetItem *template_item =
addTemplate(tbt_collection -> location(template_name),
nullptr, options);
425 tbt_collection_qtwi -> insertChild(index ++, template_item);
429 return(
fillItem(tbt_collection_qtwi, options, freshly_created));
436 if (!tb_template.
isValid())
return(
nullptr);
437 bool creation_required;
439 QTreeWidgetItem *tb_template_qtwi =
getItemForTemplate(tb_template, &creation_required);
441 reparent(tb_template_qtwi, parent_item);
442 fillTemplateItem(tb_template_qtwi, tb_template, options, creation_required);
444 return(tb_template_qtwi);
451 if (!tb_template.
isValid())
return(
nullptr);
453 QTreeWidgetItem *tb_template_qtwi =
tb_templates_.value(tb_template,
nullptr);
454 if (tb_template_qtwi) {
455 if (created) *created =
false;
456 return(tb_template_qtwi);
460 if (created) *created =
true;
461 return(tb_template_qtwi);
469 tb_template_qtwi -> setText(0,
tr(
"Modèle \"%1\"",
"used to display a title block template").arg(tb_template.
name()));
470 QString tbt_whatsthis =
tr(
471 "Ceci est un modèle de cartouche, qui peut être appliqué à un folio.",
472 "\"What's this\" tip" 474 tb_template_qtwi -> setWhatsThis(0, tbt_whatsthis);
476 tb_template_qtwi -> setToolTip(0, tb_template.
toString());
477 tb_template_qtwi -> setBackground(0, QBrush());
482 if (!tbt_project -> usesTitleBlockTemplate(tb_template)) {
487 if (freshly_created) {
491 return(
updateItem(tb_template_qtwi, options, freshly_created));
498 Q_UNUSED(tb_template)
500 Q_UNUSED(freshly_created)
501 return(
fillItem(tb_template_qtwi, options, freshly_created));
512 Q_UNUSED(freshly_created);
513 QApplication::processEvents();
525 Q_UNUSED(freshly_created);
565 if (!qtwi_project)
return;
568 QTreeWidgetItem *moved_qtwi_diagram = qtwi_project -> child(from);
569 if (!moved_qtwi_diagram)
return;
572 bool was_selected = moved_qtwi_diagram -> isSelected();
573 qtwi_project -> removeChild (moved_qtwi_diagram);
574 qtwi_project -> insertChild (to, moved_qtwi_diagram);
577 for (
int i = qMin(from, to); i < qMax(from, to) + 1; i++)
579 QTreeWidgetItem *qtwi_diagram = qtwi_project -> child(i);
580 if (!qtwi_diagram)
continue;
582 Diagram *diagram = valueForItem<Diagram *>(qtwi_diagram);
588 setCurrentItem(moved_qtwi_diagram);
607 Q_UNUSED(template_name)
637 default:
return(QString());
668 QTreeWidgetItem *qtwi =
new QTreeWidgetItem(parent, type);
669 qtwi -> setText(0, label.isEmpty() ?
defaultText(type) : label);
670 qtwi -> setIcon(0, icon.isNull() ?
defaultIcon(type) : icon);
681 Q_UNUSED(deleted_on_cascade)
683 for (
int i = item -> childCount() - 1 ; i >= 0 ; -- i) {
697 QLinearGradient t(0, 0, 200, 0);
698 t.setColorAt(0, QColor(
"#ffc0c0"));
699 t.setColorAt(1, QColor(
"#ffffff"));
700 qtwi -> setBackground(0, QBrush(t));
701 qtwi -> setToolTip(0, QString(
tr(
"%1 [non utilisé dans le projet]")).arg(qtwi -> toolTip(0)));
708 if (parent && item -> parent() != parent) {
709 parent -> addChild(item);
720 QList<QTreeWidgetItem *> items;
721 if (!item)
return(items);
722 for (
int i = 0 ; i < item -> childCount() ; ++ i) {
723 QTreeWidgetItem *current_item = item -> child(i);
724 if (!current_item)
continue;
725 if (current_item -> type() == type) {
726 items << current_item;
729 items <<
childItems(current_item, type,
true);
747 foreach (QTreeWidgetItem *child_item,
childItems(item, type, recursive)) {
748 T child_value = valueForItem<T>(child_item);
749 if (!expected_items.contains(child_value)) {
776 int type = item ->type();
778 tb_templates_.remove(valueForItem<TitleBlockTemplateLocation>(item));
780 diagrams_.remove(valueForItem<Diagram *>(item));
782 projects_.remove(valueForItem<QETProject *>(item));
792 if (
event -> type() == QEvent::WindowActivate ||
event -> type() == QEvent::Show) {
797 return(QTreeWidget::event(
event));
virtual QTreeWidgetItem * fillTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions=AddAllChild, bool=false)
virtual void templatesCollectionChanged(TitleBlockTemplatesCollection *, const QString &)
void panelContentChanged()
virtual QTreeWidgetItem * updateProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions=AddAllChild, bool=false)
virtual QTreeWidgetItem * addProject(QETProject *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
virtual QTreeWidgetItem * itemForProject(QETProject *)
virtual void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &)
virtual void projectInformationsChanged(QETProject *)
GenericPanel(QWidget *=nullptr)
void emitFirstActivated()
virtual int currentItemType()
virtual TitleBlockTemplateLocation templateLocationForItem(QTreeWidgetItem *) const
virtual QTreeWidgetItem * fillProjectItem(QTreeWidgetItem *, QETProject *, PanelOptions=AddAllChild, bool=false)
virtual QTreeWidgetItem * updateTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions=AddAllChild, bool=false)
virtual void deleteItem(QTreeWidgetItem *, bool=false)
virtual QTreeWidgetItem * addTemplate(const TitleBlockTemplateLocation &, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
virtual void diagramAdded(QETProject *, Diagram *)
virtual QTreeWidgetItem * fillDiagramItem(QTreeWidgetItem *, Diagram *, PanelOptions=AddAllChild, bool=false)
QString finalfolio() const
QHash< QETProject *, QTreeWidgetItem * > projects_
Allow quick retrieval of the item representing a given project.
virtual QTreeWidgetItem * getItemForTemplatesCollection(TitleBlockTemplatesCollection *, bool *=nullptr)
virtual QIcon defaultIcon(QET::ItemType)
virtual TitleBlockTemplateLocation selectedTemplateLocation() const
virtual QTreeWidgetItem * getItemForProject(QETProject *, bool *=nullptr)
virtual void diagramTitleChanged(Diagram *, const QString &)
bool first_activation_
boolean used to track the first time this widget is activated/shown
virtual QTreeWidgetItem * addTemplatesCollection(TitleBlockTemplatesCollection *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
virtual QString defaultText(QET::ItemType)
bool event(QEvent *) override
virtual QTreeWidgetItem * makeItem(QET::ItemType, QTreeWidgetItem *=nullptr, const QString &=QString(), const QIcon &=QIcon())
virtual QETProject * projectForItem(QTreeWidgetItem *) const
QList< QTreeWidgetItem * > childItems(QTreeWidgetItem *, QET::ItemType, bool=false) const
virtual QTreeWidgetItem * getItemForDiagram(Diagram *, bool *=nullptr)
virtual Diagram * diagramForItem(QTreeWidgetItem *) const
virtual QTreeWidgetItem * updateTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions=AddAllChild, bool=false)
virtual void reparent(QTreeWidgetItem *, QTreeWidgetItem *)
virtual QTreeWidgetItem * updateDiagramItem(QTreeWidgetItem *, Diagram *, PanelOptions=AddAllChild, bool=false)
virtual QTreeWidgetItem * addDiagram(Diagram *, QTreeWidgetItem *=nullptr, PanelOptions=AddAllChild)
virtual void diagramRemoved(QETProject *, Diagram *)
QHash< TitleBlockTemplateLocation, QTreeWidgetItem * > tb_templates_
Allow quick retrieval of the item representing a title block template.
virtual QTreeWidgetItem * updateItem(QTreeWidgetItem *, PanelOptions=AddAllChild, bool=false)
virtual Diagram * selectedDiagram() const
virtual void projectDiagramsOrderChanged(QETProject *, int, int)
GenericPanel::projectDiagramsOrderChanged.
QETProject * parentProject() const
QHash< Diagram *, QTreeWidgetItem * > diagrams_
Allow quick retrieval of the item representing a given diagram.
virtual QTreeWidgetItem * fillItem(QTreeWidgetItem *, PanelOptions=AddAllChild, bool=false)
void diagramTitleChanged(Diagram *, const QString &)
virtual QTreeWidgetItem * getItemForTemplate(const TitleBlockTemplateLocation &, bool *=nullptr)
virtual QTreeWidgetItem * fillTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions=AddAllChild, bool=false)
virtual void markItemAsUnused(QTreeWidgetItem *)
T valueForItem(QTreeWidgetItem *) const
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
void removeObsoleteItems(const QList< T > &, QTreeWidgetItem *, QET::ItemType, bool)
virtual QTreeWidgetItem * itemForTemplatesCollection(TitleBlockTemplatesCollection *)
void unregisterItem(QTreeWidgetItem *)
virtual QETProject * selectedProject() const