##// END OF EJS Templates
allow pan when click on zone...
allow pan when click on zone Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1349:3fc54ca0e4e0
r1383:e8413fdb1b68
Show More
CatalogueEventsWidget.cpp
615 lines | 22.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>
"Apply" and "cancel" buttons on an event
r1162 #include <Catalogue/CatalogueExplorerHelper.h>
Display catalogues and events with CatalogueAPI
r1129 #include <CatalogueDao.h>
#include <DBCatalogue.h>
Activate graph mode + create variable in selected zone...
r1290 #include <DBEventProduct.h>
#include <DataSource/DataSourceController.h>
Remove old graph from selected zones
r1291 #include <DataSource/DataSourceItem.h>
Display catalogues and events with CatalogueAPI
r1129 #include <SqpApplication.h>
Activate graph mode + create variable in selected zone...
r1290 #include <Variable/Variable.h>
All the codebase is modified to build with new Variable Controller...
r1348 #include <Variable/VariableController2.h>
Remove old graph from selected zones
r1291 #include <Visualization/VisualizationGraphWidget.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
Rework zone selection with graph & time mode as a poppup menu
r1322 #include <QActionGroup>
New tool dialog to select a zone on time and chart modes
r1135 #include <QDialog>
#include <QDialogButtonBox>
Add supp shortcut for Catalogues
r1314 #include <QKeyEvent>
New tool dialog to select a zone on time and chart modes
r1135 #include <QListWidget>
Rework zone selection with graph & time mode as a poppup menu
r1322 #include <QMenu>
connect remove event button
r1241 #include <QMessageBox>
New tool dialog to select a zone on time and chart modes
r1135
Time Zone Mode + prepare graph mode
r1138 Q_LOGGING_CATEGORY(LOG_CatalogueEventsWidget, "CatalogueEventsWidget")
Display catalogues and events with CatalogueAPI
r1129
refactoring + fix created graph range
r1292 /// Percentage added to the range of a event when it is displayed
const auto EVENT_RANGE_MARGE = 30; // in %
graph mode with a "New Zone"
r1323 const QString NEW_ZONE_TEXT = QStringLiteral("New Zone");
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;
Updates model after an event has been created through the colored zone
r1231 QVector<std::shared_ptr<DBCatalogue> > m_DisplayedCatalogues;
Fix creation of first event
r1257 bool m_AllEventDisplayed = false;
Activate graph mode + create variable in selected zone...
r1290 QVector<VisualizationGraphWidget *> m_CustomGraphs;
Methods to facilitate add/remove operations
r1134
Retrieves zone names from the visualization
r1136 VisualizationWidget *m_VisualizationWidget = nullptr;
store events with changes in the catalogue controller
r1237 void setEvents(const QVector<std::shared_ptr<DBEvent> > &events, CatalogueEventsWidget *widget)
Methods to facilitate add/remove operations
r1134 {
store events with changes in the catalogue controller
r1237 widget->ui->treeView->setSortingEnabled(false);
Move event in catalogue with Drag&Drop
r1308 m_Model->setSourceCatalogues(m_DisplayedCatalogues);
Methods to facilitate add/remove operations
r1134 m_Model->setEvents(events);
store events with changes in the catalogue controller
r1237 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
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,
graph mode with a "New Zone"
r1323 bool allowMultiSelection, bool addNewZoneOption, 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();
graph mode with a "New Zone"
r1323 if (!addNewZoneOption && availableZones.isEmpty()) {
Retrieves zone names from the visualization
r1136 return QStringList{};
}
Rework zone selection with graph & time mode as a poppup menu
r1322 QActionGroup actionGroup{parent};
actionGroup.setExclusive(!allowMultiSelection);
New tool dialog to select a zone on time and chart modes
r1135
graph mode with a "New Zone"
r1323 QVector<QAction *> zoneActions;
Rework zone selection with graph & time mode as a poppup menu
r1322 QMenu selectionMenu{parent};
graph mode with a "New Zone"
r1323
if (addNewZoneOption) {
availableZones.prepend(NEW_ZONE_TEXT);
}
Rework zone selection with graph & time mode as a poppup menu
r1322 selectionMenu.addSeparator();
New tool dialog to select a zone on time and chart modes
r1135 for (auto zone : availableZones) {
Rework zone selection with graph & time mode as a poppup menu
r1322 auto zoneAction = selectionMenu.addAction(zone);
zoneAction->setCheckable(true);
zoneAction->setChecked(selectedZones.contains(zone));
actionGroup.addAction(zoneAction);
zoneActions << zoneAction;
New tool dialog to select a zone on time and chart modes
r1135 }
graph mode with a "New Zone"
r1323 auto resultAction = selectionMenu.exec(QCursor::pos());
New tool dialog to select a zone on time and chart modes
r1135
QStringList result;
graph mode with a "New Zone"
r1323 if (resultAction == nullptr) {
Rework zone selection with graph & time mode as a poppup menu
r1322 result = selectedZones;
New tool dialog to select a zone on time and chart modes
r1135 }
Retrieves zone names from the visualization
r1136 else {
Rework zone selection with graph & time mode as a poppup menu
r1322 for (auto zoneAction : zoneActions) {
if (zoneAction->isChecked()) {
result << zoneAction->text();
}
}
Retrieves zone names from the visualization
r1136 }
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) {
Edition of event products via the inspector
r1150 auto event = m_Model->getEvent(selectedRows.first());
Displays TStart & TEnd for events
r1152 if (event) {
if (m_VisualizationWidget) {
if (auto tab = m_VisualizationWidget->currentTabWidget()) {
for (auto zoneName : m_ZonesForTimeMode) {
if (auto zone = tab->getZoneWithName(zoneName)) {
Renamed SqpRange to DateTimeRange, introduced VariableController2 to...
r1346 DateTimeRange eventRange;
Displays TStart & TEnd for events
r1152 eventRange.m_TStart = event->getTStart();
eventRange.m_TEnd = event->getTEnd();
zone->setZoneRange(eventRange);
}
Time Zone Mode + prepare graph mode
r1138 }
}
Displays TStart & TEnd for events
r1152 else {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateTimeZone: no tab found in the visualization";
}
Time Zone Mode + prepare graph mode
r1138 }
else {
qCWarning(LOG_CatalogueEventsWidget())
Displays TStart & TEnd for events
r1152 << "updateTimeZone: visualization widget not found";
Time Zone Mode + prepare graph mode
r1138 }
}
}
else {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateTimeZone: not compatible with multiple events selected";
}
}
Renamed SqpRange to DateTimeRange, introduced VariableController2 to...
r1346 QVector<DateTimeRange> getGraphRanges(const std::shared_ptr<DBEvent> &event)
refactoring + fix created graph range
r1292 {
// Retrieves the range of each product and the maximum size
Renamed SqpRange to DateTimeRange, introduced VariableController2 to...
r1346 QVector<DateTimeRange> graphRanges;
refactoring + fix created graph range
r1292 double maxDt = 0;
for (auto eventProduct : event->getEventProducts()) {
Renamed SqpRange to DateTimeRange, introduced VariableController2 to...
r1346 DateTimeRange eventRange;
refactoring + fix created graph range
r1292 eventRange.m_TStart = eventProduct.getTStart();
eventRange.m_TEnd = eventProduct.getTEnd();
graphRanges << eventRange;
auto dt = eventRange.m_TEnd - eventRange.m_TStart;
if (dt > maxDt) {
maxDt = dt;
}
}
// Adds the marge
maxDt *= (100.0 + EVENT_RANGE_MARGE) / 100.0;
// Corrects the graph ranges so that they all have the same size
Renamed SqpRange to DateTimeRange, introduced VariableController2 to...
r1346 QVector<DateTimeRange> correctedGraphRanges;
refactoring + fix created graph range
r1292 for (auto range : graphRanges) {
auto dt = range.m_TEnd - range.m_TStart;
auto diff = qAbs((maxDt - dt) / 2.0);
Renamed SqpRange to DateTimeRange, introduced VariableController2 to...
r1346 DateTimeRange correctedRange;
refactoring + fix created graph range
r1292 correctedRange.m_TStart = range.m_TStart - diff;
correctedRange.m_TEnd = range.m_TEnd + diff;
correctedGraphRanges << correctedRange;
}
return correctedGraphRanges;
}
Link between selection zone item and event
r1293 void updateForGraphMode(CatalogueEventsWidget *catalogueEventWidget)
Time Zone Mode + prepare graph mode
r1138 {
Link between selection zone item and event
r1293 auto selectedRows = catalogueEventWidget->ui->treeView->selectionModel()->selectedRows();
refactoring + fix created graph range
r1292 if (selectedRows.count() != 1) {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateGraphMode: not compatible with multiple events selected";
return;
}
Time Zone Mode + prepare graph mode
r1138
refactoring + fix created graph range
r1292 if (!m_VisualizationWidget) {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateGraphMode: visualization widget not found";
return;
}
auto event = m_Model->getEvent(selectedRows.first());
if (!event) {
// A event product is probably selected
qCInfo(LOG_CatalogueEventsWidget()) << "updateGraphMode: no events are selected";
return;
}
auto tab = m_VisualizationWidget->currentTabWidget();
if (!tab) {
qCWarning(LOG_CatalogueEventsWidget())
<< "updateGraphMode: no tab found in the visualization";
return;
}
Remove old graph from selected zones
r1291
graph mode with a "New Zone"
r1323 auto isNewZone = m_ZoneForGraphMode == NEW_ZONE_TEXT;
refactoring + fix created graph range
r1292 auto zone = tab->getZoneWithName(m_ZoneForGraphMode);
graph mode with a "New Zone"
r1323 if (!isNewZone && !zone) {
refactoring + fix created graph range
r1292 qCWarning(LOG_CatalogueEventsWidget()) << "updateGraphMode: zone not found";
return;
}
Remove old graph from selected zones
r1291
Closes all graphs of the selected zone in graph mode
r1307 // Closes the previous graph and delete the asociated variables
refactoring + fix created graph range
r1292 for (auto graph : m_CustomGraphs) {
graph->close();
All the codebase is modified to build with new Variable Controller...
r1348 auto variables = graph->variables();
for(const auto& variable:variables)
sqpApp->variableController().deleteVariable(variable);
refactoring + fix created graph range
r1292 }
m_CustomGraphs.clear();
Remove old graph from selected zones
r1291
Closes all graphs of the selected zone in graph mode
r1307 // Closes the remaining graphs inside the zone
graph mode with a "New Zone"
r1323 if (zone) {
zone->closeAllGraphs();
}
// Creates the zone if needed
if (isNewZone) {
zone = tab->createEmptyZone(0);
m_ZoneForGraphMode = zone->name();
}
Closes all graphs of the selected zone in graph mode
r1307
refactoring + fix created graph range
r1292 // Calculates the range of each graph which will be created
auto graphRange = getGraphRanges(event);
Activate graph mode + create variable in selected zone...
r1290
refactoring + fix created graph range
r1292 // Loops through the event products and create the graph
auto itRange = graphRange.cbegin();
for (auto eventProduct : event->getEventProducts()) {
auto productId = eventProduct.getProductId();
Remove old graph from selected zones
r1291
refactoring + fix created graph range
r1292 auto range = *itRange;
++itRange;
Remove old graph from selected zones
r1291
Renamed SqpRange to DateTimeRange, introduced VariableController2 to...
r1346 DateTimeRange productRange;
refactoring + fix created graph range
r1292 productRange.m_TStart = eventProduct.getTStart();
productRange.m_TEnd = eventProduct.getTEnd();
Remove old graph from selected zones
r1291
Link between selection zone item and event
r1293 auto context = new QObject{catalogueEventWidget};
refactoring + fix created graph range
r1292 QObject::connect(
All the codebase is modified to build with new Variable Controller...
r1348 &sqpApp->variableController(), &VariableController2::variableAdded, context,
Link between selection zone item and event
r1293 [this, catalogueEventWidget, zone, context, event, range, productRange,
productId](auto variable) {
Remove old graph from selected zones
r1291
refactoring + fix created graph range
r1292 if (variable->metadata().value(DataSourceItem::ID_DATA_KEY).toString()
== productId) {
auto graph = zone->createGraph(variable);
graph->setAutoRangeOnVariableInitialization(false);
Activate graph mode + create variable in selected zone...
r1290
Link between selection zone item and event
r1293 auto selectionZone
= graph->addSelectionZone(event->getName(), productRange);
emit catalogueEventWidget->selectionZoneAdded(event, productId,
selectionZone);
refactoring + fix created graph range
r1292 m_CustomGraphs << graph;
graph->setGraphRange(range, true);
// Removes the graph from the graph list if it is closed manually
QObject::connect(graph, &VisualizationGraphWidget::destroyed,
[this, graph]() { m_CustomGraphs.removeAll(graph); });
delete context; // removes the connection
Time Zone Mode + prepare graph mode
r1138 }
refactoring + fix created graph range
r1292 },
Qt::QueuedConnection);
QMetaObject::invokeMethod(&sqpApp->dataSourceController(),
"requestVariableFromProductIdKey", Qt::QueuedConnection,
Q_ARG(QString, productId));
Time Zone Mode + prepare graph mode
r1138 }
}
connect remove event button
r1241
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
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
Fix bug time precision with catalogue
r1315
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
graph mode with a "New Zone"
r1323 = impl->selectZone(this, impl->m_ZonesForTimeMode, true, false,
Time Zone Mode + prepare graph mode
r1138 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);
graph mode with a "New Zone"
r1323
New tool dialog to select a zone on time and chart modes
r1135 impl->m_ZoneForGraphMode
graph mode with a "New Zone"
r1323 = impl->selectZone(this, {impl->m_ZoneForGraphMode}, false, true,
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
Link between selection zone item and event
r1293 impl->updateForGraphMode(this);
Events
r1101 }
});
connect remove event button
r1241 connect(ui->btnRemove, &QToolButton::clicked, [this]() {
Adaptation to the shared pointers of catalogue controller
r1143 QVector<std::shared_ptr<DBEvent> > events;
Edition of event products via the inspector
r1150 QVector<QPair<std::shared_ptr<DBEvent>, std::shared_ptr<DBEventProduct> > > eventProducts;
connect remove event button
r1241 impl->getSelectedItems(ui->treeView, events, eventProducts);
Edition of event products via the inspector
r1150
connect remove event button
r1241 if (!events.isEmpty() && eventProducts.isEmpty()) {
Edition of event products via the inspector
r1150
Remove Event from Catalogue only unreferenced them
r1312 auto canRemoveEvent
= !this->isAllEventsDisplayed()
|| (QMessageBox::warning(
this, tr("Remove Event(s)"),
tr("The selected event(s) will be permanently removed "
"from the repository!\nAre you sure you want to continue?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
== QMessageBox::Yes);
if (canRemoveEvent) {
connect remove event button
r1241 for (auto event : events) {
Remove Event from Catalogue only unreferenced them
r1312 if (this->isAllEventsDisplayed()) {
Remove Event from catalogue statique only remove the reference.
r1313 sqpApp->catalogueController().removeEvent(event);
Remove Event from Catalogue only unreferenced them
r1312 impl->removeEvent(event, ui->treeView);
}
else {
Remove Event from catalogue statique only remove the reference.
r1313 QVector<std::shared_ptr<DBCatalogue> > modifiedCatalogues;
Remove Event from Catalogue only unreferenced them
r1312 for (auto catalogue : this->displayedCatalogues()) {
Remove Event from catalogue statique only remove the reference.
r1313 if (catalogue->removeEvent(event->getUniqId())) {
sqpApp->catalogueController().updateCatalogue(catalogue);
modifiedCatalogues << catalogue;
}
}
if (!modifiedCatalogues.empty()) {
emit eventCataloguesModified(modifiedCatalogues);
Remove Event from Catalogue only unreferenced them
r1312 }
}
impl->m_Model->removeEvent(event);
connect remove event button
r1241 }
Link between selection zone item and event
r1293
Remove Event from Catalogue only unreferenced them
r1312
Link between selection zone item and event
r1293 emit this->eventsRemoved(events);
Edition of event products via the inspector
r1150 }
Manage inspector with multiple events selected
r1131 }
connect remove event button
r1241 });
fix refresh of events after a discard
r1245 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
r1105
connect remove event button
r1241 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
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()) {
Link between selection zone item and event
r1293 impl->updateForGraphMode(this);
Time Zone Mode + prepare graph mode
r1138 }
connect remove event button
r1241
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
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);
small gui improvements
r1238 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Tags,
"Apply" and "cancel" buttons on an event
r1162 QHeaderView::Stretch);
ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Validation,
Fix hardcorded icon size for save and discard tool button
r1318 QHeaderView::ResizeToContents);
small gui improvements
r1238 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::Name,
QHeaderView::Interactive);
Fix bug time precision with catalogue
r1315 ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::TStart,
QHeaderView::ResizeToContents);
ui->treeView->header()->setSectionResizeMode((int)CatalogueEventsModel::Column::TEnd,
QHeaderView::ResizeToContents);
Change the event model to a treeview model + update the last version of CatalogueAPI
r1149 ui->treeView->header()->setSortIndicatorShown(true);
"Apply" and "cancel" buttons on an event
r1162
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
r1237 setEventChanges(event, sqpApp->catalogueController().eventHasChanges(event));
"Apply" and "cancel" buttons on an event
r1162 }
});
Handle selection of trash and repository items
r1234
populateWithAllEvents();
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;
}
Updates model after an event has been created through the colored zone
r1231 void CatalogueEventsWidget::addEvent(const std::shared_ptr<DBEvent> &event)
{
impl->addEvent(event, ui->treeView);
}
Edition of events from the inspector
r1148 void CatalogueEventsWidget::setEventChanges(const std::shared_ptr<DBEvent> &event, bool hasChanges)
{
impl->m_Model->refreshEvent(event);
"Apply" and "cancel" buttons on an event
r1162
auto eventIndex = impl->m_Model->indexOf(event);
auto validationIndex
= eventIndex.sibling(eventIndex.row(), (int)CatalogueEventsModel::Column::Validation);
Some fixes
r1235 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
r1243 [this, event]() {
Discard an added event remove it now.
r1260 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
r1245 emitSelection();
Add discard method for event
r1243 });
Some fixes
r1235 ui->treeView->setIndexWidget(validationIndex, widget);
Fix hardcorded icon size for save and discard tool button
r1318 ui->treeView->header()->resizeSection((int)CatalogueEventsModel::Column::Validation,
QHeaderView::ResizeToContents);
Some fixes
r1235 }
store events with changes in the catalogue controller
r1237 }
else {
// Note: the widget is destroyed
ui->treeView->setIndexWidget(validationIndex, nullptr);
Some fixes
r1235 }
"Apply" and "cancel" buttons on an event
r1162 }
else {
Updates model after an event has been created through the colored zone
r1231 qCWarning(LOG_CatalogueEventsWidget())
<< "setEventChanges: the event is not displayed in the model.";
"Apply" and "cancel" buttons on an event
r1162 }
Updates model after an event has been created through the colored zone
r1231 }
QVector<std::shared_ptr<DBCatalogue> > CatalogueEventsWidget::displayedCatalogues() const
{
return impl->m_DisplayedCatalogues;
}
bool CatalogueEventsWidget::isAllEventsDisplayed() const
{
Fix creation of first event
r1257 return impl->m_AllEventDisplayed;
Updates model after an event has been created through the colored zone
r1231 }
"Apply" and "cancel" buttons on an event
r1162
Updates model after an event has been created through the colored zone
r1231 bool CatalogueEventsWidget::isEventDisplayed(const std::shared_ptr<DBEvent> &event) const
{
return impl->m_Model->indexOf(event).isValid();
Edition of events from the inspector
r1148 }
Link between selection zone item and event
r1293 void CatalogueEventsWidget::refreshEvent(const std::shared_ptr<DBEvent> &event)
{
impl->m_Model->refreshEvent(event, true);
}
Adaptation to the shared pointers of catalogue controller
r1143 void CatalogueEventsWidget::populateWithCatalogues(
const QVector<std::shared_ptr<DBCatalogue> > &catalogues)
Basic interactions
r1103 {
Updates model after an event has been created through the colored zone
r1231 impl->m_DisplayedCatalogues = catalogues;
Fix creation of first event
r1257 impl->m_AllEventDisplayed = false;
Updates model after an event has been created through the colored zone
r1231
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
store events with changes in the catalogue controller
r1237 impl->setEvents(events, this);
Events
r1101 }
Displays all events
r1160
void CatalogueEventsWidget::populateWithAllEvents()
{
Updates model after an event has been created through the colored zone
r1231 impl->m_DisplayedCatalogues.clear();
Fix creation of first event
r1257 impl->m_AllEventDisplayed = true;
Updates model after an event has been created through the colored zone
r1231
Displays all events
r1160 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
r1237 impl->setEvents(events, this);
Displays all events
r1160 }
Updates model after an event has been created through the colored zone
r1231
Handle selection of trash and repository items
r1234 void CatalogueEventsWidget::clear()
{
impl->m_DisplayedCatalogues.clear();
Fix creation of first event
r1257 impl->m_AllEventDisplayed = false;
store events with changes in the catalogue controller
r1237 impl->setEvents({}, this);
Handle selection of trash and repository items
r1234 }
Updates model after an event has been created through the colored zone
r1231 void CatalogueEventsWidget::refresh()
{
Fix creation of first event
r1257 if (isAllEventsDisplayed()) {
Updates model after an event has been created through the colored zone
r1231 populateWithAllEvents();
}
Fix creation of first event
r1257 else if (!impl->m_DisplayedCatalogues.isEmpty()) {
Updates model after an event has been created through the colored zone
r1231 populateWithCatalogues(impl->m_DisplayedCatalogues);
}
}
fix refresh of events after a discard
r1245
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();
}
}
Add supp shortcut for Catalogues
r1314
void CatalogueEventsWidget::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Delete: {
ui->btnRemove->click();
}
default:
break;
}
}