##// END OF EJS Templates
Display of the save & cancel button next to a catalogue
trabillard -
r1142:425eece3bcf7
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -14,8 +14,11 public:
14 QVariant data(int column, int role) const override;
14 QVariant data(int column, int role) const override;
15 void setData(int column, int role, const QVariant &value) override;
15 void setData(int column, int role, const QVariant &value) override;
16
16
17 /// Returns the catalogue represented by the item
17 DBCatalogue catalogue() const;
18 DBCatalogue catalogue() const;
18
19
20 void setHasChanges(bool value);
21
19 private:
22 private:
20 class CatalogueTreeWidgetItemPrivate;
23 class CatalogueTreeWidgetItemPrivate;
21 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
24 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
@@ -25,5 +25,7
25 <file>icones/allEvents.png</file>
25 <file>icones/allEvents.png</file>
26 <file>icones/trash.png</file>
26 <file>icones/trash.png</file>
27 <file>icones/database.png</file>
27 <file>icones/database.png</file>
28 <file>icones/save.png</file>
29 <file>icones/discard.png</file>
28 </qresource>
30 </qresource>
29 </RCC>
31 </RCC>
@@ -35,6 +35,11 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
35 ui->setupUi(this);
35 ui->setupUi(this);
36 impl->configureTreeWidget(ui->treeWidget);
36 impl->configureTreeWidget(ui->treeWidget);
37
37
38 ui->treeWidget->setColumnCount(2);
39 ui->treeWidget->header()->setStretchLastSection(false);
40 ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
41 ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
42
38 auto emitSelection = [this]() {
43 auto emitSelection = [this]() {
39
44
40 auto selectedItems = ui->treeWidget->selectedItems();
45 auto selectedItems = ui->treeWidget->selectedItems();
@@ -145,7 +150,6 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
145
150
146 auto separator = new QFrame{treeWidget};
151 auto separator = new QFrame{treeWidget};
147 separator->setFrameShape(QFrame::HLine);
152 separator->setFrameShape(QFrame::HLine);
148
149 auto separatorItem = new QTreeWidgetItem{};
153 auto separatorItem = new QTreeWidgetItem{};
150 separatorItem->setFlags(Qt::NoItemFlags);
154 separatorItem->setFlags(Qt::NoItemFlags);
151 treeWidget->addTopLevelItem(separatorItem);
155 treeWidget->addTopLevelItem(separatorItem);
@@ -1,5 +1,12
1 #include "Catalogue/CatalogueTreeWidgetItem.h"
1 #include "Catalogue/CatalogueTreeWidgetItem.h"
2
2
3 #include <memory>
4
5 #include <QBoxLayout>
6 #include <QToolButton>
7
8 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
9
3 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
10 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
4
11
5 DBCatalogue m_Catalogue;
12 DBCatalogue m_Catalogue;
@@ -17,12 +24,14 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(DBCatalogue catalogue, int type
17
24
18 QVariant CatalogueTreeWidgetItem::data(int column, int role) const
25 QVariant CatalogueTreeWidgetItem::data(int column, int role) const
19 {
26 {
20 switch (role) {
27 if (column == 0) {
21 case Qt::EditRole: // fallthrough
28 switch (role) {
22 case Qt::DisplayRole:
29 case Qt::EditRole: // fallthrough
23 return impl->m_Catalogue.getName();
30 case Qt::DisplayRole:
24 default:
31 return impl->m_Catalogue.getName();
25 break;
32 default:
33 break;
34 }
26 }
35 }
27
36
28 return QTreeWidgetItem::data(column, role);
37 return QTreeWidgetItem::data(column, role);
@@ -32,8 +41,11 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &valu
32 {
41 {
33 if (role == Qt::EditRole && column == 0) {
42 if (role == Qt::EditRole && column == 0) {
34 auto newName = value.toString();
43 auto newName = value.toString();
35 setText(0, newName);
44 if (newName != impl->m_Catalogue.getName()) {
36 impl->m_Catalogue.setName(newName);
45 setText(0, newName);
46 impl->m_Catalogue.setName(newName);
47 setHasChanges(true);
48 }
37 }
49 }
38 else {
50 else {
39 QTreeWidgetItem::setData(column, role, value);
51 QTreeWidgetItem::setData(column, role, value);
@@ -44,3 +56,35 DBCatalogue CatalogueTreeWidgetItem::catalogue() const
44 {
56 {
45 return impl->m_Catalogue;
57 return impl->m_Catalogue;
46 }
58 }
59
60 void CatalogueTreeWidgetItem::setHasChanges(bool value)
61 {
62 if (value) {
63 auto widet = new QWidget{treeWidget()};
64
65 auto layout = new QHBoxLayout{widet};
66 layout->setContentsMargins(0, 0, 0, 0);
67 layout->setSpacing(0);
68
69 auto btnValid = new QToolButton{widet};
70 btnValid->setIcon(QIcon{":/icones/save"});
71 btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
72 btnValid->setAutoRaise(true);
73 QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); });
74 layout->addWidget(btnValid);
75
76 auto btnDiscard = new QToolButton{widet};
77 btnDiscard->setIcon(QIcon{":/icones/discard"});
78 btnDiscard->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
79 btnDiscard->setAutoRaise(true);
80 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
81 layout->addWidget(btnDiscard);
82
83 treeWidget()->setItemWidget(this, 1, {widet});
84 treeWidget()->resizeColumnToContents(1);
85 }
86 else {
87 // Note: the widget is destroyed
88 treeWidget()->setItemWidget(this, 1, nullptr);
89 }
90 }
General Comments 0
You need to be logged in to leave comments. Login now