Add variable %F in the widget used to link master element.

Revamp the widget : replace QListWidget by QTreeWidget


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4867 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-01-22 13:48:58 +00:00
parent 7e284311a6
commit f97b9bcc84
3 changed files with 309 additions and 108 deletions

View File

@@ -37,8 +37,34 @@ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
m_project(nullptr) m_project(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
connect(ui->free_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
connect(ui->linked_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*))); ui->m_free_tree_widget->setContextMenuPolicy(Qt::CustomContextMenu);
ui->m_link_tree_widget->setContextMenuPolicy(Qt::CustomContextMenu);
m_context_menu = new QMenu(this);
m_link_action = new QAction(tr("Lier l'élément"), this);
m_unlink_action = new QAction(tr("Délier l'élément"), this);
m_show_qtwi = new QAction(tr("Montrer l'élément"), this);
m_show_element = new QAction(tr("Montrer l'élément maître"), this);
connect(ui->m_free_tree_widget, &QTreeWidget::itemDoubleClicked, this, &MasterPropertiesWidget::showElementFromTWI);
connect(ui->m_link_tree_widget, &QTreeWidget::itemDoubleClicked, this, &MasterPropertiesWidget::showElementFromTWI);
connect(ui->m_free_tree_widget, &QTreeWidget::customContextMenuRequested, [this](QPoint point) {this->customContextMenu(point, 1);});
connect(ui->m_link_tree_widget, &QTreeWidget::customContextMenuRequested, [this](QPoint point) {this->customContextMenu(point, 2);});
connect(m_link_action, &QAction::triggered, this, &MasterPropertiesWidget::on_link_button_clicked);
connect(m_unlink_action, &QAction::triggered, this, &MasterPropertiesWidget::on_unlink_button_clicked);
connect(m_show_qtwi, &QAction::triggered, [this]() {this->showElementFromTWI(this->m_qtwi_at_context_menu,0);});
connect(m_show_element, &QAction::triggered, [this]()
{
this->m_element->diagram()->showMe();
this->m_element->setHighlighted(true);
if(this->m_showed_element)
m_showed_element->setHighlighted(false);
});
setElement(elmt); setElement(elmt);
} }
@@ -48,7 +74,11 @@ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
*/ */
MasterPropertiesWidget::~MasterPropertiesWidget() MasterPropertiesWidget::~MasterPropertiesWidget()
{ {
if (m_showed_element) m_showed_element->setHighlighted(false); if (m_showed_element)
m_showed_element->setHighlighted(false);
m_element->setHighlighted(false);
delete ui; delete ui;
} }
@@ -59,19 +89,32 @@ MasterPropertiesWidget::~MasterPropertiesWidget()
*/ */
void MasterPropertiesWidget::setElement(Element *element) void MasterPropertiesWidget::setElement(Element *element)
{ {
if (m_element == element) return; if (m_element == element)
if (m_showed_element) {m_showed_element->setHighlighted(false); m_showed_element = nullptr;} return;
if (m_project) disconnect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
if (m_showed_element)
{
m_showed_element->setHighlighted(false);
m_showed_element = nullptr;
}
if (m_element)
m_element->setHighlighted(false);
if (m_project)
disconnect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
if(Q_LIKELY(element->diagram() && element->diagram()->project())) if(Q_LIKELY(element->diagram() && element->diagram()->project()))
{ {
m_project = element->diagram()->project(); m_project = element->diagram()->project();
connect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject())); connect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
} }
else m_project = nullptr; else
m_project = nullptr;
//Keep up to date this widget when the linked elements of m_element change //Keep up to date this widget when the linked elements of m_element change
if (m_element) disconnect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi); if (m_element)
disconnect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi);
m_element = element; m_element = element;
connect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi); connect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi);
@@ -94,11 +137,12 @@ void MasterPropertiesWidget::apply() {
* @brief MasterPropertiesWidget::reset * @brief MasterPropertiesWidget::reset
* Reset curent widget, clear eveything and rebuild widget. * Reset curent widget, clear eveything and rebuild widget.
*/ */
void MasterPropertiesWidget::reset() { void MasterPropertiesWidget::reset()
foreach (QListWidgetItem *lwi, lwi_hash.keys()) { {
delete lwi; foreach (QTreeWidgetItem *qtwi, m_qtwi_hash.keys())
} delete qtwi;
lwi_hash.clear();
m_qtwi_hash.clear();
updateUi(); updateUi();
} }
@@ -114,8 +158,8 @@ QUndoCommand* MasterPropertiesWidget::associatedUndo() const
QList <Element *> to_link; QList <Element *> to_link;
QList <Element *> linked_ = m_element->linkedElements(); QList <Element *> linked_ = m_element->linkedElements();
for (int i=0; i<ui->linked_list->count(); i++) for (int i=0; i<ui->m_link_tree_widget->topLevelItemCount(); i++)
to_link << lwi_hash[ui->linked_list->item(i)]; to_link << m_qtwi_hash[ui->m_link_tree_widget->topLevelItem(i)];
//The two list contain the same element, there is no change //The two list contain the same element, there is no change
if (to_link.size() == linked_.size()) if (to_link.size() == linked_.size())
@@ -158,43 +202,54 @@ bool MasterPropertiesWidget::setLiveEdit(bool live_edit)
*/ */
void MasterPropertiesWidget::updateUi() void MasterPropertiesWidget::updateUi()
{ {
ui->free_list->clear(); ui->m_free_tree_widget->clear();
ui->linked_list->clear(); ui->m_link_tree_widget->clear();
lwi_hash.clear(); m_qtwi_hash.clear();
if (Q_UNLIKELY(!m_project)) return; if (Q_UNLIKELY(!m_project))
return;
ElementProvider elmt_prov(m_project); ElementProvider elmt_prov(m_project);
//Build the list of free available element //Build the list of free available element
QList <QTreeWidgetItem *> items_list;
foreach(Element *elmt, elmt_prov.freeElement(Element::Slave)) foreach(Element *elmt, elmt_prov.freeElement(Element::Slave))
{ {
//label for list widget QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_free_tree_widget);
QString widget_text; qtwi->setIcon(0, elmt->pixmap());
QString title = elmt->diagram()->title(); qtwi->setText(1, QString::number(elmt->diagram()->folioIndex() + 1));
if (title.isEmpty()) title = tr("Sans titre");
widget_text += QString(tr("Folio %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1) autonum::sequentialNumbers seq;
.arg(title) QString F =autonum::AssignVariables::formulaToLabel(elmt->diagram()->border_and_titleblock.folio(), seq, elmt->diagram(), elmt);
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()); qtwi->setText(2, F);
QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text); qtwi->setText(3, elmt->diagram()->title());
lwi_hash.insert(lwi_, elmt); qtwi->setText(4, elmt->diagram()->convertPosition(elmt->scenePos()).toString());
ui->free_list->addItem(lwi_); items_list.append(qtwi);
m_qtwi_hash.insert(qtwi, elmt);
} }
ui->m_free_tree_widget->addTopLevelItems(items_list);
items_list.clear();
//Build the list of already linked element //Build the list of already linked element
foreach(Element *elmt, m_element->linkedElements()) foreach(Element *elmt, m_element->linkedElements())
{ {
//label for list widget QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_link_tree_widget);
QString widget_text; qtwi->setIcon(0, elmt->pixmap());
QString title = elmt->diagram()->title(); qtwi->setText(1, QString::number(elmt->diagram()->folioIndex() + 1));
if (title.isEmpty()) title = tr("Sans titre");
widget_text += QString(tr("Folio %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1) autonum::sequentialNumbers seq;
.arg(title) QString F =autonum::AssignVariables::formulaToLabel(elmt->diagram()->border_and_titleblock.folio(), seq, elmt->diagram(), elmt);
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()); qtwi->setText(2, F);
QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text); qtwi->setText(3, elmt->diagram()->title());
lwi_hash.insert(lwi_, elmt); qtwi->setText(4, elmt->diagram()->convertPosition(elmt->scenePos()).toString());
ui->linked_list->addItem(lwi_); items_list.append(qtwi);
m_qtwi_hash.insert(qtwi, elmt);
} }
if(items_list.count())
ui->m_link_tree_widget->addTopLevelItems(items_list);
} }
/** /**
@@ -204,9 +259,9 @@ void MasterPropertiesWidget::updateUi()
void MasterPropertiesWidget::on_link_button_clicked() void MasterPropertiesWidget::on_link_button_clicked()
{ {
//take the curent item from free_list and push it to linked_list //take the curent item from free_list and push it to linked_list
ui->linked_list->addItem( QTreeWidgetItem *qtwi = ui->m_free_tree_widget->currentItem();
ui->free_list->takeItem( ui->m_free_tree_widget->takeTopLevelItem(ui->m_free_tree_widget->indexOfTopLevelItem(qtwi));
ui->free_list->currentRow())); ui->m_link_tree_widget->insertTopLevelItem(0, qtwi);
if(m_live_edit) apply(); if(m_live_edit) apply();
} }
@@ -218,27 +273,31 @@ void MasterPropertiesWidget::on_link_button_clicked()
void MasterPropertiesWidget::on_unlink_button_clicked() void MasterPropertiesWidget::on_unlink_button_clicked()
{ {
//take the curent item from linked_list and push it to free_list //take the curent item from linked_list and push it to free_list
ui->free_list->addItem( QTreeWidgetItem *qtwi = ui->m_link_tree_widget->currentItem();
ui->linked_list->takeItem( ui->m_link_tree_widget->takeTopLevelItem(ui->m_link_tree_widget->indexOfTopLevelItem(qtwi));
ui->linked_list->currentRow())); ui->m_free_tree_widget->insertTopLevelItem(0, qtwi);
if(m_live_edit) apply(); if(m_live_edit) apply();
} }
/** /**
* @brief MasterPropertiesWidget::showElementFromLWI * @brief MasterPropertiesWidget::showElementFromTWI
* Show the element corresponding to the given QListWidgetItem * Show the element corresponding to the given QTreeWidgetItem
* @param lwi * @param qtwi
* @param column
*/ */
void MasterPropertiesWidget::showElementFromLWI(QListWidgetItem *lwi) void MasterPropertiesWidget::showElementFromTWI(QTreeWidgetItem *qtwi, int column)
{ {
Q_UNUSED(column);
if (m_showed_element) if (m_showed_element)
{ {
disconnect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted())); disconnect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
m_showed_element -> setHighlighted(false); m_showed_element -> setHighlighted(false);
} }
if (m_element)
m_element->setHighlighted(false);
m_showed_element = lwi_hash[lwi]; m_showed_element = m_qtwi_hash[qtwi];
m_showed_element->diagram()->showMe(); m_showed_element->diagram()->showMe();
m_showed_element->setHighlighted(true); m_showed_element->setHighlighted(true);
connect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted())); connect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
@@ -263,3 +322,47 @@ void MasterPropertiesWidget::diagramWasdeletedFromProject()
//we must to wait for this elements be unlinked, else the linked list provide deleted elements. //we must to wait for this elements be unlinked, else the linked list provide deleted elements.
QTimer::singleShot(10, this, SLOT(updateUi())); QTimer::singleShot(10, this, SLOT(updateUi()));
} }
/**
* @brief MasterPropertiesWidget::customContextMenu
* Display a context menu
* @param pos
* @param i : the tree widget where the context menu was requested.
*/
void MasterPropertiesWidget::customContextMenu(const QPoint &pos, int i)
{
//add the size of the header to display the topleft of the QMenu at the position of the mouse.
//See doc about QWidget::customContextMenuRequested section related to QAbstractScrollArea
QPoint point = pos;
point.ry()+=ui->m_free_tree_widget->header()->height();
m_context_menu->clear();
if (i == 1)
{
point = ui->m_free_tree_widget->mapToGlobal(point);
//Context at for free tree widget
if (ui->m_free_tree_widget->currentItem())
{
m_qtwi_at_context_menu = ui->m_free_tree_widget->currentItem();
m_context_menu->addAction(m_link_action);
m_context_menu->addAction(m_show_qtwi);
}
}
else
{
point = ui->m_link_tree_widget->mapToGlobal(point);
//context at for link tre widget
if (ui->m_link_tree_widget->currentItem())
{
m_qtwi_at_context_menu = ui->m_link_tree_widget->currentItem();
m_context_menu->addAction(m_unlink_action);
m_context_menu->addAction(m_show_qtwi);
}
}
m_context_menu->addAction(m_show_element);
m_context_menu->popup(point);
}

