//===================================================================
QMimeData* QResourceTreeModel
::mimeData(const QModelIndexList
&indexes
) const {
/* Store row id list */
QList<int> rowIdList;
int rowId;
if (index.isValid()) {
rowId = index.row();
if (!rowIdList.contains(rowId)) {
rowIdList << rowId;
}
}
}
mimeDataPtr->setData("application/text.list", encodedData);
return mimeDataPtr;
}
//===================================================================
bool QResourceTreeModel
::dropMimeData(const QMimeData* data, Qt
::DropAction action,
int row,
{
if (action == Qt::IgnoreAction) {
return true;
}
if (column > QResourceTreeModel::NB_COLUMN) {
return false;
}
int position;
if (row != -1) {
position = row;
} else if (parent.isValid()) {
position = parent.row();
} else {
}
QByteArray encodedData
= data
->data
("application/text.list");
/* Retrieve row id */
QList<int> rowIdList;
while (!stream.atEnd()) {
stream >> text;
rowIdList << text.toInt();
}
/* Insert rows (one by one) */
foreach(int rowId, rowIdList) {
insertRow(position, parent, rowId);
}
return true;
}
//===================================================================
bool QResourceTreeModel
::insertRow(int position,
const QModelIndex &parent,
int rowId
) {
bool success;
beginInsertRows(parent, position, position);
success = m_rootPtr->insertChildren(position, m_rootPtr->child(rowId)->getTreeItem());
endInsertRows();
/* Add masks */
// m_rootPtr->child(position)->insertChildren(0, m_rootPtr->child(rowId)->child(0)->getTreeItem());
// m_rootPtr->child(position)->insertChildren(1, m_rootPtr->child(rowId)->child(1)->getTreeItem());
return success;
}
//===================================================================
QMimeData* QResourceTreeModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeDataPtr = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
/* Store row id list */
QList<int> rowIdList;
int rowId;
foreach (QModelIndex index, indexes) {
if (index.isValid()) {
rowId = index.row();
if (!rowIdList.contains(rowId)) {
rowIdList << rowId;
stream << QVariant(rowId).toString();
}
}
}
mimeDataPtr->setData("application/text.list", encodedData);
return mimeDataPtr;
}
//===================================================================
bool QResourceTreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row,
int column, const QModelIndex &parent)
{
if (action == Qt::IgnoreAction) {
return true;
}
if (column > QResourceTreeModel::NB_COLUMN) {
return false;
}
int position;
if (row != -1) {
position = row;
} else if (parent.isValid()) {
position = parent.row();
} else {
position = rowCount(QModelIndex());
}
QByteArray encodedData = data->data("application/text.list");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
/* Retrieve row id */
QList<int> rowIdList;
while (!stream.atEnd()) {
QString text;
stream >> text;
rowIdList << text.toInt();
}
/* Insert rows (one by one) */
foreach(int rowId, rowIdList) {
insertRow(position, parent, rowId);
}
return true;
}
//===================================================================
bool QResourceTreeModel::insertRow(int position, const QModelIndex &parent, int rowId)
{
bool success;
beginInsertRows(parent, position, position);
success = m_rootPtr->insertChildren(position, m_rootPtr->child(rowId)->getTreeItem());
endInsertRows();
/* Add masks */
// m_rootPtr->child(position)->insertChildren(0, m_rootPtr->child(rowId)->child(0)->getTreeItem());
// m_rootPtr->child(position)->insertChildren(1, m_rootPtr->child(rowId)->child(1)->getTreeItem());
return success;
}
To copy to clipboard, switch view to plain text mode
Bookmarks