##// END OF EJS Templates
Adds the ability to force an acquisition pending for an operation (3)...
Adds the ability to force an acquisition pending for an operation (3) Forces to wait acquisition when creating a variable

File last commit:

r1164:b6390f556418
r1218:6cdc10030ad4
Show More
CatalogueTreeWidgetItem.cpp
91 lines | 2.6 KiB | text/x-c | CppLexer
/ gui / src / Catalogue / CatalogueTreeWidgetItem.cpp
Display catalogues and events with CatalogueAPI
r1129 #include "Catalogue/CatalogueTreeWidgetItem.h"
"Apply" and "cancel" buttons on an event
r1162 #include <Catalogue/CatalogueExplorerHelper.h>
Display catalogues and events with CatalogueAPI
r1129
Adaptation to last version of catalogue controller
r1164 #include <Catalogue/CatalogueController.h>
#include <SqpApplication.h>
Display of the save & cancel button next to a catalogue
r1142 #include <memory>
Adaptation to the shared pointers of catalogue controller
r1143 #include <DBCatalogue.h>
Display of the save & cancel button next to a catalogue
r1142
Edition of catalogues from the inspector
r1147 /// Column in the tree widget where the apply and cancel buttons must appear
const auto APPLY_CANCEL_BUTTONS_COLUMN = 1;
Display catalogues and events with CatalogueAPI
r1129 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
Adaptation to the shared pointers of catalogue controller
r1143 std::shared_ptr<DBCatalogue> m_Catalogue;
Display catalogues and events with CatalogueAPI
r1129
Adaptation to the shared pointers of catalogue controller
r1143 CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
{
}
Display catalogues and events with CatalogueAPI
r1129 };
Adaptation to the shared pointers of catalogue controller
r1143 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
Display catalogues and events with CatalogueAPI
r1129 : QTreeWidgetItem(type),
impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
{
Rename a catalogue
r1140 setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
Display catalogues and events with CatalogueAPI
r1129 }
QVariant CatalogueTreeWidgetItem::data(int column, int role) const
{
Display of the save & cancel button next to a catalogue
r1142 if (column == 0) {
switch (role) {
case Qt::EditRole: // fallthrough
case Qt::DisplayRole:
Adaptation to the shared pointers of catalogue controller
r1143 return impl->m_Catalogue->getName();
Display of the save & cancel button next to a catalogue
r1142 default:
break;
}
Display catalogues and events with CatalogueAPI
r1129 }
return QTreeWidgetItem::data(column, role);
}
Rename a catalogue
r1140 void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value)
{
if (role == Qt::EditRole && column == 0) {
auto newName = value.toString();
Adaptation to the shared pointers of catalogue controller
r1143 if (newName != impl->m_Catalogue->getName()) {
Display of the save & cancel button next to a catalogue
r1142 setText(0, newName);
Adaptation to the shared pointers of catalogue controller
r1143 impl->m_Catalogue->setName(newName);
Adaptation to last version of catalogue controller
r1164 sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue);
Display of the save & cancel button next to a catalogue
r1142 setHasChanges(true);
}
Rename a catalogue
r1140 }
else {
QTreeWidgetItem::setData(column, role, value);
}
}
Adaptation to the shared pointers of catalogue controller
r1143 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
Display catalogues and events with CatalogueAPI
r1129 {
return impl->m_Catalogue;
}
Display of the save & cancel button next to a catalogue
r1142
void CatalogueTreeWidgetItem::setHasChanges(bool value)
{
if (value) {
"Apply" and "cancel" buttons on an event
r1162 if (!hasChanges()) {
auto widget = CatalogueExplorerHelper::buildValidationWidget(
treeWidget(), [this]() { setHasChanges(false); },
[this]() { setHasChanges(false); });
treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, widget);
Edition of catalogues from the inspector
r1147 }
Display of the save & cancel button next to a catalogue
r1142 }
else {
// Note: the widget is destroyed
Edition of catalogues from the inspector
r1147 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
Display of the save & cancel button next to a catalogue
r1142 }
}
Edition of catalogues from the inspector
r1147
"Apply" and "cancel" buttons on an event
r1162 bool CatalogueTreeWidgetItem::hasChanges()
{
return treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) != nullptr;
}
Edition of catalogues from the inspector
r1147 void CatalogueTreeWidgetItem::refresh()
{
emitDataChanged();
}