##// END OF EJS Templates
Corrects the problem of refreshing synchronized graphs from TimeWidget (1)...
Corrects the problem of refreshing synchronized graphs from TimeWidget (1) Introduces graph flags to set options for the widget

File last commit:

r1315:7185ea8182da merge
r1325:87a145505c37
Show More
CatalogueEventsWidget.cpp
470 lines | 17.2 KiB | text/x-c | CppLexer
/ gui / src / Catalogue / CatalogueEventsWidget.cpp
Sub widget classes
r1130 #include "Catalogue/CatalogueEventsWidget.h"
#include "ui_CatalogueEventsWidget.h"
Display catalogues and events with CatalogueAPI
r1162 #include <Catalogue/CatalogueController.h>
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 #include <Catalogue/CatalogueEventsModel.h>
"Apply" and "cancel" buttons on an event
r1194 #include <Catalogue/CatalogueExplorerHelper.h>
Display catalogues and events with CatalogueAPI
r1162 #include <CatalogueDao.h>
#include <DBCatalogue.h>
#include <SqpApplication.h>
Retrieves zone names from the visualization
r1169 #include <Visualization/VisualizationTabWidget.h>
#include <Visualization/VisualizationWidget.h>
Time Zone Mode + prepare graph mode
r1171 #include <Visualization/VisualizationZoneWidget.h>
Display catalogues and events with CatalogueAPI
r1162
New tool dialog to select a zone on time and chart modes
r1168 #include <QDialog>
#include <QDialogButtonBox>
#include <QListWidget>
connect remove event button
r1296 #include <QMessageBox>
New tool dialog to select a zone on time and chart modes
r1168
Time Zone Mode + prepare graph mode
r1171 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
Display catalogues and events with CatalogueAPI
r1162
"Apply" and "cancel" buttons on an event
r1194 /// Fixed size of the validation column
const auto VALIDATION_COLUMN_SIZE = 35;
Skeleton to fill the inspector with the selection
r1140
Events
r1136 struct CatalogueEventsWidget::CatalogueEventsWidgetPrivate {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 CatalogueEventsModel *m_Model = nullptr;
Time Zone Mode + prepare graph mode
r1171 QStringList m_ZonesForTimeMode;
New tool dialog to select a zone on time and chart modes
r1168 QString m_ZoneForGraphMode;
Updates model after an event has been created through the colored zone
r1286 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
Fix creation of first event
r1311 bool m_AllEventDisplayed = false;
Methods to facilitate add/remove operations
r1167
Retrieves zone names from the visualization
r1169 VisualizationWidget *m_VisualizationWidget = nullptr;
store events with changes in the catalogue controller
r1292 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
Methods to facilitate add/remove operations
r1167 {
store events with changes in the catalogue controller
r1292 widget->ui->treeView->setSortingEnabled(false);
Methods to facilitate add/remove operations
r1167 m_Model->setEvents(events);
store events with changes in the catalogue controller
r1292 widget->ui->treeView->setSortingEnabled(true);
for (auto event : events) {
if (sqpApp->catalogueController().eventHasChanges(event)) {
auto index = m_Model->indexOf(event);
widget->setEventChanges(event, true);
}
}
Methods to facilitate add/remove operations
r1167 }
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 void addEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
Methods to facilitate add/remove operations
r1167 {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 treeView->setSortingEnabled(false);
Methods to facilitate add/remove operations
r1167 m_Model->addEvent(event);
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 treeView->setSortingEnabled(true);
Methods to facilitate add/remove operations
r1167 }
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 void removeEvent(const std::shared_ptr<DBEvent> &event, QTreeView *treeView)
Methods to facilitate add/remove operations
r1167 {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 treeView->setSortingEnabled(false);
Methods to facilitate add/remove operations
r1167 m_Model->removeEvent(event);
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 treeView->setSortingEnabled(true);
Methods to facilitate add/remove operations
r1167 }
Events
r1136
Retrieves zone names from the visualization
r1169 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
r1168 {
Retrieves zone names from the visualization
r1169 auto availableZones = getAvailableVisualizationZoneList();
if (availableZones.isEmpty()) {
return QStringList{};
}
New tool dialog to select a zone on time and chart modes
r1168 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
r1169 else {
result = selectedZones;
}
New tool dialog to select a zone on time and chart modes
r1168
return result;
}
Time Zone Mode + prepare graph mode
r1171
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 void updateForTimeMode(QTreeView *treeView)
Time Zone Mode + prepare graph mode
r1171 {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 auto selectedRows = treeView->selectionModel()->selectedRows();
Time Zone Mode + prepare graph mode
r1171
if (selectedRows.count() == 1) {
Edition of event products via the inspector
r1183 auto event = m_Model->getEvent(selectedRows.first());
Displays TStart & TEnd for events
r1185 if (event) {
if (m_VisualizationWidget) {
if (auto tab = m_VisualizationWidget->currentTabWidget()) {
for (auto zoneName : m_ZonesForTimeMode) {
if (auto zone = tab->getZoneWithName(zoneName)) {
SqpRange eventRange;
eventRange.m_TStart = event->getTStart();
eventRange.m_TEnd = event->getTEnd();
zone->setZoneRange(eventRange);
}
Time Zone Mode + prepare graph mode
r1171 }
}
Displays TStart & TEnd for events
r1185 else {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateTimeZone: no tab found in the visualization";
}
Time Zone Mode + prepare graph mode
r1171 }
else {
qCWarning(LOG_CatalogueEventsWidget())
Displays TStart & TEnd for events
r1185 << "updateTimeZone: visualization widget not found";
Time Zone Mode + prepare graph mode
r1171 }
}
}
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
r1182 void updateForGraphMode(QTreeView *treeView)
Time Zone Mode + prepare graph mode
r1171 {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 auto selectedRows = treeView->selectionModel()->selectedRows();
Time Zone Mode + prepare graph mode
r1171
if (selectedRows.count() == 1) {
Edition of event products via the inspector
r1183 auto event = m_Model->getEvent(selectedRows.first());
Time Zone Mode + prepare graph mode
r1171 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";
}
}
connect remove event button
r1296
void getSelectedItems(
QTreeView *treeView, QVector<std::shared_ptr<DBEvent> > &events,
QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > &eventProducts)
{
for (auto rowIndex : treeView->selectionModel()->selectedRows()) {
auto itemType = m_Model->itemTypeOf(rowIndex);
if (itemType == CatalogueEventsModel::ItemType::Event) {
events << m_Model->getEvent(rowIndex);
}
else if (itemType == CatalogueEventsModel::ItemType::EventProduct) {
eventProducts << qMakePair(m_Model->getParentEvent(rowIndex),
m_Model->getEventProduct(rowIndex));
}
}
}
New tool dialog to select a zone on time and chart modes
r1168 };
Events
r1136
Sub widget classes
r1130 CatalogueEventsWidget::CatalogueEventsWidget(QWidget *parent)
Events
r1136 : QWidget(parent),
ui(new Ui::CatalogueEventsWidget),
impl{spimpl::make_unique_impl<CatalogueEventsWidgetPrivate>()}
Sub widget classes
r1130 {
ui->setupUi(this);
Events
r1136
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 impl->m_Model = new CatalogueEventsModel{this};
ui->treeView->setModel(impl->m_Model);
TableModel for events
r1163
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 ui->treeView->setSortingEnabled(true);
ui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
ui->treeView->setDragEnabled(true);
TableModel for events
r1163
Events
r1136 connect(ui->btnTime, &QToolButton::clicked, [this](auto checked) {
if (checked) {
ui->btnChart->setChecked(false);
Time Zone Mode + prepare graph mode
r1171 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
r1182 impl->updateForTimeMode(ui->treeView);
Events
r1136 }
});
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
r1168 impl->m_ZoneForGraphMode
Retrieves zone names from the visualization
r1169 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false,
New tool dialog to select a zone on time and chart modes
r1168 this->mapToGlobal(ui->btnChart->frameGeometry().center()))
.value(0);
Time Zone Mode + prepare graph mode
r1171
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 impl->updateForGraphMode(ui->treeView);
Events
r1136 }
});
connect remove event button
r1296 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
Adaptation to the shared pointers of catalogue controller
r1176 QVector<std::shared_ptr<DBEvent> > events;
Edition of event products via the inspector
r1183 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
connect remove event button
r1296 impl->getSelectedItems(ui->treeView, events, eventProducts);
Edition of event products via the inspector
r1183
connect remove event button
r1296 if (!events.isEmpty() && eventProducts.isEmpty()) {
Edition of event products via the inspector
r1183
connect remove event button
r1296 if (QMessageBox::warning(this, tr("Remove Event(s)"),
tr("The selected event(s) will be completly removed "
"from the repository!\nAre you sure you want to continue?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
== QMessageBox::Yes) {
for (auto event : events) {
sqpApp->catalogueController().removeEvent(event);
impl->removeEvent(event, ui->treeView);
}
Edition of event products via the inspector
r1183 }
Manage inspector with multiple events selected
r1164 }
connect remove event button
r1296 });
fix refresh of events after a discard
r1300 connect(ui->treeView, &QTreeView::clicked, this, &CatalogueEventsWidget::emitSelection);
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&CatalogueEventsWidget::emitSelection);
Skeleton to fill the inspector with the selection
r1140
connect remove event button
r1296 ui->btnRemove->setEnabled(false); // Disabled by default when nothing is selected
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
auto isNotMultiSelection = ui->treeView->selectionModel()->selectedRows().count() <= 1;
Fixes
r1141 ui->btnChart->setEnabled(isNotMultiSelection);
ui->btnTime->setEnabled(isNotMultiSelection);
Time Zone Mode + prepare graph mode
r1171
if (isNotMultiSelection && ui->btnTime->isChecked()) {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 impl->updateForTimeMode(ui->treeView);
Time Zone Mode + prepare graph mode
r1171 }
else if (isNotMultiSelection && ui->btnChart->isChecked()) {
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 impl->updateForGraphMode(ui->treeView);
Time Zone Mode + prepare graph mode
r1171 }
connect remove event button
r1296
QVector<std::shared_ptr<DBEvent> > events;
QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
impl->getSelectedItems(ui->treeView, events, eventProducts);
ui->btnRemove->setEnabled(!events.isEmpty() && eventProducts.isEmpty());
Skeleton to fill the inspector with the selection
r1140 });
Basic interactions
r1138
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
small gui improvements
r1293 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags,
"Apply" and "cancel" buttons on an event
r1194 QHeaderView::Stretch);
ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
QHeaderView::Fixed);
small gui improvements
r1293 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
QHeaderView::Interactive);
"Apply" and "cancel" buttons on an event
r1194 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
VALIDATION_COLUMN_SIZE);
Change the event model to a treeview model + update the last version of CatalogueAPI
r1182 ui->treeView->header()->setSortIndicatorShown(true);
"Apply" and "cancel" buttons on an event
r1194
connect(impl->m_Model, &CatalogueEventsModel::modelSorted, [this]() {
auto allEvents = impl->m_Model->events();
for (auto event : allEvents) {
store events with changes in the catalogue controller
r1292 setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event));
"Apply" and "cancel" buttons on an event
r1194 }
});
Handle selection of trash and repository items
r1289
populateWithAllEvents();
Sub widget classes
r1130 }
CatalogueEventsWidget::~CatalogueEventsWidget()
{
delete ui;
}
Events
r1136
Retrieves zone names from the visualization
r1169 void CatalogueEventsWidget::setVisualizationWidget(VisualizationWidget *visualization)
{
impl->m_VisualizationWidget = visualization;
}
Updates model after an event has been created through the colored zone
r1286 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
{
impl->addEvent(event, ui->treeView);
}
Edition of events from the inspector
r1181 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
{
impl->m_Model->refreshEvent(event);
"Apply" and "cancel" buttons on an event
r1194
auto eventIndex = impl->m_Model->indexOf(event);
auto validationIndex
= eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
Some fixes
r1290 if (validationIndex.isValid()) {
if (hasChanges) {
if (ui->treeView->indexWidget(validationIndex) == nullptr) {
auto widget = CatalogueExplorerHelper::buildValidationWidget(
ui->treeView,
[this, event]() {
sqpApp->catalogueController().saveEvent(event);
setEventChanges(event, false);
},
Add discard method for event
r1298 [this, event]() {
Discard an added event remove it now.
r1314 bool removed = false;
sqpApp->catalogueController().discardEvent(event, removed);
if (removed) {
impl->m_Model->removeEvent(event);
}
else {
setEventChanges(event, false);
impl->m_Model->refreshEvent(event, true);
}
fix refresh of events after a discard
r1300 emitSelection();
Add discard method for event
r1298 });
Some fixes
r1290 ui->treeView->setIndexWidget(validationIndex, widget);
}
store events with changes in the catalogue controller
r1292 }
else {
// Note: the widget is destroyed
ui->treeView->setIndexWidget(validationIndex, nullptr);
Some fixes
r1290 }
"Apply" and "cancel" buttons on an event
r1194 }
else {
Updates model after an event has been created through the colored zone
r1286 qCWarning(LOG_CatalogueEventsWidget())
<< "setEventChanges: the event is not displayed in the model.";
"Apply" and "cancel" buttons on an event
r1194 }
Updates model after an event has been created through the colored zone
r1286 }
QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
{
return impl->m_DisplayedCatalogues;
}
bool CatalogueEventsWidget::isAllEventsDisplayed() const
{
Fix creation of first event
r1311 return impl->m_AllEventDisplayed;
Updates model after an event has been created through the colored zone
r1286 }
"Apply" and "cancel" buttons on an event
r1194
Updates model after an event has been created through the colored zone
r1286 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
{
return impl->m_Model->indexOf(event).isValid();
Edition of events from the inspector
r1181 }
Adaptation to the shared pointers of catalogue controller
r1176 void CatalogueEventsWidget::populateWithCatalogues(
const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
Basic interactions
r1138 {
Updates model after an event has been created through the colored zone
r1286 impl->m_DisplayedCatalogues = catalogues;
Fix creation of first event
r1311 impl->m_AllEventDisplayed = false;
Updates model after an event has been created through the colored zone
r1286
Multi selection of catalogues
r1165 QSet<QUuid> eventIds;
Adaptation to the shared pointers of catalogue controller
r1176 QVector<std::shared_ptr<DBEvent> > events;
Multi selection of catalogues
r1165
for (auto catalogue : catalogues) {
Adaptation to the shared pointers of catalogue controller
r1176 auto catalogueEvents = sqpApp->catalogueController().retrieveEventsFromCatalogue(catalogue);
Multi selection of catalogues
r1165 for (auto event : catalogueEvents) {
Adaptation to the shared pointers of catalogue controller
r1176 if (!eventIds.contains(event->getUniqId())) {
Multi selection of catalogues
r1165 events << event;
Adaptation to the shared pointers of catalogue controller
r1176 eventIds.insert(event->getUniqId());
Multi selection of catalogues
r1165 }
}
Display catalogues and events with CatalogueAPI
r1162 }
Basic interactions
r1138
store events with changes in the catalogue controller
r1292 impl->setEvents(events, this);
Events
r1136 }
Displays all events
r1192
void CatalogueEventsWidget::populateWithAllEvents()
{
Updates model after an event has been created through the colored zone
r1286 impl->m_DisplayedCatalogues.clear();
Fix creation of first event
r1311 impl->m_AllEventDisplayed = true;
Updates model after an event has been created through the colored zone
r1286
Displays all events
r1192 auto allEvents = sqpApp->catalogueController().retrieveAllEvents();
QVector<std::shared_ptr<DBEvent> > events;
for (auto event : allEvents) {
events << event;
}
store events with changes in the catalogue controller
r1292 impl->setEvents(events, this);
Displays all events
r1192 }
Updates model after an event has been created through the colored zone
r1286
Handle selection of trash and repository items
r1289 void CatalogueEventsWidget::clear()
{
impl->m_DisplayedCatalogues.clear();
Fix creation of first event
r1311 impl->m_AllEventDisplayed = false;
store events with changes in the catalogue controller
r1292 impl->setEvents({}, this);
Handle selection of trash and repository items
r1289 }
Updates model after an event has been created through the colored zone
r1286 void CatalogueEventsWidget::refresh()
{
Fix creation of first event
r1311 if (isAllEventsDisplayed()) {
Updates model after an event has been created through the colored zone
r1286 populateWithAllEvents();
}
Fix creation of first event
r1311 else if (!impl->m_DisplayedCatalogues.isEmpty()) {
Updates model after an event has been created through the colored zone
r1286 populateWithCatalogues(impl->m_DisplayedCatalogues);
}
}
fix refresh of events after a discard
r1300
void CatalogueEventsWidget::emitSelection()
{
QVector<std::shared_ptr<DBEvent> > events;
QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
impl->getSelectedItems(ui->treeView, events, eventProducts);
if (!events.isEmpty() && eventProducts.isEmpty()) {
emit eventsSelected(events);
}
else if (events.isEmpty() && !eventProducts.isEmpty()) {
emit eventProductsSelected(eventProducts);
}
else {
emit selectionCleared();
}
}