##// END OF EJS Templates
Edition of catalogues from the inspector
trabillard -
r1180:938a31670f5f
parent child
Show More
@@ -1,36 +1,44
1 1 #ifndef SCIQLOP_CATALOGUEINSPECTORWIDGET_H
2 2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
3 3
4 #include <Common/spimpl.h>
4 5 #include <QWidget>
5 6 #include <memory>
6 7
7 8 namespace Ui {
8 9 class CatalogueInspectorWidget;
9 10 }
10 11
11 12 class DBCatalogue;
12 13 class DBEvent;
13 14
14 15 class CatalogueInspectorWidget : public QWidget {
15 16 Q_OBJECT
16 17
18 signals:
19 void catalogueUpdated(const std::shared_ptr<DBCatalogue> &catalogue);
20 void eventUpdated(const std::shared_ptr<DBEvent> &event);
21
17 22 public:
18 23 explicit CatalogueInspectorWidget(QWidget *parent = 0);
19 24 virtual ~CatalogueInspectorWidget();
20 25
21 26 /// Enum matching the pages inside the stacked widget
22 27 enum class Page { Empty, CatalogueProperties, EventProperties };
23 28
24 29 Page currentPage() const;
25 30
26 31 void setEvent(const std::shared_ptr<DBEvent> &event);
27 32 void setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue);
28 33
29 34 public slots:
30 35 void showPage(Page page);
31 36
32 37 private:
33 38 Ui::CatalogueInspectorWidget *ui;
39
40 class CatalogueInspectorWidgetPrivate;
41 spimpl::unique_impl_ptr<CatalogueInspectorWidgetPrivate> impl;
34 42 };
35 43
36 44 #endif // SCIQLOP_CATALOGUEINSPECTORWIDGET_H
@@ -1,38 +1,43
1 1 #ifndef SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
3 3
4 4 #include <Common/spimpl.h>
5 #include <QLoggingCategory>
5 6 #include <QTreeWidgetItem>
6 7 #include <QWidget>
7 8
8 9 class DBCatalogue;
9 10
10 11 namespace Ui {
11 12 class CatalogueSideBarWidget;
12 13 }
13 14
15 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget)
16
14 17 class CatalogueSideBarWidget : public QWidget {
15 18 Q_OBJECT
16 19
17 20 signals:
18 21 void catalogueSelected(const QVector<std::shared_ptr<DBCatalogue> > &catalogues);
19 22 void databaseSelected(const QStringList &databases);
20 23 void allEventsSelected();
21 24 void trashSelected();
22 25 void selectionCleared();
23 26
24 27 public:
25 28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
26 29 virtual ~CatalogueSideBarWidget();
27 30
31 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
32
28 33 private:
29 34 Ui::CatalogueSideBarWidget *ui;
30 35
31 36 class CatalogueSideBarWidgetPrivate;
32 37 spimpl::unique_impl_ptr<CatalogueSideBarWidgetPrivate> impl;
33 38
34 39 private slots:
35 40 void onContextMenuRequested(const QPoint &pos);
36 41 };
37 42
38 43 #endif // SCIQLOP_CATALOGUESIDEBARWIDGET_H
@@ -1,28 +1,33
1 1 #ifndef SCIQLOP_CATALOGUETREEWIDGETITEM_H
2 2 #define SCIQLOP_CATALOGUETREEWIDGETITEM_H
3 3
4 4 #include <Common/spimpl.h>
5 5 #include <QTreeWidgetItem>
6 6
7 7 class DBCatalogue;
8 8
9 9
10 10 class CatalogueTreeWidgetItem : public QTreeWidgetItem {
11 11 public:
12 12 CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue,
13 13 int type = QTreeWidgetItem::Type);
14 14
15 15 QVariant data(int column, int role) const override;
16 16 void setData(int column, int role, const QVariant &value) override;
17 17
18 18 /// Returns the catalogue represented by the item
19 19 std::shared_ptr<DBCatalogue> catalogue() const;
20 20
21 /// Displays or hides the save and cancel buttons indicating that the catalogue has unsaved
22 /// changes
21 23 void setHasChanges(bool value);
22 24
25 /// Refreshes the data displayed by the item from the catalogue
26 void refresh();
27
23 28 private:
24 29 class CatalogueTreeWidgetItemPrivate;
25 30 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
26 31 };
27 32
28 33 #endif // SCIQLOP_CATALOGUETREEWIDGETITEM_H
@@ -1,61 +1,64
1 1 #include "Catalogue/CatalogueExplorer.h"
2 2 #include "ui_CatalogueExplorer.h"
3 3
4 4 #include <Visualization/VisualizationWidget.h>
5 5
6 6 #include <DBCatalogue.h>
7 7 #include <DBEvent.h>
8 8
9 9 struct CatalogueExplorer::CatalogueExplorerPrivate {
10 10 };
11 11
12 12 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
13 13 : QDialog(parent, Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
14 14 ui(new Ui::CatalogueExplorer),
15 15 impl{spimpl::make_unique_impl<CatalogueExplorerPrivate>()}
16 16 {
17 17 ui->setupUi(this);
18 18
19 19 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
20 20 if (catalogues.count() == 1) {
21 21 ui->inspector->setCatalogue(catalogues.first());
22 22 }
23 23 else {
24 24 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
25 25 }
26 26
27 27 ui->events->populateWithCatalogues(catalogues);
28 28 });
29 29
30 30 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) {
31 31 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
32 32 });
33 33
34 34 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
35 35 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
36 36
37 37 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected,
38 38 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
39 39
40 40 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
41 41 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
42 42
43 43 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
44 44 if (events.count() == 1) {
45 45 ui->inspector->setEvent(events.first());
46 46 }
47 47 else {
48 48 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
49 49 }
50 50 });
51
52 connect(ui->inspector, &CatalogueInspectorWidget::catalogueUpdated,
53 [this](auto catalogue) { ui->catalogues->setCatalogueChanges(catalogue, true); });
51 54 }
52 55
53 56 CatalogueExplorer::~CatalogueExplorer()
54 57 {
55 58 delete ui;
56 59 }
57 60
58 61 void CatalogueExplorer::setVisualizationWidget(VisualizationWidget *visualization)
59 62 {
60 63 ui->events->setVisualizationWidget(visualization);
61 64 }
@@ -1,56 +1,89
1 1 #include "Catalogue/CatalogueInspectorWidget.h"
2 2 #include "ui_CatalogueInspectorWidget.h"
3 3
4 4 #include <Common/DateUtils.h>
5 5 #include <DBCatalogue.h>
6 6 #include <DBEvent.h>
7 7 #include <DBTag.h>
8 8
9 struct CatalogueInspectorWidget::CatalogueInspectorWidgetPrivate {
10 std::shared_ptr<DBCatalogue> m_DisplayedCatalogue = nullptr;
11 std::shared_ptr<DBEvent> m_DisplayedEvent = nullptr;
12 };
13
9 14 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
10 : QWidget(parent), ui(new Ui::CatalogueInspectorWidget)
15 : QWidget(parent),
16 ui(new Ui::CatalogueInspectorWidget),
17 impl{spimpl::make_unique_impl<CatalogueInspectorWidgetPrivate>()}
11 18 {
12 19 ui->setupUi(this);
13 20 showPage(Page::Empty);
21
22 connect(ui->leCatalogueName, &QLineEdit::editingFinished, [this]() {
23 if (ui->leCatalogueName->text() != impl->m_DisplayedCatalogue->getName()) {
24 impl->m_DisplayedCatalogue->setName(ui->leCatalogueName->text());
25 emit this->catalogueUpdated(impl->m_DisplayedCatalogue);
26 }
27 });
28
29 connect(ui->leCatalogueAuthor, &QLineEdit::editingFinished, [this]() {
30 if (ui->leCatalogueAuthor->text() != impl->m_DisplayedCatalogue->getAuthor()) {
31 impl->m_DisplayedCatalogue->setAuthor(ui->leCatalogueAuthor->text());
32 emit this->catalogueUpdated(impl->m_DisplayedCatalogue);
33 }
34 });
14 35 }
15 36
16 37 CatalogueInspectorWidget::~CatalogueInspectorWidget()
17 38 {
18 39 delete ui;
19 40 }
20 41
21 42 void CatalogueInspectorWidget::showPage(CatalogueInspectorWidget::Page page)
22 43 {
23 44 ui->stackedWidget->setCurrentIndex(static_cast<int>(page));
24 45 }
25 46
26 47 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
27 48 {
28 49 return static_cast<Page>(ui->stackedWidget->currentIndex());
29 50 }
30 51
31 52 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
32 53 {
54 impl->m_DisplayedEvent = event;
55
56 blockSignals(true);
57
33 58 showPage(Page::EventProperties);
34 59 ui->leEventName->setText(event->getName());
35 60 ui->leEventMission->setText(event->getMission());
36 61 ui->leEventProduct->setText(event->getProduct());
37 62
38 63 QString tagList;
39 64 auto tags = event->getTags();
40 65 for (auto tag : tags) {
41 66 tagList += tag.getName();
42 67 tagList += ' ';
43 68 }
44 69
45 70 ui->leEventTags->setText(tagList);
46 71
47 72 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
48 73 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
74
75 blockSignals(false);
49 76 }
50 77
51 78 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
52 79 {
80 impl->m_DisplayedCatalogue = catalogue;
81
82 blockSignals(true);
83
53 84 showPage(Page::CatalogueProperties);
54 85 ui->leCatalogueName->setText(catalogue->getName());
55 86 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
87
88 blockSignals(false);
56 89 }
@@ -1,198 +1,247
1 1 #include "Catalogue/CatalogueSideBarWidget.h"
2 2 #include "ui_CatalogueSideBarWidget.h"
3 3 #include <SqpApplication.h>
4 4
5 5 #include <Catalogue/CatalogueController.h>
6 6 #include <Catalogue/CatalogueTreeWidgetItem.h>
7 7 #include <CatalogueDao.h>
8 8 #include <ComparaisonPredicate.h>
9 9 #include <DBCatalogue.h>
10 10
11 11 #include <QMenu>
12 12
13 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
14
13 15
14 16 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
15 17 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
16 18 constexpr auto CATALOGUE_ITEM_TYPE = QTreeWidgetItem::UserType + 2;
17 19 constexpr auto DATABASE_ITEM_TYPE = QTreeWidgetItem::UserType + 3;
18 20
19 21
20 22 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
21 23
22 24 void configureTreeWidget(QTreeWidget *treeWidget);
23 25 QTreeWidgetItem *addDatabaseItem(const QString &name, QTreeWidget *treeWidget);
24 26 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
25 27 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
26 28 QTreeWidgetItem *parentDatabaseItem);
29
30 CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
31 QTreeWidget *treeWidget) const;
27 32 };
28 33
29 34 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
30 35 : QWidget(parent),
31 36 ui(new Ui::CatalogueSideBarWidget),
32 37 impl{spimpl::make_unique_impl<CatalogueSideBarWidgetPrivate>()}
33 38 {
34 39 ui->setupUi(this);
35 40 impl->configureTreeWidget(ui->treeWidget);
36 41
37 42 ui->treeWidget->setColumnCount(2);
38 43 ui->treeWidget->header()->setStretchLastSection(false);
39 44 ui->treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
40 45 ui->treeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
41 46
42 47 auto emitSelection = [this]() {
43 48
44 49 auto selectedItems = ui->treeWidget->selectedItems();
45 50 if (selectedItems.isEmpty()) {
46 51 emit this->selectionCleared();
47 52 }
48 53 else {
49 54 QVector<std::shared_ptr<DBCatalogue> > catalogues;
50 55 QStringList databases;
51 56 int selectionType = selectedItems.first()->type();
52 57
53 58 for (auto item : ui->treeWidget->selectedItems()) {
54 59 if (item->type() == selectionType) {
55 60 switch (selectionType) {
56 61 case CATALOGUE_ITEM_TYPE:
57 62 catalogues.append(
58 63 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
59 64 break;
60 65 case DATABASE_ITEM_TYPE:
61 66 selectionType = DATABASE_ITEM_TYPE;
62 67 databases.append(item->text(0));
63 68 case ALL_EVENT_ITEM_TYPE: // fallthrough
64 69 case TRASH_ITEM_TYPE: // fallthrough
65 70 default:
66 71 break;
67 72 }
68 73 }
69 74 else {
70 75 // Incoherent multi selection
71 76 selectionType = -1;
72 77 break;
73 78 }
74 79 }
75 80
76 81 switch (selectionType) {
77 82 case CATALOGUE_ITEM_TYPE:
78 83 emit this->catalogueSelected(catalogues);
79 84 break;
80 85 case DATABASE_ITEM_TYPE:
81 86 emit this->databaseSelected(databases);
82 87 break;
83 88 case ALL_EVENT_ITEM_TYPE:
84 89 emit this->allEventsSelected();
85 90 break;
86 91 case TRASH_ITEM_TYPE:
87 92 emit this->trashSelected();
88 93 break;
89 94 default:
90 95 emit this->selectionCleared();
91 96 break;
92 97 }
93 98 }
94 99
95 100
96 101 };
97 102
98 103 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
99 104 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
105 connect(ui->treeWidget, &QTreeWidget::itemChanged,
106 [emitSelection, this](auto item, auto column) {
107 auto selectedItems = ui->treeWidget->selectedItems();
108 qDebug() << "ITEM CHANGED" << column;
109 if (selectedItems.contains(item) && column == 0) {
110 emitSelection();
111 }
112 });
100 113
101 114 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
102 115 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
103 116 &CatalogueSideBarWidget::onContextMenuRequested);
104 117 }
105 118
106 119 CatalogueSideBarWidget::~CatalogueSideBarWidget()
107 120 {
108 121 delete ui;
109 122 }
110 123
124 void CatalogueSideBarWidget::setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue,
125 bool hasChanges)
126 {
127 if (auto catalogueItem = impl->getCatalogueItem(catalogue, ui->treeWidget)) {
128 catalogueItem->setHasChanges(hasChanges);
129 catalogueItem->refresh();
130 }
131 }
132
111 133 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
112 134 {
113 135 QMenu menu{this};
114 136
115 137 auto currentItem = ui->treeWidget->currentItem();
116 138 switch (currentItem->type()) {
117 139 case CATALOGUE_ITEM_TYPE:
118 140 menu.addAction("Rename",
119 141 [this, currentItem]() { ui->treeWidget->editItem(currentItem); });
120 142 break;
121 143 case DATABASE_ITEM_TYPE:
122 144 break;
123 145 case ALL_EVENT_ITEM_TYPE:
124 146 break;
125 147 case TRASH_ITEM_TYPE:
126 148 menu.addAction("Empty Trash", []() {
127 149 // TODO
128 150 });
129 151 break;
130 152 default:
131 153 break;
132 154 }
133 155
134 156 if (!menu.isEmpty()) {
135 157 menu.exec(ui->treeWidget->mapToGlobal(pos));
136 158 }
137 159 }
138 160
139 161 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::configureTreeWidget(
140 162 QTreeWidget *treeWidget)
141 163 {
142 164 auto allEventsItem = new QTreeWidgetItem{{"All Events"}, ALL_EVENT_ITEM_TYPE};
143 165 allEventsItem->setIcon(0, QIcon(":/icones/allEvents.png"));
144 166 treeWidget->addTopLevelItem(allEventsItem);
145 167
146 168 auto trashItem = new QTreeWidgetItem{{"Trash"}, TRASH_ITEM_TYPE};
147 169 trashItem->setIcon(0, QIcon(":/icones/trash.png"));
148 170 treeWidget->addTopLevelItem(trashItem);
149 171
150 172 auto separator = new QFrame{treeWidget};
151 173 separator->setFrameShape(QFrame::HLine);
152 174 auto separatorItem = new QTreeWidgetItem{};
153 175 separatorItem->setFlags(Qt::NoItemFlags);
154 176 treeWidget->addTopLevelItem(separatorItem);
155 177 treeWidget->setItemWidget(separatorItem, 0, separator);
156 178
157 179 auto db = addDatabaseItem("Default", treeWidget);
158 180
159 181 auto catalogues = sqpApp->catalogueController().getCatalogues("Default");
160 182 for (auto catalogue : catalogues) {
161 183 addCatalogueItem(catalogue, db);
162 184 }
163 185
164 186 treeWidget->expandAll();
165 187 }
166 188
167 189 QTreeWidgetItem *
168 190 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addDatabaseItem(const QString &name,
169 191 QTreeWidget *treeWidget)
170 192 {
171 193 auto databaseItem = new QTreeWidgetItem{{name}, DATABASE_ITEM_TYPE};
172 194 databaseItem->setIcon(0, QIcon{":/icones/database.png"});
173 195 treeWidget->addTopLevelItem(databaseItem);
174 196
175 197 return databaseItem;
176 198 }
177 199
178 200 QTreeWidgetItem *
179 201 CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getDatabaseItem(const QString &name,
180 202 QTreeWidget *treeWidget)
181 203 {
182 204 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
183 205 auto item = treeWidget->topLevelItem(i);
184 206 if (item->type() == DATABASE_ITEM_TYPE && item->text(0) == name) {
185 207 return item;
186 208 }
187 209 }
188 210
189 211 return nullptr;
190 212 }
191 213
192 214 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
193 215 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidgetItem *parentDatabaseItem)
194 216 {
195 217 auto catalogueItem = new CatalogueTreeWidgetItem{catalogue, CATALOGUE_ITEM_TYPE};
196 218 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
197 219 parentDatabaseItem->addChild(catalogueItem);
198 220 }
221
222 CatalogueTreeWidgetItem *CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::getCatalogueItem(
223 const std::shared_ptr<DBCatalogue> &catalogue, QTreeWidget *treeWidget) const
224 {
225 for (auto i = 0; i < treeWidget->topLevelItemCount(); ++i) {
226 auto item = treeWidget->topLevelItem(i);
227 if (item->type() == DATABASE_ITEM_TYPE) {
228 for (auto j = 0; j < item->childCount(); ++j) {
229 auto childItem = item->child(j);
230 if (childItem->type() == CATALOGUE_ITEM_TYPE) {
231 auto catalogueItem = static_cast<CatalogueTreeWidgetItem *>(childItem);
232 if (catalogueItem->catalogue() == catalogue) {
233 return catalogueItem;
234 }
235 }
236 else {
237 qCWarning(LOG_CatalogueSideBarWidget()) << "getCatalogueItem: Invalid tree "
238 "structure. A database item should "
239 "only contain catalogues.";
240 Q_ASSERT(false);
241 }
242 }
243 }
244 }
245
246 return nullptr;
247 }
@@ -1,93 +1,103
1 1 #include "Catalogue/CatalogueTreeWidgetItem.h"
2 2
3 3 #include <memory>
4 4
5 5 #include <DBCatalogue.h>
6 6 #include <QBoxLayout>
7 7 #include <QToolButton>
8 8
9 9 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
10 10
11 /// Column in the tree widget where the apply and cancel buttons must appear
12 const auto APPLY_CANCEL_BUTTONS_COLUMN = 1;
13
11 14 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
12 15
13 16 std::shared_ptr<DBCatalogue> m_Catalogue;
14 17
15 18 CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
16 19 {
17 20 }
18 21 };
19 22
20 23
21 24 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
22 25 : QTreeWidgetItem(type),
23 26 impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
24 27 {
25 28 setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
26 29 }
27 30
28 31 QVariant CatalogueTreeWidgetItem::data(int column, int role) const
29 32 {
30 33 if (column == 0) {
31 34 switch (role) {
32 35 case Qt::EditRole: // fallthrough
33 36 case Qt::DisplayRole:
34 37 return impl->m_Catalogue->getName();
35 38 default:
36 39 break;
37 40 }
38 41 }
39 42
40 43 return QTreeWidgetItem::data(column, role);
41 44 }
42 45
43 46 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value)
44 47 {
45 48 if (role == Qt::EditRole && column == 0) {
46 49 auto newName = value.toString();
47 50 if (newName != impl->m_Catalogue->getName()) {
48 51 setText(0, newName);
49 52 impl->m_Catalogue->setName(newName);
50 53 setHasChanges(true);
51 54 }
52 55 }
53 56 else {
54 57 QTreeWidgetItem::setData(column, role, value);
55 58 }
56 59 }
57 60
58 61 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
59 62 {
60 63 return impl->m_Catalogue;
61 64 }
62 65
63 66 void CatalogueTreeWidgetItem::setHasChanges(bool value)
64 67 {
65 68 if (value) {
66 auto widet = new QWidget{treeWidget()};
67
68 auto layout = new QHBoxLayout{widet};
69 layout->setContentsMargins(0, 0, 0, 0);
70 layout->setSpacing(0);
71
72 auto btnValid = new QToolButton{widet};
73 btnValid->setIcon(QIcon{":/icones/save"});
74 btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
75 btnValid->setAutoRaise(true);
76 QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); });
77 layout->addWidget(btnValid);
78
79 auto btnDiscard = new QToolButton{widet};
80 btnDiscard->setIcon(QIcon{":/icones/discard"});
81 btnDiscard->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
82 btnDiscard->setAutoRaise(true);
83 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
84 layout->addWidget(btnDiscard);
85
86 treeWidget()->setItemWidget(this, 1, {widet});
87 treeWidget()->resizeColumnToContents(1);
69 if (treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) == nullptr) {
70 auto widet = new QWidget{treeWidget()};
71
72 auto layout = new QHBoxLayout{widet};
73 layout->setContentsMargins(0, 0, 0, 0);
74 layout->setSpacing(0);
75
76 auto btnValid = new QToolButton{widet};
77 btnValid->setIcon(QIcon{":/icones/save"});
78 btnValid->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
79 btnValid->setAutoRaise(true);
80 QObject::connect(btnValid, &QToolButton::clicked, [this]() { setHasChanges(false); });
81 layout->addWidget(btnValid);
82
83 auto btnDiscard = new QToolButton{widet};
84 btnDiscard->setIcon(QIcon{":/icones/discard"});
85 btnDiscard->setIconSize(
86 QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
87 btnDiscard->setAutoRaise(true);
88 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
89 layout->addWidget(btnDiscard);
90
91 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, {widet});
92 }
88 93 }
89 94 else {
90 95 // Note: the widget is destroyed
91 treeWidget()->setItemWidget(this, 1, nullptr);
96 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
92 97 }
93 98 }
99
100 void CatalogueTreeWidgetItem::refresh()
101 {
102 emitDataChanged();
103 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

You need to be logged in to leave comments. Login now