##// END OF EJS Templates
Addd save methods. Fix bug with work repository suffix handling
Addd save methods. Fix bug with work repository suffix handling

File last commit:

r1196:b6390f556418
r1279:4e7a8f2af91d
Show More
CatalogueTreeWidgetItem.cpp
91 lines | 2.6 KiB | text/x-c | CppLexer
/ gui / src / Catalogue / CatalogueTreeWidgetItem.cpp
Display catalogues and events with CatalogueAPI
r1162 #include "Catalogue/CatalogueTreeWidgetItem.h"
"Apply" and "cancel" buttons on an event
r1194 #include <Catalogue/CatalogueExplorerHelper.h>
Display catalogues and events with CatalogueAPI
r1162
Adaptation to last version of catalogue controller
r1196 #include <Catalogue/CatalogueController.h>
#include <SqpApplication.h>
Display of the save & cancel button next to a catalogue
r1175 #include <memory>
Adaptation to the shared pointers of catalogue controller
r1176 #include <DBCatalogue.h>
Display of the save & cancel button next to a catalogue
r1175
Edition of catalogues from the inspector
r1180 /// 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
r1162 struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
Adaptation to the shared pointers of catalogue controller
r1176 std::shared_ptr<DBCatalogue> m_Catalogue;
Display catalogues and events with CatalogueAPI
r1162
Adaptation to the shared pointers of catalogue controller
r1176 CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
{
}
Display catalogues and events with CatalogueAPI
r1162 };
Adaptation to the shared pointers of catalogue controller
r1176 CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
Display catalogues and events with CatalogueAPI
r1162 : QTreeWidgetItem(type),
impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
{
Rename a catalogue
r1173 setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
Display catalogues and events with CatalogueAPI
r1162 }
QVariant CatalogueTreeWidgetItem::data(int column, int role) const
{
Display of the save & cancel button next to a catalogue
r1175 if (column == 0) {
switch (role) {
case Qt::EditRole: // fallthrough
case Qt::DisplayRole:
Adaptation to the shared pointers of catalogue controller
r1176 return impl->m_Catalogue->getName();
Display of the save & cancel button next to a catalogue
r1175 default:
break;
}
Display catalogues and events with CatalogueAPI
r1162 }
return QTreeWidgetItem::data(column, role);
}
Rename a catalogue
r1173 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
r1176 if (newName != impl->m_Catalogue->getName()) {
Display of the save & cancel button next to a catalogue
r1175 setText(0, newName);
Adaptation to the shared pointers of catalogue controller
r1176 impl->m_Catalogue->setName(newName);
Adaptation to last version of catalogue controller
r1196 sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue);
Display of the save & cancel button next to a catalogue
r1175 setHasChanges(true);
}
Rename a catalogue
r1173 }
else {
QTreeWidgetItem::setData(column, role, value);
}
}
Adaptation to the shared pointers of catalogue controller
r1176 std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
Display catalogues and events with CatalogueAPI
r1162 {
return impl->m_Catalogue;
}
Display of the save & cancel button next to a catalogue
r1175
void CatalogueTreeWidgetItem::setHasChanges(bool value)
{
if (value) {
"Apply" and "cancel" buttons on an event
r1194 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
r1180 }
Display of the save & cancel button next to a catalogue
r1175 }
else {
// Note: the widget is destroyed
Edition of catalogues from the inspector
r1180 treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
Display of the save & cancel button next to a catalogue
r1175 }
}
Edition of catalogues from the inspector
r1180
"Apply" and "cancel" buttons on an event
r1194 bool CatalogueTreeWidgetItem::hasChanges()
{
return treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) != nullptr;
}
Edition of catalogues from the inspector
r1180 void CatalogueTreeWidgetItem::refresh()
{
emitDataChanged();
}