##// END OF EJS Templates
Completes fuzzing test structure by setting initial range for the time controller
Completes fuzzing test structure by setting initial range for the time controller

File last commit:

r1164:b6390f556418
r1178:324a3ee21c58
Show More
CatalogueTreeWidgetItem.cpp
91 lines | 2.6 KiB | text/x-c | CppLexer
/ gui / src / Catalogue / CatalogueTreeWidgetItem.cpp
#include "Catalogue/CatalogueTreeWidgetItem.h"
#include <Catalogue/CatalogueExplorerHelper.h>
#include <Catalogue/CatalogueController.h>
#include <SqpApplication.h>
#include <memory>
#include <DBCatalogue.h>
/// Column in the tree widget where the apply and cancel buttons must appear
const auto APPLY_CANCEL_BUTTONS_COLUMN = 1;
struct CatalogueTreeWidgetItem::CatalogueTreeWidgetItemPrivate {
std::shared_ptr<DBCatalogue> m_Catalogue;
CatalogueTreeWidgetItemPrivate(std::shared_ptr<DBCatalogue> catalogue) : m_Catalogue(catalogue)
{
}
};
CatalogueTreeWidgetItem::CatalogueTreeWidgetItem(std::shared_ptr<DBCatalogue> catalogue, int type)
: QTreeWidgetItem(type),
impl{spimpl::make_unique_impl<CatalogueTreeWidgetItemPrivate>(catalogue)}
{
setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
}
QVariant CatalogueTreeWidgetItem::data(int column, int role) const
{
if (column == 0) {
switch (role) {
case Qt::EditRole: // fallthrough
case Qt::DisplayRole:
return impl->m_Catalogue->getName();
default:
break;
}
}
return QTreeWidgetItem::data(column, role);
}
void CatalogueTreeWidgetItem::setData(int column, int role, const QVariant &value)
{
if (role == Qt::EditRole && column == 0) {
auto newName = value.toString();
if (newName != impl->m_Catalogue->getName()) {
setText(0, newName);
impl->m_Catalogue->setName(newName);
sqpApp->catalogueController().updateCatalogue(impl->m_Catalogue);
setHasChanges(true);
}
}
else {
QTreeWidgetItem::setData(column, role, value);
}
}
std::shared_ptr<DBCatalogue> CatalogueTreeWidgetItem::catalogue() const
{
return impl->m_Catalogue;
}
void CatalogueTreeWidgetItem::setHasChanges(bool value)
{
if (value) {
if (!hasChanges()) {
auto widget = CatalogueExplorerHelper::buildValidationWidget(
treeWidget(), [this]() { setHasChanges(false); },
[this]() { setHasChanges(false); });
treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, widget);
}
}
else {
// Note: the widget is destroyed
treeWidget()->setItemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN, nullptr);
}
}
bool CatalogueTreeWidgetItem::hasChanges()
{
return treeWidget()->itemWidget(this, APPLY_CANCEL_BUTTONS_COLUMN) != nullptr;
}
void CatalogueTreeWidgetItem::refresh()
{
emitDataChanged();
}