##// END OF EJS Templates
Multi selection of catalogues
trabillard -
r1165:13f4a3063503
parent child
Show More
@@ -22,7 +22,7 public:
22 virtual ~CatalogueEventsWidget();
22 virtual ~CatalogueEventsWidget();
23
23
24 public slots:
24 public slots:
25 void populateWithCatalogue(const DBCatalogue &catalogue);
25 void populateWithCatalogues(const QVector<DBCatalogue> &catalogues);
26
26
27 private:
27 private:
28 Ui::CatalogueEventsWidget *ui;
28 Ui::CatalogueEventsWidget *ui;
@@ -15,9 +15,11 class CatalogueSideBarWidget : public QWidget {
15 Q_OBJECT
15 Q_OBJECT
16
16
17 signals:
17 signals:
18 void catalogueSelected(const DBCatalogue &catalogue);
18 void catalogueSelected(const QVector<DBCatalogue> &catalogues);
19 void databaseSelected(const QStringList &databases);
19 void allEventsSelected();
20 void allEventsSelected();
20 void trashSelected();
21 void trashSelected();
22 void selectionCleared();
21
23
22 public:
24 public:
23 explicit CatalogueSideBarWidget(QWidget *parent = 0);
25 explicit CatalogueSideBarWidget(QWidget *parent = 0);
@@ -41,23 +41,17 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
41 }
41 }
42 });
42 });
43
43
44 connect(ui->tableView, &QTableView::clicked, [this](auto index) {
44 auto emitSelection = [this]() {
45 QVector<DBEvent> events;
45 QVector<DBEvent> events;
46 for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) {
46 for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) {
47 events << impl->m_Model->getEvent(rowIndex.row());
47 events << impl->m_Model->getEvent(rowIndex.row());
48 }
48 }
49
49
50 emit this->eventsSelected(events);
50 emit this->eventsSelected(events);
51 });
51 };
52
53 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
54 QVector<DBEvent> events;
55 for (auto rowIndex : ui->tableView->selectionModel()->selectedRows()) {
56 events << impl->m_Model->getEvent(rowIndex.row());
57 }
58
52
59 emit this->eventsSelected(events);
53 connect(ui->tableView, &QTableView::clicked, emitSelection);
60 });
54 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
61
55
62 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
56 connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
63 auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1;
57 auto isNotMultiSelection = ui->tableView->selectionModel()->selectedRows().count() <= 1;
@@ -75,17 +69,24 CatalogueEventsWidget::~CatalogueEventsWidget()
75 delete ui;
69 delete ui;
76 }
70 }
77
71
78 void CatalogueEventsWidget::populateWithCatalogue(const DBCatalogue &catalogue)
72 void CatalogueEventsWidget::populateWithCatalogues(const QVector<DBCatalogue> &catalogues)
79 {
73 {
80 auto &dao = sqpApp->catalogueController().getDao();
74 auto &dao = sqpApp->catalogueController().getDao();
81 auto events = dao.getCatalogueEvents(catalogue);
82
75
83 QVector<DBEvent> eventVector;
76 QSet<QUuid> eventIds;
84 for (auto event : events) {
77 QVector<DBEvent> events;
85 eventVector << event;
78
79 for (auto catalogue : catalogues) {
80 auto catalogueEvents = dao.getCatalogueEvents(catalogue);
81 for (auto event : catalogueEvents) {
82 if (!eventIds.contains(event.getUniqId())) {
83 events << event;
84 eventIds.insert(event.getUniqId());
85 }
86 }
86 }
87 }
87
88
88 ui->tableView->setSortingEnabled(false);
89 ui->tableView->setSortingEnabled(false);
89 impl->m_Model->setEvents(eventVector);
90 impl->m_Model->setEvents(events);
90 ui->tableView->setSortingEnabled(true);
91 ui->tableView->setSortingEnabled(true);
91 }
92 }
@@ -10,11 +10,30 CatalogueExplorer::CatalogueExplorer(QWidget *parent)
10 {
10 {
11 ui->setupUi(this);
11 ui->setupUi(this);
12
12
13 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogue) {
13 connect(ui->catalogues, &CatalogueSideBarWidget::catalogueSelected, [this](auto catalogues) {
14 ui->inspector->setCatalogue(catalogue);
14 if (catalogues.count() == 1) {
15 ui->events->populateWithCatalogue(catalogue);
15 ui->inspector->setCatalogue(catalogues.first());
16 }
17 else {
18 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
19 }
20
21 ui->events->populateWithCatalogues(catalogues);
16 });
22 });
17
23
24 connect(ui->catalogues, &CatalogueSideBarWidget::databaseSelected, [this](auto databases) {
25 ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty);
26 });
27
28 connect(ui->catalogues, &CatalogueSideBarWidget::trashSelected,
29 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
30
31 connect(ui->catalogues, &CatalogueSideBarWidget::allEventsSelected,
32 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
33
34 connect(ui->catalogues, &CatalogueSideBarWidget::selectionCleared,
35 [this]() { ui->inspector->showPage(CatalogueInspectorWidget::Page::Empty); });
36
18 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
37 connect(ui->events, &CatalogueEventsWidget::eventsSelected, [this](auto events) {
19 if (events.count() == 1) {
38 if (events.count() == 1) {
20 ui->inspector->setEvent(events.first());
39 ui->inspector->setEvent(events.first());
@@ -32,22 +32,60 CatalogueSideBarWidget::CatalogueSideBarWidget(QWidget *parent)
32 ui->setupUi(this);
32 ui->setupUi(this);
33 impl->configureTreeWidget(ui->treeWidget);
33 impl->configureTreeWidget(ui->treeWidget);
34
34
35 auto emitSelection = [this](auto item) {
35 auto emitSelection = [this]() {
36 switch (item->type()) {
36
37 auto selectedItems = ui->treeWidget->selectedItems();
38 if (selectedItems.isEmpty()) {
39 emit this->selectionCleared();
40 }
41 else {
42 QVector<DBCatalogue> catalogues;
43 QStringList databases;
44 int selectionType = selectedItems.first()->type();
45
46 for (auto item : ui->treeWidget->selectedItems()) {
47 if (item->type() == selectionType) {
48 switch (selectionType) {
37 case CATALOGUE_ITEM_TYPE:
49 case CATALOGUE_ITEM_TYPE:
38 emit this->catalogueSelected(
50 catalogues.append(
39 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
51 static_cast<CatalogueTreeWidgetItem *>(item)->catalogue());
40 break;
52 break;
53 case DATABASE_ITEM_TYPE:
54 selectionType = DATABASE_ITEM_TYPE;
55 databases.append(item->text(0));
56 case ALL_EVENT_ITEM_TYPE: // fallthrough
57 case TRASH_ITEM_TYPE: // fallthrough
58 default:
59 break;
60 }
61 }
62 else {
63 // Incoherent multi selection
64 selectionType = -1;
65 break;
66 }
67 }
68
69 switch (selectionType) {
70 case CATALOGUE_ITEM_TYPE:
71 emit this->catalogueSelected(catalogues);
72 break;
73 case DATABASE_ITEM_TYPE:
74 emit this->databaseSelected(databases);
75 break;
41 case ALL_EVENT_ITEM_TYPE:
76 case ALL_EVENT_ITEM_TYPE:
42 emit this->allEventsSelected();
77 emit this->allEventsSelected();
43 break;
78 break;
44 case TRASH_ITEM_TYPE:
79 case TRASH_ITEM_TYPE:
45 emit this->trashSelected();
80 emit this->trashSelected();
46 break;
81 break;
47 case DATABASE_ITEM_TYPE:
48 default:
82 default:
83 emit this->selectionCleared();
49 break;
84 break;
50 }
85 }
86 }
87
88
51 };
89 };
52
90
53 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
91 connect(ui->treeWidget, &QTreeWidget::itemClicked, emitSelection);
@@ -34,7 +34,7
34 <string>+</string>
34 <string>+</string>
35 </property>
35 </property>
36 <property name="icon">
36 <property name="icon">
37 <iconset>
37 <iconset resource="../../resources/sqpguiresources.qrc">
38 <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset>
38 <normaloff>:/icones/add.png</normaloff>:/icones/add.png</iconset>
39 </property>
39 </property>
40 <property name="autoRaise">
40 <property name="autoRaise">
@@ -48,7 +48,7
48 <string> - </string>
48 <string> - </string>
49 </property>
49 </property>
50 <property name="icon">
50 <property name="icon">
51 <iconset>
51 <iconset resource="../../resources/sqpguiresources.qrc">
52 <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset>
52 <normaloff>:/icones/remove.png</normaloff>:/icones/remove.png</iconset>
53 </property>
53 </property>
54 <property name="autoRaise">
54 <property name="autoRaise">
@@ -73,6 +73,9
73 </item>
73 </item>
74 <item>
74 <item>
75 <widget class="QTreeWidget" name="treeWidget">
75 <widget class="QTreeWidget" name="treeWidget">
76 <property name="selectionMode">
77 <enum>QAbstractItemView::ExtendedSelection</enum>
78 </property>
76 <attribute name="headerVisible">
79 <attribute name="headerVisible">
77 <bool>false</bool>
80 <bool>false</bool>
78 </attribute>
81 </attribute>
@@ -85,6 +88,9
85 </item>
88 </item>
86 </layout>
89 </layout>
87 </widget>
90 </widget>
88 <resources/>
91 <resources>
92 <include location="../../resources/sqpguiresources.qrc"/>
93 <include location="../../resources/sqpguiresources.qrc"/>
94 </resources>
89 <connections/>
95 <connections/>
90 </ui>
96 </ui>
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