##// END OF EJS Templates
Change the event model to a treeview model + update the last version of CatalogueAPI
Change the event model to a treeview model + update the last version of CatalogueAPI

File last commit:

r1149:c352dc0e2afa
r1149:c352dc0e2afa
Show More
CatalogueEventsWidget.cpp
296 lines | 10.5 KiB | text/x-c | CppLexer
/ gui / src / Catalogue / CatalogueEventsWidget.cpp
Sub widget classes
r1095 #include "Catalogue/CatalogueEventsWidget.h"
#include "ui_CatalogueEventsWidget.h"
Display catalogues and events with CatalogueAPI
r1129 #include <Catalogue/CatalogueController.h>
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 #include <Catalogue/CatalogueEventsModel.h>
Display catalogues and events with CatalogueAPI
r1129 #include <CatalogueDao.h>
#include <DBCatalogue.h>
#include <SqpApplication.h>
Retrieves zone names from the visualization
r1136 #include <Visualization/VisualizationTabWidget.h>
#include <Visualization/VisualizationWidget.h>
Time Zone Mode + prepare graph mode
r1138 #include <Visualization/VisualizationZoneWidget.h>
Display catalogues and events with CatalogueAPI
r1129
New tool dialog to select a zone on time and chart modes
r1135 #include <QDialog>
#include <QDialogButtonBox>
#include <QListWidget>
Time Zone Mode + prepare graph mode
r1138 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
Display catalogues and events with CatalogueAPI
r1129
/// Format of the dates appearing in the label of a cursor
const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss");
Skeleton to fill the inspector with the selection
r1105
Events
r1101 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 CatalogueEventsModel *m_Model = nullptr;
Time Zone Mode + prepare graph mode
r1138 QStringList m_ZonesForTimeMode;
New tool dialog to select a zone on time and chart modes
r1135 QString m_ZoneForGraphMode;
Methods to facilitate add/remove operations
r1134
Retrieves zone names from the visualization
r1136 VisualizationWidget *m_VisualizationWidget = nullptr;
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, QTreeView *treeView)
Methods to facilitate add/remove operations
r1134 {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 treeView->setSortingEnabled(false);
Methods to facilitate add/remove operations
r1134 m_Model->setEvents(events);
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 treeView->setSortingEnabled(true);
Methods to facilitate add/remove operations
r1134 }
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
Methods to facilitate add/remove operations
r1134 {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 treeView->setSortingEnabled(false);
Methods to facilitate add/remove operations
r1134 m_Model->addEvent(event);
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 treeView->setSortingEnabled(true);
Methods to facilitate add/remove operations
r1134 }
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
Methods to facilitate add/remove operations
r1134 {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 treeView->setSortingEnabled(false);
Methods to facilitate add/remove operations
r1134 m_Model->removeEvent(event);
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 treeView->setSortingEnabled(true);
Methods to facilitate add/remove operations
r1134 }
Events
r1101
Retrieves zone names from the visualization
r1136 QStringList getAvailableVisualizationZoneList() const
{
if (m_VisualizationWidget) {
if (auto tab = m_VisualizationWidget->currentTabWidget()) {
return tab->availableZoneWidgets();
}
}
return QStringList{};
}
QStringList selectZone(QWidget *parent, const QStringList &selectedZones,
bool allowMultiSelection, const QPoint &location)
New tool dialog to select a zone on time and chart modes
r1135 {
Retrieves zone names from the visualization
r1136 auto availableZones = getAvailableVisualizationZoneList();
if (availableZones.isEmpty()) {
return QStringList{};
}
New tool dialog to select a zone on time and chart modes
r1135 QDialog d(parent, Qt::Tool);
d.setWindowTitle("Choose a zone");
auto layout = new QVBoxLayout{&d};
layout->setContentsMargins(0, 0, 0, 0);
auto listWidget = new QListWidget{&d};
layout->addWidget(listWidget);
QSet<QListWidgetItem *> checkedItems;
for (auto zone : availableZones) {
auto item = new QListWidgetItem{zone};
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
if (selectedZones.contains(zone)) {
item->setCheckState(Qt::Checked);
checkedItems << item;
}
else {
item->setCheckState(Qt::Unchecked);
}
listWidget->addItem(item);
}
auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok, &d};
layout->addWidget(buttonBox);
QObject::connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
QObject::connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
QObject::connect(listWidget, &QListWidget::itemChanged,
[&checkedItems, allowMultiSelection, listWidget](auto item) {
if (item->checkState() == Qt::Checked) {
if (!allowMultiSelection) {
for (auto checkedItem : checkedItems) {
listWidget->blockSignals(true);
checkedItem->setCheckState(Qt::Unchecked);
listWidget->blockSignals(false);
}
checkedItems.clear();
}
checkedItems << item;
}
else {
checkedItems.remove(item);
}
});
QStringList result;
d.setMinimumWidth(120);
d.resize(d.minimumSizeHint());
d.move(location);
if (d.exec() == QDialog::Accepted) {
for (auto item : checkedItems) {
result += item->text();
}
}
Retrieves zone names from the visualization
r1136 else {
result = selectedZones;
}
New tool dialog to select a zone on time and chart modes
r1135
return result;
}
Time Zone Mode + prepare graph mode
r1138
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 void updateForTimeMode(QTreeView *treeView)
Time Zone Mode + prepare graph mode
r1138 {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 auto selectedRows = treeView->selectionModel()->selectedRows();
Time Zone Mode + prepare graph mode
r1138
if (selectedRows.count() == 1) {
auto event = m_Model->getEvent(selectedRows.first().row());
if (m_VisualizationWidget) {
if (auto tab = m_VisualizationWidget->currentTabWidget()) {
for (auto zoneName : m_ZonesForTimeMode) {
if (auto zone = tab->getZoneWithName(zoneName)) {
SqpRange eventRange;
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 // eventRange.m_TStart = event->getTStart();
// eventRange.m_TEnd = event->getTEnd();
Time Zone Mode + prepare graph mode
r1138 zone->setZoneRange(eventRange);
}
}
}
else {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateTimeZone: no tab found in the visualization";
}
}
else {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateTimeZone: visualization widget not found";
}
}
else {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateTimeZone: not compatible with multiple events selected";
}
}
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 void updateForGraphMode(QTreeView *treeView)
Time Zone Mode + prepare graph mode
r1138 {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 auto selectedRows = treeView->selectionModel()->selectedRows();
Time Zone Mode + prepare graph mode
r1138
if (selectedRows.count() == 1) {
auto event = m_Model->getEvent(selectedRows.first().row());
if (m_VisualizationWidget) {
if (auto tab = m_VisualizationWidget->currentTabWidget()) {
if (auto zone = tab->getZoneWithName(m_ZoneForGraphMode)) {
// TODO
}
}
else {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateGraphMode: no tab found in the visualization";
}
}
else {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateGraphMode: visualization widget not found";
}
}
else {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateGraphMode: not compatible with multiple events selected";
}
}
New tool dialog to select a zone on time and chart modes
r1135 };
Events
r1101
Sub widget classes
r1095 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
Events
r1101 : QWidget(parent),
ui(new Ui::CatalogueEventsWidget),
impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
Sub widget classes
r1095 {
ui->setupUi(this);
Events
r1101
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 impl->m_Model = new CatalogueEventsModel{this};
ui->treeView->setModel(impl->m_Model);
TableModel for events
r1130
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 ui->treeView->setSortingEnabled(true);
ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
ui->treeView->setDragEnabled(true);
TableModel for events
r1130
Events
r1101 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
if (checked) {
ui->btnChart->setChecked(false);
Time Zone Mode + prepare graph mode
r1138 impl->m_ZonesForTimeMode
= impl->selectZone(this, impl->m_ZonesForTimeMode, true,
this->mapToGlobal(ui->btnTime->frameGeometry().center()));
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 impl->updateForTimeMode(ui->treeView);
Events
r1101 }
});
connect(ui->btnChart, &QToolButton::clicked, [this](auto checked) {
if (checked) {
ui->btnTime->setChecked(false);
New tool dialog to select a zone on time and chart modes
r1135 impl->m_ZoneForGraphMode
Retrieves zone names from the visualization
r1136 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
New tool dialog to select a zone on time and chart modes
r1135 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
.value(0);
Time Zone Mode + prepare graph mode
r1138
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 impl->updateForGraphMode(ui->treeView);
Events
r1101 }
});
Multi selection of catalogues
r1132 auto emitSelection = [this]() {
Adaptation to the shared pointers of catalogue controller
r1143 QVector<std::shared_ptr<DBEvent> > events;
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 for (auto rowIndex : ui->treeView->selectionModel()->selectedRows()) {
Manage inspector with multiple events selected
r1131 events << impl->m_Model->getEvent(rowIndex.row());
}
emit this->eventsSelected(events);
Multi selection of catalogues
r1132 };
Skeleton to fill the inspector with the selection
r1105
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 connect(ui->treeView, &QTreeView::clicked, emitSelection);
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, emitSelection);
Skeleton to fill the inspector with the selection
r1105
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
Fixes
r1106 ui->btnChart->setEnabled(isNotMultiSelection);
ui->btnTime->setEnabled(isNotMultiSelection);
Time Zone Mode + prepare graph mode
r1138
if (isNotMultiSelection && ui->btnTime->isChecked()) {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 impl->updateForTimeMode(ui->treeView);
Time Zone Mode + prepare graph mode
r1138 }
else if (isNotMultiSelection && ui->btnChart->isChecked()) {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 impl->updateForGraphMode(ui->treeView);
Time Zone Mode + prepare graph mode
r1138 }
Skeleton to fill the inspector with the selection
r1105 });
Basic interactions
r1103
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->treeView->header()->setSortIndicatorShown(true);
Sub widget classes
r1095 }
CatalogueEventsWidget::~CatalogueEventsWidget()
{
delete ui;
}
Events
r1101
Retrieves zone names from the visualization
r1136 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
{
impl->m_VisualizationWidget = visualization;
}
Edition of events from the inspector
r1148 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
{
impl->m_Model->refreshEvent(event);
}
Adaptation to the shared pointers of catalogue controller
r1143 void CatalogueEventsWidget::populateWithCatalogues(
const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
Basic interactions
r1103 {
Multi selection of catalogues
r1132 QSet<QUuid> eventIds;
Adaptation to the shared pointers of catalogue controller
r1143 QVector<std::shared_ptr<DBEvent> > events;
Multi selection of catalogues
r1132
for (auto catalogue : catalogues) {
Adaptation to the shared pointers of catalogue controller
r1143 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
Multi selection of catalogues
r1132 for (auto event : catalogueEvents) {
Adaptation to the shared pointers of catalogue controller
r1143 if (!eventIds.contains(event->getUniqId())) {
Multi selection of catalogues
r1132 events << event;
Adaptation to the shared pointers of catalogue controller
r1143 eventIds.insert(event->getUniqId());
Multi selection of catalogues
r1132 }
}
Display catalogues and events with CatalogueAPI
r1129 }
Basic interactions
r1103
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 impl->setEvents(events, ui->treeView);
Events
r1101 }