Skip to content
Snippets Groups Projects
Commit 30660f0b authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

colleciton: Fix removing items

Refs #66840
parent 08fd6254
No related branches found
No related tags found
No related merge requests found
......@@ -25,10 +25,11 @@ public:
char m_DropState;
int m_HoverState;
CategorizedCompositeNode* m_pParent;
bool m_IsActive;
};
CategorizedCompositeNodePrivate::CategorizedCompositeNodePrivate():
m_DropState(0),m_pParent(nullptr),m_HoverState(0),m_type(CategorizedCompositeNode::Type::CALL)
m_DropState(0),m_pParent(nullptr),m_HoverState(0),m_type(CategorizedCompositeNode::Type::CALL),m_IsActive(true)
{
}
......@@ -79,3 +80,14 @@ void CategorizedCompositeNode::setParentNode(CategorizedCompositeNode* node)
{
d_ptr->m_pParent = node;
}
bool CategorizedCompositeNode::isActive() const
{
return d_ptr->m_IsActive;
}
void CategorizedCompositeNode::setActive(bool active) const
{
d_ptr->m_IsActive = active;
}
......@@ -24,10 +24,7 @@ class QObject;
class CategorizedCompositeNodePrivate;
/**
* This class is used internally to store QAbstractModelItems it will eventually
* need to be made private
*
* @todo remove the export symbol and don't install the file in "make install"
* DO NOT USE, DEPRECATED
*/
class LIB_EXPORT CategorizedCompositeNode {
public:
......@@ -48,6 +45,8 @@ public:
void setHoverState(const int state);
CategorizedCompositeNode* parentNode() const;
void setParentNode(CategorizedCompositeNode* node);
bool isActive() const;
void setActive(bool active) const;
private:
CategorizedCompositeNodePrivate* d_ptr;
};
......
......@@ -306,7 +306,6 @@ void CategorizedHistoryModelPrivate::add(Call* call)
// }//TODO implement reordering
emit q_ptr->newHistoryCall(call);
emit q_ptr->layoutAboutToBeChanged();
HistoryTopLevelItem* tl = getCategory(call);
const QModelIndex& parentIdx = q_ptr->index(tl->modelRow,0);
q_ptr->beginInsertRows(parentIdx,tl->m_lChildren.size(),tl->m_lChildren.size());
......@@ -321,7 +320,6 @@ void CategorizedHistoryModelPrivate::add(Call* call)
//we don't care
m_sHistoryCalls[(call->startTimeStamp() << 10)+qrand()%1024] = call;
q_ptr->endInsertRows();
emit q_ptr->layoutChanged();
LastUsedNumberModel::instance()->addCall(call);
emit q_ptr->historyChanged();
......@@ -439,6 +437,16 @@ QVariant CategorizedHistoryModel::data( const QModelIndex& idx, int role) const
else {
const int parRow = idx.parent().row();
const HistoryTopLevelItem* parTli = d_ptr->m_lCategoryCounter[parRow];
//HACK force a reload
#if QT_VERSION >= 0x050400
if (parTli->isActive() && !parTli->m_lChildren[idx.row()]->call()->isActive()) {
QTimer::singleShot(0,[this,idx]() {
emit dataChanged(idx,idx);
});
}
#endif
if (d_ptr->m_lCategoryCounter.size() > parRow && parRow >= 0 && parTli && parTli->m_lChildren.size() > idx.row())
return parTli->m_lChildren[idx.row()]->call()->roleData((Call::Role)role);
}
......@@ -486,7 +494,12 @@ Qt::ItemFlags CategorizedHistoryModel::flags( const QModelIndex& idx ) const
{
if (!idx.isValid())
return Qt::NoItemFlags;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | (idx.parent().isValid()?Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled:Qt::ItemIsEnabled);
CategorizedCompositeNode* node = static_cast<CategorizedCompositeNode*>(idx.internalPointer());
const bool hasParent = node->type() != CategorizedCompositeNode::Type::TOP_LEVEL;
const bool isEnabled = node->type() == CategorizedCompositeNode::Type::CALL && ((Call*)((CategorizedCompositeNode*)(idx.internalPointer()))->getSelf())->isActive();
return (isEnabled?Qt::ItemIsEnabled:Qt::NoItemFlags) | Qt::ItemIsSelectable | (hasParent?Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled:Qt::ItemIsEnabled);
}
int CategorizedHistoryModel::columnCount ( const QModelIndex& parentIdx) const
......@@ -620,6 +633,7 @@ bool CategorizedHistoryModel::addItemCallback(const Call* item)
bool CategorizedHistoryModel::removeItemCallback(const Call* item)
{
Q_UNUSED(item)
emit const_cast<Call*>(item)->changed();
return false;
}
......
......@@ -102,7 +102,11 @@ bool CollectionInterface::edit(ItemBase<QObject>* base)
bool CollectionInterface::remove(ItemBase<QObject>* base)
{
return d_ptr->m_fRemove(base);
if (d_ptr->m_fRemove(base)) {
deactivate(base);
return true;
}
return false;
}
int CollectionInterface::size() const
......@@ -110,6 +114,17 @@ int CollectionInterface::size() const
return d_ptr->m_fSize();
}
void CollectionInterface::activate(ItemBase<QObject>* base)
{
base->d_ptr->m_isActive = true;
}
void CollectionInterface::deactivate(ItemBase<QObject>* base)
{
base->d_ptr->m_isActive = false;
}
QMetaObject CollectionInterface::metaObject()
{
return d_ptr->m_pEditorType;
......
......@@ -223,6 +223,8 @@ protected:
bool save (ItemBase<QObject>* base);
bool edit (ItemBase<QObject>* base);
bool remove (ItemBase<QObject>* base);
void activate (ItemBase<QObject>* base);
void deactivate(ItemBase<QObject>* base);
QMetaObject metaObject();
private:
......
......@@ -224,16 +224,18 @@ void CollectionManagerInterface<T>::collectionAddedCallback(CollectionInterface*
template<class T>
bool CollectionManagerInterface<T>::deleteItem(T* item)
{
if (item->collection()->model() == (QAbstractItemModel*) this) {
if (item->collection()) {
if (item->collection()->model() != (QAbstractItemModel*) this)
qWarning() << "Item not deleted by its parent model";
if (item->collection()->supportedFeatures() & CollectionInterface::SupportedFeatures::REMOVE) {
static_cast<CollectionInterface*>(item->collection())->editor<T>()->remove(item);
item->collection()->remove(item);
return true;
}
else
qDebug() << item << "cannot be deleted, the collection doesn't support removing items";
}
else
qDebug() << item << "cannot be deleted, it is not managed by" << this;
qDebug() << item << "cannot be deleted, it has no collection";
return false;
}
......
......@@ -43,7 +43,7 @@ bool CollectionMediator<T>::addItem(const T* item)
template<typename T>
bool CollectionMediator<T>::removeItem(const T* item)
{
return d_ptr->m_pParent->removeItemCallback(item); //TODO wrong
return d_ptr->m_pParent->removeItemCallback(item);
}
template<typename T>
......
......@@ -39,12 +39,11 @@ public:
bool save() const;
bool edit() ;
bool remove() ;
bool isActive() ;
bool isActive() const ;
//Setter
void setCollection(CollectionInterface* backend);
protected:
private:
ItemBasePrivate* d_ptr;
};
......
......@@ -79,7 +79,7 @@ bool ItemBase<Base>::remove()
}
template<typename Base>
bool ItemBase<Base>::isActive()
bool ItemBase<Base>::isActive() const
{
return d_ptr->m_pBackend->isEnabled() && d_ptr->m_isActive;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment