本文整理汇总了C++中QAbstractItemModel::dropMimeData方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::dropMimeData方法的具体用法?C++ QAbstractItemModel::dropMimeData怎么用?C++ QAbstractItemModel::dropMimeData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemModel
的用法示例。
在下文中一共展示了QAbstractItemModel::dropMimeData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testDragAndDropEntry
void TestGui::testDragAndDropEntry()
{
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
GroupView* groupView = m_dbWidget->findChild<GroupView*>("groupView");
QAbstractItemModel* groupModel = groupView->model();
QModelIndex sourceIndex = entryView->model()->index(0, 1);
QModelIndex targetIndex = groupModel->index(0, 0, groupModel->index(0, 0));
QVERIFY(sourceIndex.isValid());
QVERIFY(targetIndex.isValid());
QMimeData mimeData;
QByteArray encoded;
QDataStream stream(&encoded, QIODevice::WriteOnly);
Entry* entry = entryView->entryFromIndex(sourceIndex);
stream << entry->group()->database()->uuid() << entry->uuid();
mimeData.setData("application/x-keepassx-entry", encoded);
QVERIFY(groupModel->dropMimeData(&mimeData, Qt::MoveAction, -1, 0, targetIndex));
QCOMPARE(entry->group()->name(), QString("General"));
}
示例2: perform
void DragAndDrop::perform(DropTarget *source, DropTarget *target, int flags)
{
QModelIndexList indices = source->view()->selectionModel()->selectedIndexes();
QMimeData *mimeData = source->view()->model()->mimeData(indices);
Qt::DropAction action = Qt::CopyAction;
if (target->view()->model()->supportedDropActions() & Qt::MoveAction)
action = Qt::MoveAction;
QAbstractItemModel *model = target->view()->model();
EnhancedDropTarget *enhancedModel = dynamic_cast<EnhancedDropTarget *>(model);
bool success;
if (enhancedModel != NULL)
success = enhancedModel->dropMimeData(mimeData, action, -1, 0, QModelIndex(), flags);
else
success = model->dropMimeData(mimeData, action, -1, 0, QModelIndex());
if (success && action == Qt::MoveAction && source != target)
source->notifyDragWasDropped();
}
示例3: shouldGetAnErrorMessageWhenAssociateTaskFailed
void shouldGetAnErrorMessageWhenAssociateTaskFailed()
{
// GIVEN
// One Tag
auto tag = Domain::Tag::Ptr::create();
tag->setName("Tag1");
// One note and one task
auto rootTask = Domain::Task::Ptr::create();
rootTask->setTitle("rootTask");
auto artifactProvider = Domain::QueryResultProvider<Domain::Artifact::Ptr>::Ptr::create();
auto artifactResult = Domain::QueryResult<Domain::Artifact::Ptr>::create(artifactProvider);
artifactProvider->append(rootTask);
// One task under the root task
auto childTask = Domain::Task::Ptr::create();
childTask->setTitle("childTask");
childTask->setDone(true);
auto taskProvider = Domain::QueryResultProvider<Domain::Task::Ptr>::Ptr::create();
auto taskResult = Domain::QueryResult<Domain::Task::Ptr>::create(taskProvider);
taskProvider->append(childTask);
Utils::MockObject<Domain::TagQueries> tagQueriesMock;
tagQueriesMock(&Domain::TagQueries::findTopLevelArtifacts).when(tag).thenReturn(artifactResult);
Utils::MockObject<Domain::TaskQueries> taskQueriesMock;
taskQueriesMock(&Domain::TaskQueries::findChildren).when(rootTask).thenReturn(taskResult);
taskQueriesMock(&Domain::TaskQueries::findChildren).when(childTask).thenReturn(Domain::QueryResult<Domain::Task::Ptr>::Ptr());
Utils::MockObject<Domain::TaskRepository> taskRepositoryMock;
Utils::MockObject<Domain::NoteRepository> noteRepositoryMock;
Utils::MockObject<Domain::TagRepository> tagRepositoryMock;
Presentation::TagPageModel page(tag,
tagQueriesMock.getInstance(),
tagRepositoryMock.getInstance(),
taskQueriesMock.getInstance(),
taskRepositoryMock.getInstance(),
noteRepositoryMock.getInstance());
QAbstractItemModel *model = page.centralListModel();
const QModelIndex rootTaskIndex = model->index(0, 0);
FakeErrorHandler errorHandler;
page.setErrorHandler(&errorHandler);
// WHEN
auto childTask2 = Domain::Task::Ptr::create();
childTask2->setTitle("childTask2");
auto job = new FakeJob(this);
job->setExpectedError(KJob::KilledJobError, "Foo");
taskRepositoryMock(&Domain::TaskRepository::associate).when(rootTask, childTask2).thenReturn(job);
auto data = new QMimeData;
data->setData("application/x-zanshin-object", "object");
data->setProperty("objects", QVariant::fromValue(Domain::Artifact::List() << childTask2));
model->dropMimeData(data, Qt::MoveAction, -1, -1, rootTaskIndex);
// THEN
QTest::qWait(150);
QCOMPARE(errorHandler.m_message, QString("Cannot move task childTask2 as sub-task of rootTask: Foo"));
}