void ListModel::removeItem(const QModelIndex& index) { if (!index.isValid()) return; ListItem* item = itemFromIndex(index); if (!item) return; bool isProject = item->isProject(); ListItem* parent = item->parent(); // disable removing the last child if (parent == root() && root()->childCount() == 1) return; int row = item->row(); beginRemoveRows(indexFromItem(parent), row, row); QSqlDatabase db = QSqlDatabase::database(); db.transaction(); if (_removeItem(item)) { db.commit(); if (isProject) emit projectRemoved(); } else { db.rollback(); } endRemoveRows(); }
void DelProject::sureDelPro() { QModelIndex index = m_ui->listView->currentIndex(); QString projectName = pathModel->stringList().at(index.row()); QStringList fileToDel; if(projectName == "linux-0.11") { QMessageBox::warning(this, "提示", "无法删除此工程\n" "如果确实要删除,请到程序程序目录下" "oslab/codeview/project目录下删除linux-0.11文件夹"); return; } if (!index.isValid()) return; fileToDel += QString("project") + QDir::separator() + projectName + QDir::separator() + "func.txt"; fileToDel += QString("project") + QDir::separator() + projectName + QDir::separator() + "simple.txt"; fileToDel += QString("project") + QDir::separator() + projectName + QDir::separator() + "struct.txt"; fileToDel += QString("project") + QDir::separator() + projectName + QDir::separator() + "dcpt.txt"; fileToDel += QString("project") + QDir::separator() + projectName + QDir::separator() + "path.txt"; QDir dir; for(int i = 0; i < fileToDel.count(); i++) { if(dir.exists(fileToDel.at(i))) if(!dir.remove(fileToDel.at(i))) { QMessageBox::information(this, "错误", "删除工程文件失败"); return; } } if(!dir.rmdir(QString("project") + QDir::separator() + projectName)) { QMessageBox::information(this, "错误", "删除工程目录失败"); return; } allProject.removeAt(index.row()); pathModel->setStringList(allProject); m_ui->listView->setModel(pathModel); m_ui->lineEdit->clear(); emit projectRemoved(projectName); }
/** * @brief InfoManager::closeProject Close project given project if exists. If existing is active, set as active something else. * @param name Name of the project we want to close. * @return True if project was closed, false if project do not exists. */ bool InfoManager::closeProject(QString name) { if(!projects.contains(name)) return false; if(activeProject == name) setActiveProject(""); MetaProject* proj = projects.take(name); emit projectRemoved(name); delete proj; /* if(projects.isEmpty()) return true; */ //setActiveProject(projects.values().first()->getName()); return true; }
void QgsWelcomePage::showContextMenuForProjects( QPoint point ) { QModelIndex index = mRecentProjectsListView->indexAt( point ); if ( !index.isValid() ) return; bool pin = mModel->data( index, QgsWelcomePageItemsModel::PinRole ).toBool(); QString path = mModel->data( index, QgsWelcomePageItemsModel::PathRole ).toString(); if ( path.isEmpty() ) return; bool enabled = mModel->flags( index ) & Qt::ItemIsEnabled; QMenu *menu = new QMenu( this ); if ( enabled ) { if ( !pin ) { QAction *pinAction = new QAction( tr( "Pin to List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->pinProject( index ); emit projectPinned( index.row() ); } ); menu->addAction( pinAction ); } else { QAction *pinAction = new QAction( tr( "Unpin from List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->unpinProject( index ); emit projectUnpinned( index.row() ); } ); menu->addAction( pinAction ); } QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu ); connect( openFolderAction, &QAction::triggered, this, [path] { QFileInfo fi( path ); QString folder = fi.path(); QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) ); } ); menu->addAction( openFolderAction ); } else { QAction *rescanAction = new QAction( tr( "Refresh" ), menu ); connect( rescanAction, &QAction::triggered, this, [this, index] { mModel->recheckProject( index ); } ); menu->addAction( rescanAction ); } QAction *removeProjectAction = new QAction( tr( "Remove from List" ), menu ); connect( removeProjectAction, &QAction::triggered, this, [this, index] { mModel->removeProject( index ); emit projectRemoved( index.row() ); } ); menu->addAction( removeProjectAction ); menu->popup( mapToGlobal( point ) ); }
void QgsWelcomePage::showContextMenuForProjects( QPoint point ) { QModelIndex index = mRecentProjectsListView->indexAt( point ); if ( !index.isValid() ) return; bool pin = mModel->data( index, QgsWelcomePageItemsModel::PinRole ).toBool(); QString path = mModel->data( index, QgsWelcomePageItemsModel::PathRole ).toString(); if ( path.isEmpty() ) return; bool enabled = mModel->flags( index ) & Qt::ItemIsEnabled; QMenu *menu = new QMenu( this ); if ( enabled ) { if ( !pin ) { QAction *pinAction = new QAction( tr( "Pin to List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->pinProject( index ); emit projectPinned( index.row() ); } ); menu->addAction( pinAction ); } else { QAction *pinAction = new QAction( tr( "Unpin from List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->unpinProject( index ); emit projectUnpinned( index.row() ); } ); menu->addAction( pinAction ); } QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu ); connect( openFolderAction, &QAction::triggered, this, [path] { QgsGui::instance()->nativePlatformInterface()->openFileExplorerAndSelectFile( path ); } ); menu->addAction( openFolderAction ); } else { QAction *rescanAction = new QAction( tr( "Refresh" ), menu ); connect( rescanAction, &QAction::triggered, this, [this, index] { mModel->recheckProject( index ); } ); menu->addAction( rescanAction ); // add an entry to open the closest existing path to the original project file location // to help users re-find moved/renamed projects! const QString closestPath = QgsFileUtils::findClosestExistingPath( path ); QAction *openFolderAction = new QAction( tr( "Open “%1”…" ).arg( QDir::toNativeSeparators( closestPath ) ), menu ); connect( openFolderAction, &QAction::triggered, this, [closestPath] { QDesktopServices::openUrl( QUrl::fromLocalFile( closestPath ) ); } ); menu->addAction( openFolderAction ); } QAction *removeProjectAction = new QAction( tr( "Remove from List" ), menu ); connect( removeProjectAction, &QAction::triggered, this, [this, index] { mModel->removeProject( index ); emit projectRemoved( index.row() ); } ); menu->addAction( removeProjectAction ); menu->popup( mapToGlobal( point ) ); }
void KdeObservatory::createConfigurationInterface(KConfigDialog *parent) { m_configGeneral = new KdeObservatoryConfigGeneral(parent); parent->addPage(m_configGeneral, i18nc("Global configuration options", "General"), "applications-development"); m_configProjects = new KdeObservatoryConfigProjects(parent); parent->addPage(m_configProjects, i18n("Projects"), "project-development"); m_configViews = new KdeObservatoryConfigViews(parent); m_configViews->m_projects = m_projects; m_configViews->m_projectsInView[i18n("Top Active Projects")] = m_topActiveProjectsViewProjects; m_configViews->m_projectsInView[i18n("Top Developers")] = m_topDevelopersViewProjects; m_configViews->m_projectsInView[i18n("Commit History")] = m_commitHistoryViewProjects; m_configViews->m_projectsInView[i18n("Krazy Report")] = m_krazyReportViewProjects; m_configViews->updateView(i18n("Top Active Projects")); parent->addPage(m_configViews, i18n("Views"), "view-presentation"); connect(m_configProjects, SIGNAL(projectAdded(QString,QString)), m_configViews, SLOT(projectAdded(QString,QString))); connect(m_configProjects, SIGNAL(projectRemoved(QString)), m_configViews, SLOT(projectRemoved(QString))); // Config - General if (m_activityRangeType == 0) m_configGeneral->activitiesFullHistory->setChecked(true); else if (m_activityRangeType == 1) m_configGeneral->activitiesInPastDays->setChecked(true); else m_configGeneral->activitiesInRange->setChecked(true); m_configGeneral->commitExtent->setValue(m_commitExtent); m_configGeneral->fromDate->setDate(QDate::fromString(m_commitFrom, "yyyyMMdd")); m_configGeneral->toDate ->setDate(QDate::fromString(m_commitTo , "yyyyMMdd")); m_configGeneral->enableAutoViewChange->setChecked(m_enableAutoViewChange); m_configGeneral->viewsDelay->setTime(QTime(m_viewsDelay/3600, (m_viewsDelay/60)%60, m_viewsDelay%60)); int viewsCount = m_activeViews.count(); for (int i = 0; i < viewsCount; ++i) { const QPair<QString, bool> &pair = m_activeViews.at(i); QListWidgetItem * item = m_configViews->activeViews->findItems(pair.first, Qt::MatchFixedString).first(); item->setCheckState(pair.second == true ? Qt::Checked:Qt::Unchecked); m_configViews->activeViews->takeItem(m_configViews->activeViews->row(item)); m_configViews->activeViews->insertItem(i, item); } // Config - Projects QMapIterator<QString, Project> i(m_projects); while (i.hasNext()) { i.next(); Project project = i.value(); m_configProjects->createTableWidgetItem(i.key(), project.commitSubject, project.krazyReport, project.krazyFilePrefix, project.icon); m_configProjects->projects->setCurrentCell(0, 0); } m_configProjects->projects->setCurrentItem(m_configProjects->projects->item(0, 0)); m_configProjects->projects->resizeColumnsToContents(); m_configProjects->projects->horizontalHeader()->setStretchLastSection(true); connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted())); connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted())); connect(parent, SIGNAL(cancelClicked()), m_viewTransitionTimer, SLOT(start())); m_viewTransitionTimer->stop(); connect(m_configGeneral->activitiesFullHistory, SIGNAL(toggled(bool)), parent, SLOT(settingsModified())); connect(m_configGeneral->activitiesInPastDays, SIGNAL(toggled()), parent, SLOT(settingsModified())); connect(m_configGeneral->activitiesInRange , SIGNAL(toggled(bool)), parent, SLOT(settingsModified())); connect(m_configGeneral->commitExtent, SIGNAL(valueChanged(int)), parent, SLOT(settingsModified())); connect(m_configGeneral->fromDate, SIGNAL(dateChanged(QDate)), parent, SLOT(settingsModified())); connect(m_configGeneral->toDate, SIGNAL(dateChanged(QDate)), parent, SLOT(settingsModified())); connect(m_configGeneral->enableAutoViewChange, SIGNAL(toggled(bool)), parent, SLOT(settingsModified())); connect(m_configGeneral->viewsDelay, SIGNAL(dateTimeChanged(QDateTime)), parent, SLOT(settingsModified())); connect(m_configProjects, SIGNAL(projectAdded(QString,QString)), parent, SLOT(settingsModified())); connect(m_configProjects, SIGNAL(projectRemoved(QString)), parent, SLOT(settingsModified())); connect(m_configProjects->projects, SIGNAL(cellChanged(int,int)), parent, SLOT(settingsModified())); connect(m_configProjects, SIGNAL(projectEdited(QString)) , parent, SLOT(settingsModified())); connect(m_configViews->activeViews, SIGNAL(itemChanged(QListWidgetItem*)), parent, SLOT(settingsModified())); connect(m_configViews->tlbUp, SIGNAL(clicked(bool)), parent, SLOT(settingsModified())); connect(m_configViews->tlbDown, SIGNAL(clicked(bool)), parent, SLOT(settingsModified())); connect(m_configViews->views, SIGNAL(currentIndexChanged(int)), parent, SLOT(settingsModified())); connect(m_configViews->projectsInView, SIGNAL(itemChanged(QListWidgetItem*)), parent, SLOT(settingsModified())); connect(m_configViews->psbCheckAll, SIGNAL(toggled(bool)), parent, SLOT(settingsModified())); connect(m_configViews->psbUncheckAll, SIGNAL(toggled(bool)), parent, SLOT(settingsModified())); }