| 323 | } |
| 324 | |
| 325 | void TestProjectModel::testRename() |
| 326 | { |
| 327 | QString projectFolderPath = QDir::rootPath() + QStringLiteral("dummyprojectfolder"); |
| 328 | QFETCH( int, itemType ); |
| 329 | QFETCH( QString, itemText ); |
| 330 | QFETCH( QString, newName ); |
| 331 | QFETCH( bool, datachangesignal ); |
| 332 | QFETCH( QString, expectedItemText ); |
| 333 | QFETCH( int, expectedRenameCode ); |
| 334 | |
| 335 | const Path projectFolder = Path(QUrl::fromLocalFile(projectFolderPath)); |
| 336 | QScopedPointer<TestProject> proj(new TestProject()); |
| 337 | auto* rootItem = new ProjectFolderItem( proj.data(), projectFolder, nullptr); |
| 338 | proj->setProjectItem( rootItem ); |
| 339 | |
| 340 | new ProjectFileItem(QStringLiteral("existing"), rootItem); |
| 341 | |
| 342 | ProjectBaseItem* item = nullptr; |
| 343 | if( itemType == ProjectBaseItem::Target ) { |
| 344 | item = new ProjectTargetItem( proj.data(), itemText, rootItem ); |
| 345 | } else if( itemType == ProjectBaseItem::File ) { |
| 346 | item = new ProjectFileItem( itemText, rootItem ); |
| 347 | } else if( itemType == ProjectBaseItem::Folder ) { |
| 348 | item = new ProjectFolderItem( itemText, rootItem ); |
| 349 | } else if( itemType == ProjectBaseItem::BuildFolder ) { |
| 350 | item = new ProjectBuildFolderItem( itemText, rootItem ); |
| 351 | } |
| 352 | Q_ASSERT( item ); |
| 353 | |
| 354 | QCOMPARE(item->model(), model); |
| 355 | QSignalSpy s( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)) ); |
| 356 | ProjectBaseItem::RenameStatus stat = item->rename( newName ); |
| 357 | QCOMPARE( (int)stat, expectedRenameCode ); |
| 358 | if( datachangesignal ) { |
| 359 | QCOMPARE( s.count(), 1 ); |
| 360 | QCOMPARE( qvariant_cast<QModelIndex>( s.takeFirst().at(0) ), item->index() ); |
| 361 | } else { |
| 362 | QCOMPARE( s.count(), 0 ); |
| 363 | } |
| 364 | QCOMPARE( item->text(), expectedItemText ); |
| 365 | } |
| 366 | |
| 367 | void TestProjectModel::testRename_data() |
| 368 | { |