当前位置: 首页>>代码示例>>C++>>正文


C++ QAbstractItemModel::dropMimeData方法代码示例

本文整理汇总了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"));
}
开发者ID:debfx,项目名称:keepassx,代码行数:21,代码来源:TestGui.cpp

示例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();

}
开发者ID:lvanderlinden,项目名称:jasp-desktop,代码行数:23,代码来源:draganddrop.cpp

示例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"));
    }
开发者ID:sandsmark,项目名称:zanshin,代码行数:61,代码来源:tagpagemodeltest.cpp


注:本文中的QAbstractItemModel::dropMimeData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。