##// END OF EJS Templates
Edition of catalogues from the inspector
trabillard -
r1180:938a31670f5f
parent child
Show More
@@ -1,6 +1,7
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
@@ -14,6 +15,10 class DBEvent;
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();
@@ -31,6 +36,9 public slots:
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
@@ -2,6 +2,7
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
@@ -11,6 +12,8 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
@@ -25,6 +28,8 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
@@ -18,8 +18,13 public:
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;
@@ -48,6 +48,9 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
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()
@@ -6,11 +6,32
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()
@@ -30,6 +51,10 CatalogueInspectorWidget::Page CatalogueInspectorWidget::currentPage() const
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());
@@ -46,11 +71,19 void CatalogueInspectorWidget::setEvent(const std::shared_ptr<DBEvent> &event)
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 }
@@ -10,6 +10,8
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;
@@ -24,6 +26,9 struct CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate {
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)
@@ -97,6 +102,14 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
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,
@@ -108,6 +121,15 CatalogueSideBarWidget::~CatalogueSideBarWidget()
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};
@@ -196,3 +218,30 void CatalogueSideBarWidget::CatalogueSideBarWidgetPrivate::addCatalogueItem(
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 }
@@ -8,6 +8,9
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;
@@ -63,31 +66,38 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
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