View File

@@ -22,11 +22,13 @@
#include <QHash> #include <QHash>
#include "abstractelementpropertieseditorwidget.h" #include "abstractelementpropertieseditorwidget.h"
class QListWidgetItem;
class Element; class Element;
class QUndoCommand; class QUndoCommand;
class QETProject; class QETProject;
class Diagram; class Diagram;
class QTreeWidgetItem;
class QMenu;
class QAction;
namespace Ui { namespace Ui {
class MasterPropertiesWidget; class MasterPropertiesWidget;
@@ -50,7 +52,7 @@ class MasterPropertiesWidget : public AbstractElementPropertiesEditorWidget
void apply(); void apply();
void reset(); void reset();
QUndoCommand *associatedUndo () const; QUndoCommand *associatedUndo () const;
QString title() const {return tr("Référence croisée (maitre)");} QString title() const {return tr("Référence croisée (maître)");}
bool setLiveEdit(bool live_edit); bool setLiveEdit(bool live_edit);
public slots: public slots:
@@ -59,15 +61,22 @@ class MasterPropertiesWidget : public AbstractElementPropertiesEditorWidget
private slots: private slots:
void on_link_button_clicked(); void on_link_button_clicked();
void on_unlink_button_clicked(); void on_unlink_button_clicked();
void showElementFromLWI(QListWidgetItem *lwi); void showElementFromTWI(QTreeWidgetItem *qtwi, int column);
void showedElementWasDeleted (); void showedElementWasDeleted ();
void diagramWasdeletedFromProject(); void diagramWasdeletedFromProject();
void customContextMenu(const QPoint &pos, int i=0);
private: private:
Ui::MasterPropertiesWidget *ui; Ui::MasterPropertiesWidget *ui;
QHash <QListWidgetItem *, Element *> lwi_hash; QHash <QTreeWidgetItem *, Element *> m_qtwi_hash;
QTreeWidgetItem *m_qtwi_at_context_menu = nullptr;
Element *m_showed_element; Element *m_showed_element;
QETProject *m_project; QETProject *m_project;
QMenu *m_context_menu;
QAction *m_link_action,
*m_unlink_action,
*m_show_qtwi,
*m_show_element;
}; };
#endif // MASTERPROPERTIESWIDGET_H #endif // MASTERPROPERTIESWIDGET_H

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>300</width> <width>642</width>
<height>400</height> <height>666</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
@@ -19,55 +19,139 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="1" rowspan="5"> <item row="2" column="2">
<widget class="QListWidget" name="free_list"/> <widget class="QLabel" name="label_2">
</item> <property name="frameShape">
<item row="5" column="2"> <enum>QFrame::NoFrame</enum>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="text">
<string>Éléments liés</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<widget class="QTreeWidget" name="m_link_tree_widget">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="iconSize">
<size> <size>
<width>20</width> <width>32</width>
<height>40</height> <height>32</height>
</size> </size>
</property> </property>
</spacer> <property name="uniformRowHeights">
</item> <bool>true</bool>
<item row="4" column="2">
<widget class="QPushButton" name="unlink_button">
<property name="toolTip">
<string>Délier l'élément séléctionné</string>
</property> </property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<attribute name="headerDefaultSectionSize">
<number>80</number>
</attribute>
<attribute name="headerStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text"> <property name="text">
<string/> <string>Vignette</string>
</property> </property>
<property name="icon"> </column>
<iconset resource="../../qelectrotech.qrc"> <column>
<normaloff>:/ico/16x16/arrow-left.png</normaloff>:/ico/16x16/arrow-left.png</iconset> <property name="text">
<string>N° de folio</string>
</property> </property>
</column>
<column>
<property name="text">
<string>Label de folio</string>
</property>
</column>
<column>
<property name="text">
<string>Titre de folio</string>
</property>
</column>
<column>
<property name="text">
<string>Position</string>
</property>
</column>
</widget> </widget>
</item> </item>
<item row="1" column="3" rowspan="5"> <item row="1" column="2" colspan="3">
<widget class="QListWidget" name="linked_list"/> <widget class="QTreeWidget" name="m_free_tree_widget">
</item> <property name="showDropIndicator" stdset="0">
<item row="3" column="2"> <bool>false</bool>
<widget class="QPushButton" name="link_button">
<property name="toolTip">
<string>Lier l'élément séléctionné</string>
</property> </property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>true</bool>
</attribute>
<attribute name="headerCascadingSectionResizes">
<bool>false</bool>
</attribute>
<attribute name="headerDefaultSectionSize">
<number>80</number>
</attribute>
<attribute name="headerStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text"> <property name="text">
<string/> <string>Vignette</string>
</property> </property>
<property name="icon"> </column>
<iconset resource="../../qelectrotech.qrc"> <column>
<normaloff>:/ico/16x16/arrow-right.png</normaloff>:/ico/16x16/arrow-right.png</iconset> <property name="text">
<string>N° de folio</string>
</property> </property>
</column>
<column>
<property name="text">
<string>Label de folio</string>
</property>
</column>
<column>
<property name="text">
<string>Titre de folio</string>
</property>
</column>
<column>
<property name="text">
<string>Position</string>
</property>
</column>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="2">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Éléments disponibles</string> <string>Éléments disponibles</string>
@@ -77,28 +161,33 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="3"> <item row="2" column="3">
<widget class="QLabel" name="label_2"> <widget class="QPushButton" name="unlink_button">
<property name="text"> <property name="toolTip">
<string>Éléments liés</string> <string>Délier l'élément séléctionné</string>
</property> </property>
<property name="alignment"> <property name="text">
<set>Qt::AlignCenter</set> <string/>
</property>
<property name="icon">
<iconset resource="../../qelectrotech.qrc">
<normaloff>:/ico/16x16/go-up.png</normaloff>:/ico/16x16/go-up.png</iconset>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2"> <item row="2" column="4">
<spacer name="verticalSpacer"> <widget class="QPushButton" name="link_button">
<property name="orientation"> <property name="toolTip">
<enum>Qt::Vertical</enum> <string>Lier l'élément séléctionné</string>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="text">
<size> <string/>
<width>20</width>
<height>40</height>
</size>
</property> </property>
</spacer> <property name="icon">
<iconset resource="../../qelectrotech.qrc">
<normaloff>:/ico/16x16/go-down.png</normaloff>:/ico/16x16/go-down.png</iconset>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>