The model (JB_NodeModel) uses a helper class (dragDropHelper) that handles the various drag drop methods e.g. dropMimeData.
bool JB_NodeModel
::dropMimeData(const QMimeData *data,
Qt::DropAction action,
int row,
int column,
{
if (dragDropHelper)
return dragDropHelper->dropMimeData(data,
action,
row,
column,
parent,
this);
else
action,
row,
column,
parent);
}
bool JB_NodeModel::dropMimeData(const QMimeData *data,
Qt::DropAction action,
int row,
int column,
const QModelIndex &parent)
{
if (dragDropHelper)
return dragDropHelper->dropMimeData(data,
action,
row,
column,
parent,
this);
else
return QAbstractItemModel::dropMimeData(data,
action,
row,
column,
parent);
}
To copy to clipboard, switch view to plain text mode
bool JB_NMHP_DD_KwGrpsWidget
::dropMimeData(const QMimeData *data,
Qt::DropAction action,
int row,
int column,
JB_NodeModel *aNodeModel)
{
Q_CHECK_PTR(aNodeModel);
bool handleDrop = true;
JB_Node* movedNode = 0;
if (action == Qt::IgnoreAction)
handleDrop = true;
if (!data->hasFormat("text/plain"))
handleDrop = false;
else if (column > 0)
handleDrop = false;
else
{
JB_Node* aParentNode = 0;
if (modelWrapper->getJBNodeModel() == aNodeModel)
{
aParentNode = aNodeModel->nodeFromIndex(parent);
Q_CHECK_PTR(aParentNode);
}
else
JB_Utilities::getJBUtilities()->debugMB("ERROR: The Drag&Drop modelWrapper and nodeModel do not match", 0);
int beginRow;
if (row >= 0)
beginRow = row;
else
beginRow = 0;
//beginRow = aParentNode->children.count();
QString aFirstNodePrimaryTableName;
QHash<QString, QVariant> aFirstNodeFieldValues;
QStringList nodesMimeDataTextList
= JB_Utilities
::getJBUtilities()->getTextListFromMimeData
(data
);
QString firstNodeText
= nodesMimeDataTextList.
value(0);
JB_Utilities::getJBUtilities()->getInfoFromMIMEDataText(firstNodeText,
aFirstNodePrimaryTableName,
aFirstNodeLineage,
aFirstNodeRowIDFieldName,
aFirstNodeFieldValues);
if (aFirstNodePrimaryTableName == "KeywordGroup")
{
if (nodesMimeDataTextList.size() > 1)
JB_Utilities::getJBUtilities()->debugMB("ERROR: The Drag&Drop is trying to move more than one Keyword Group", 0);
else
{
movedNode = aNodeModel->getNodeForNodeLineage(aFirstNodeLineage);
Q_CHECK_PTR(movedNode);
if (movedNode->parent == aParentNode)
handleDrop = false;
else
{
handleDrop = true;
JB_Node* newFromMovedNode = new JB_Node(*movedNode);
newFromMovedNode->children = movedNode->children;
for (int i = 0; i < newFromMovedNode->children.count(); i++)
newFromMovedNode->children.value(i)->parent = newFromMovedNode;
int parentRowID = aParentNode->getRowID();
int unhashedParentRowID = JB_Utilities::getJBUtilities()->getUnHashedTreeLevelID(parentRowID);
QString kwGrpParentIDFieldName
= "kwGrp_KwGrpParentID";
if (newFromMovedNode->getMappedDBFieldNames().contains(kwGrpParentIDFieldName))
{
newFromMovedNode
->setData
("kwGrp_KwGrpParentID",
QVariant(unhashedParentRowID
));
newFromMovedNode->setDragDropStatus(JB_DRAGDROP);
aNodeModel->insertNode(aParentNode, beginRow, newFromMovedNode, false, true);
}
else
JB_Utilities::getJBUtilities()->debugMB("ERROR: newFromMovedNode should have a kwGrp_KwGrpParentID field", 0);
}
}
}
}
if (handleDrop == false && movedNode)
movedNode->setDragDropStatus(JB_CANCEL_DRAGDROP);
return handleDrop;
}
bool JB_NMHP_DD_KwGrpsWidget::dropMimeData(const QMimeData *data,
Qt::DropAction action,
int row,
int column,
const QModelIndex &parent,
JB_NodeModel *aNodeModel)
{
Q_CHECK_PTR(aNodeModel);
bool handleDrop = true;
JB_Node* movedNode = 0;
if (action == Qt::IgnoreAction)
handleDrop = true;
if (!data->hasFormat("text/plain"))
handleDrop = false;
else if (column > 0)
handleDrop = false;
else
{
JB_Node* aParentNode = 0;
if (modelWrapper->getJBNodeModel() == aNodeModel)
{
aParentNode = aNodeModel->nodeFromIndex(parent);
Q_CHECK_PTR(aParentNode);
}
else
JB_Utilities::getJBUtilities()->debugMB("ERROR: The Drag&Drop modelWrapper and nodeModel do not match", 0);
int beginRow;
if (row >= 0)
beginRow = row;
else
beginRow = 0;
//beginRow = aParentNode->children.count();
QString aFirstNodePrimaryTableName;
QString aFirstNodeLineage;
QString aFirstNodeRowIDFieldName;
QHash<QString, QVariant> aFirstNodeFieldValues;
QStringList nodesMimeDataTextList = JB_Utilities::getJBUtilities()->getTextListFromMimeData(data);
QString firstNodeText = nodesMimeDataTextList.value(0);
JB_Utilities::getJBUtilities()->getInfoFromMIMEDataText(firstNodeText,
aFirstNodePrimaryTableName,
aFirstNodeLineage,
aFirstNodeRowIDFieldName,
aFirstNodeFieldValues);
if (aFirstNodePrimaryTableName == "KeywordGroup")
{
if (nodesMimeDataTextList.size() > 1)
JB_Utilities::getJBUtilities()->debugMB("ERROR: The Drag&Drop is trying to move more than one Keyword Group", 0);
else
{
movedNode = aNodeModel->getNodeForNodeLineage(aFirstNodeLineage);
Q_CHECK_PTR(movedNode);
if (movedNode->parent == aParentNode)
handleDrop = false;
else
{
handleDrop = true;
JB_Node* newFromMovedNode = new JB_Node(*movedNode);
newFromMovedNode->children = movedNode->children;
for (int i = 0; i < newFromMovedNode->children.count(); i++)
newFromMovedNode->children.value(i)->parent = newFromMovedNode;
int parentRowID = aParentNode->getRowID();
int unhashedParentRowID = JB_Utilities::getJBUtilities()->getUnHashedTreeLevelID(parentRowID);
QString kwGrpParentIDFieldName = "kwGrp_KwGrpParentID";
if (newFromMovedNode->getMappedDBFieldNames().contains(kwGrpParentIDFieldName))
{
newFromMovedNode->setData("kwGrp_KwGrpParentID", QVariant(unhashedParentRowID));
newFromMovedNode->setDragDropStatus(JB_DRAGDROP);
aNodeModel->insertNode(aParentNode, beginRow, newFromMovedNode, false, true);
}
else
JB_Utilities::getJBUtilities()->debugMB("ERROR: newFromMovedNode should have a kwGrp_KwGrpParentID field", 0);
}
}
}
}
if (handleDrop == false && movedNode)
movedNode->setDragDropStatus(JB_CANCEL_DRAGDROP);
return handleDrop;
}
To copy to clipboard, switch view to plain text mode
Qt::DropActions JB_NMHP_DD_KwGrpsWidget::supportedDropActions() const
{
return Qt::MoveAction;
}
Qt::DropActions JB_NMHP_DD_KwGrpsWidget::supportedDropActions() const
{
return Qt::MoveAction;
}
To copy to clipboard, switch view to plain text mode
Bookmarks