##// END OF EJS Templates
Edition of catalogues from the inspector
trabillard -
r1180:938a31670f5f
parent child
Show More
@@ -1,6 +1,7
1 #ifndef SCIQLOP_CATALOGUEINSPECTORWIDGET_H
1 #ifndef SCIQLOP_CATALOGUEINSPECTORWIDGET_H
2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
2 #define SCIQLOP_CATALOGUEINSPECTORWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <QWidget>
5 #include <QWidget>
5 #include <memory>
6 #include <memory>
6
7
@@ -14,6 +15,10 class DBEvent;
14 class CatalogueInspectorWidget : public QWidget {
15 class CatalogueInspectorWidget : public QWidget {
15 Q_OBJECT
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 public:
22 public:
18 explicit CatalogueInspectorWidget(QWidget *parent = 0);
23 explicit CatalogueInspectorWidget(QWidget *parent = 0);
19 virtual ~CatalogueInspectorWidget();
24 virtual ~CatalogueInspectorWidget();
@@ -31,6 +36,9 public slots:
31
36
32 private:
37 private:
33 Ui::CatalogueInspectorWidget *ui;
38 Ui::CatalogueInspectorWidget *ui;
39
40 class CatalogueInspectorWidgetPrivate;
41 spimpl::unique_impl_ptr<CatalogueInspectorWidgetPrivate> impl;
34 };
42 };
35
43
36 #endif // SCIQLOP_CATALOGUEINSPECTORWIDGET_H
44 #endif // SCIQLOP_CATALOGUEINSPECTORWIDGET_H
@@ -2,6 +2,7
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
2 #define SCIQLOP_CATALOGUESIDEBARWIDGET_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5 #include <QLoggingCategory>
5 #include <QTreeWidgetItem>
6 #include <QTreeWidgetItem>
6 #include <QWidget>
7 #include <QWidget>
7
8
@@ -11,6 +12,8 namespace Ui {
11 class CatalogueSideBarWidget;
12 class CatalogueSideBarWidget;
12 }
13 }
13
14
15 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget)
16
14 class CatalogueSideBarWidget : public QWidget {
17 class CatalogueSideBarWidget : public QWidget {
15 Q_OBJECT
18 Q_OBJECT
16
19
@@ -25,6 +28,8 public:
25 explicit CatalogueSideBarWidget(QWidget *parent = 0);
28 explicit CatalogueSideBarWidget(QWidget *parent = 0);
26 virtual ~CatalogueSideBarWidget();
29 virtual ~CatalogueSideBarWidget();
27
30
31 void setCatalogueChanges(const std::shared_ptr<DBCatalogue> &catalogue, bool hasChanges);
32
28 private:
33 private:
29 Ui::CatalogueSideBarWidget *ui;
34 Ui::CatalogueSideBarWidget *ui;
30
35
@@ -18,8 +18,13 public:
18 /// Returns the catalogue represented by the item
18 /// Returns the catalogue represented by the item
19 std::shared_ptr<DBCatalogue> catalogue() const;
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 void setHasChanges(bool value);
23 void setHasChanges(bool value);
22
24
25 /// Refreshes the data displayed by the item from the catalogue
26 void refresh();
27
23 private:
28 private:
24 class CatalogueTreeWidgetItemPrivate;
29 class CatalogueTreeWidgetItemPrivate;
25 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
30 spimpl::unique_impl_ptr<CatalogueTreeWidgetItemPrivate> impl;
@@ -48,6 +48,9 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
48 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
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 CatalogueExplorer::~CatalogueExplorer()
56 CatalogueExplorer::~CatalogueExplorer()
@@ -6,11 +6,32
6 #include <DBEvent.h>
6 #include <DBEvent.h>
7 #include <DBTag.h>
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 CatalogueInspectorWidget::CatalogueInspectorWidget(QWidget *parent)
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 ui->setupUi(this);
19 ui->setupUi(this);
13 showPage(Page::Empty);
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 CatalogueInspectorWidget::~CatalogueInspectorWidget()
37 CatalogueInspectorWidget::~CatalogueInspectorWidget()
@@ -30,6 +51,10 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
30
51
31 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
52 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
32 {
53 {
54 impl->m_DisplayedEvent = event;
55
56 blockSignals(true);
57
33 showPage(Page::EventProperties);
58 showPage(Page::EventProperties);
34 ui->leEventName->setText(event->getName());
59 ui->leEventName->setText(event->getName());
35 ui->leEventMission->setText(event->getMission());
60 ui->leEventMission->setText(event->getMission());
@@ -46,11 +71,19 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
46
71
47 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
72 ui->dateTimeEventTStart->setDateTime(DateUtils::dateTime(event->getTStart()));
48 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
73 ui->dateTimeEventTEnd->setDateTime(DateUtils::dateTime(event->getTEnd()));
74
75 blockSignals(false);
49 }
76 }
50
77
51 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
78 void CatalogueInspectorWidget::setCatalogue(const std::shared_ptr<DBCatalogue> &catalogue)
52 {
79 {
80 impl->m_DisplayedCatalogue = catalogue;
81
82 blockSignals(true);
83
53 showPage(Page::CatalogueProperties);
84 showPage(Page::CatalogueProperties);
54 ui->leCatalogueName->setText(catalogue->getName());
85 ui->leCatalogueName->setText(catalogue->getName());
55 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
86 ui->leCatalogueAuthor->setText(catalogue->getAuthor());
87
88 blockSignals(false);
56 }
89 }
@@ -10,6 +10,8
10
10
11 #include <QMenu>
11 #include <QMenu>
12
12
13 Q_LOGGING_CATEGORY(LOG_CatalogueSideBarWidget, "CatalogueSideBarWidget")
14
13
15
14 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
16 constexpr auto ALL_EVENT_ITEM_TYPE = QTreeWidgetItem::UserType;
15 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
17 constexpr auto TRASH_ITEM_TYPE = QTreeWidgetItem::UserType + 1;
@@ -24,6 +26,9 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
24 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
26 QTreeWidgetItem *getDatabaseItem(const QString &name, QTreeWidget *treeWidget);
25 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
27 void addCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
26 QTreeWidgetItem *parentDatabaseItem);
28 QTreeWidgetItem *parentDatabaseItem);
29
30 CatalogueTreeWidgetItem *getCatalogueItem(const std::shared_ptr<DBCatalogue> &catalogue,
31 QTreeWidget *treeWidget) const;
27 };
32 };
28
33
29 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
34 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
@@ -97,6 +102,14 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
97
102
98 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
103 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
99 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, emitSelection);
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 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
114 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
102 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
115 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
@@ -108,6 +121,15 CatalogueSideBarWidget::~CatalogueSideBarWidget()
108 delete ui;
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 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
133 void CatalogueSideBarWidget::onContextMenuRequested(const QPoint &pos)
112 {
134 {
113 QMenu menu{this};
135 QMenu menu{this};
@@ -196,3 +218,30 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
196 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
218 catalogueItem->setIcon(0, QIcon{":/icones/catalogue.png"});
197 parentDatabaseItem->addChild(catalogueItem);
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 }
@@ -8,6 +8,9
8
8
9 const auto VALIDATION_BUTTON_ICON_SIZE = 12;
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 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
14 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
12
15
13 std::shared_ptr<DBCatalogue> m_Catalogue;
16 std::shared_ptr<DBCatalogue> m_Catalogue;
@@ -63,6 +66,7 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
63 void CatalogueTreeWidgetItem::setHasChanges(bool value)
66 void CatalogueTreeWidgetItem::setHasChanges(bool value)
64 {
67 {
65 if (value) {
68 if (value) {
69 if (treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) == nullptr) {
66 auto widet = new QWidget{treeWidget()};
70 auto widet = new QWidget{treeWidget()};
67
71
68 auto layout = new QHBoxLayout{widet};
72 auto layout = new QHBoxLayout{widet};
@@ -78,16 +82,22 void CatalogueTreeWidgetItem::setHasChanges(bool value)
78
82
79 auto btnDiscard = new QToolButton{widet};
83 auto btnDiscard = new QToolButton{widet};
80 btnDiscard->setIcon(QIcon{":/icones/discard"});
84 btnDiscard->setIcon(QIcon{":/icones/discard"});
81 btnDiscard->setIconSize(QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
85 btnDiscard->setIconSize(
86 QSize{VALIDATION_BUTTON_ICON_SIZE, VALIDATION_BUTTON_ICON_SIZE});
82 btnDiscard->setAutoRaise(true);
87 btnDiscard->setAutoRaise(true);
83 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
88 QObject::connect(btnDiscard, &QToolButton::clicked, [this]() { setHasChanges(false); });
84 layout->addWidget(btnDiscard);
89 layout->addWidget(btnDiscard);
85
90
86 treeWidget()->setItemWidget(this, 1, {widet});
91 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, {widet});
87 treeWidget()->resizeColumnToContents(1);
92 }
88 }
93 }
89 else {
94 else {
90 // Note: the widget is destroyed
95 // Note: the widget is destroyed
91 treeWidget()->setItemWidget(this, 1, nullptr);
96 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
97 }
92 }
98 }
99
100 void CatalogueTreeWidgetItem::refresh()
101 {
102 emitDataChanged();
93 }
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