Commit d2b47ce2 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

kdevplatform/project: use Q_DECLARE_PRIVATE/Q_D to forward constness to d

parent 90ab45fe
......@@ -435,12 +435,13 @@ AbstractFileManagerPlugin::AbstractFileManagerPlugin( const QString& componentNa
const QVariantList & /*args*/ )
: IProjectFileManager(),
IPlugin( componentName, parent ),
d(new AbstractFileManagerPluginPrivate(this))
d_ptr(new AbstractFileManagerPluginPrivate(this))
{
connect(core()->projectController(), &IProjectController::projectClosing,
this, [&] (IProject* project) { d->projectClosing(project); });
this, [this] (IProject* project) { Q_D(AbstractFileManagerPlugin); d->projectClosing(project); });
connect(core()->projectController()->projectModel(), &ProjectModel::rowsAboutToBeRemoved,
this, [&] (const QModelIndex& parent, int first, int last) {
this, [this] (const QModelIndex& parent, int first, int last) {
Q_D(AbstractFileManagerPlugin);
// cleanup list jobs to remove about-to-be-dangling pointers
auto* model = core()->projectController()->projectModel();
for (int i = first; i <= last; ++i) {
......@@ -471,6 +472,8 @@ QList<ProjectFolderItem*> AbstractFileManagerPlugin::parse( ProjectFolderItem *i
ProjectFolderItem *AbstractFileManagerPlugin::import( IProject *project )
{
Q_D(AbstractFileManagerPlugin);
ProjectFolderItem *projectRoot = createFolderItem( project, project->path(), nullptr );
emit folderAdded( projectRoot );
qCDebug(FILEMANAGER) << "imported new project" << project->name() << "at" << projectRoot->path();
......@@ -487,14 +490,16 @@ ProjectFolderItem *AbstractFileManagerPlugin::import( IProject *project )
// the rebase.
// see also: https://bugs.kde.org/show_bug.cgi?id=404184
connect(watcher, &KDirWatch::created,
this, [&] (const QString& path) {
this, [this] (const QString& path) {
QTimer::singleShot(1000, this, [this, path]() {
Q_D(AbstractFileManagerPlugin);
d->created(path);
});
});
connect(watcher, &KDirWatch::deleted,
this, [&] (const QString& path) {
this, [this] (const QString& path) {
QTimer::singleShot(1000, this, [this, path]() {
Q_D(AbstractFileManagerPlugin);
d->deleted(path);
});
});
......@@ -509,11 +514,15 @@ ProjectFolderItem *AbstractFileManagerPlugin::import( IProject *project )
KJob* AbstractFileManagerPlugin::createImportJob(ProjectFolderItem* item)
{
Q_D(AbstractFileManagerPlugin);
return d->eventuallyReadFolder(item);
}
bool AbstractFileManagerPlugin::reload( ProjectFolderItem* item )
{
Q_D(AbstractFileManagerPlugin);
qCDebug(FILEMANAGER) << "reloading item" << item->path();
auto job = d->eventuallyReadFolder( item->folder() );
job->start();
......@@ -523,6 +532,8 @@ bool AbstractFileManagerPlugin::reload( ProjectFolderItem* item )
ProjectFolderItem* AbstractFileManagerPlugin::addFolder( const Path& folder,
ProjectFolderItem * parent )
{
Q_D(AbstractFileManagerPlugin);
qCDebug(FILEMANAGER) << "adding folder" << folder << "to" << parent->path();
ProjectFolderItem* created = nullptr;
d->stopWatcher(parent);
......@@ -540,6 +551,8 @@ ProjectFolderItem* AbstractFileManagerPlugin::addFolder( const Path& folder,
ProjectFileItem* AbstractFileManagerPlugin::addFile( const Path& file,
ProjectFolderItem * parent )
{
Q_D(AbstractFileManagerPlugin);
qCDebug(FILEMANAGER) << "adding file" << file << "to" << parent->path();
ProjectFileItem* created = nullptr;
d->stopWatcher(parent);
......@@ -555,18 +568,24 @@ ProjectFileItem* AbstractFileManagerPlugin::addFile( const Path& file,
bool AbstractFileManagerPlugin::renameFolder(ProjectFolderItem* folder, const Path& newPath)
{
Q_D(AbstractFileManagerPlugin);
qCDebug(FILEMANAGER) << "trying to rename a folder:" << folder->path() << newPath;
return d->rename(folder, newPath);
}
bool AbstractFileManagerPlugin::renameFile(ProjectFileItem* file, const Path& newPath)
{
Q_D(AbstractFileManagerPlugin);
qCDebug(FILEMANAGER) << "trying to rename a file:" << file->path() << newPath;
return d->rename(file, newPath);
}
bool AbstractFileManagerPlugin::removeFilesAndFolders(const QList<ProjectBaseItem*> &items)
{
Q_D(AbstractFileManagerPlugin);
bool success = true;
for (ProjectBaseItem* item : items) {
Q_ASSERT(item->folder() || item->file());
......@@ -594,6 +613,8 @@ bool AbstractFileManagerPlugin::removeFilesAndFolders(const QList<ProjectBaseIte
bool AbstractFileManagerPlugin::moveFilesAndFolders(const QList< ProjectBaseItem* >& items, ProjectFolderItem* newParent)
{
Q_D(AbstractFileManagerPlugin);
bool success = true;
for (ProjectBaseItem* item : items) {
Q_ASSERT(item->folder() || item->file());
......@@ -630,6 +651,8 @@ bool AbstractFileManagerPlugin::moveFilesAndFolders(const QList< ProjectBaseItem
bool AbstractFileManagerPlugin::copyFilesAndFolders(const Path::List& items, ProjectFolderItem* newParent)
{
Q_D(AbstractFileManagerPlugin);
bool success = true;
for (const Path& item : items) {
d->stopWatcher(newParent);
......@@ -653,6 +676,8 @@ bool AbstractFileManagerPlugin::copyFilesAndFolders(const Path::List& items, Pro
bool AbstractFileManagerPlugin::isValid( const Path& path, const bool isFolder,
IProject* project ) const
{
Q_D(const AbstractFileManagerPlugin);
return d->m_filters.isValid( path, isFolder, project );
}
......@@ -670,6 +695,8 @@ ProjectFolderItem* AbstractFileManagerPlugin::createFolderItem( IProject* projec
KDirWatch* AbstractFileManagerPlugin::projectWatcher( IProject* project ) const
{
Q_D(const AbstractFileManagerPlugin);
return d->m_watchers.value( project, nullptr );
}
......
......@@ -117,7 +117,8 @@ Q_SIGNALS:
void fileRenamed(const KDevelop::Path& oldFile, KDevelop::ProjectFileItem* newFile);
private:
const QScopedPointer<class AbstractFileManagerPluginPrivate> d;
const QScopedPointer<class AbstractFileManagerPluginPrivate> d_ptr;
Q_DECLARE_PRIVATE(AbstractFileManagerPlugin)
friend class AbstractFileManagerPluginPrivate;
public:
friend class AbstractFileManagerPluginImportBenchmark;
......
......@@ -145,7 +145,7 @@ void BuilderJobPrivate::addJob( BuilderJob::BuildType t, ProjectBaseItem* item )
}
BuilderJob::BuilderJob()
: d( new BuilderJobPrivate( this ) )
: d_ptr(new BuilderJobPrivate(this))
{
}
......@@ -153,6 +153,8 @@ BuilderJob::~BuilderJob() = default;
void BuilderJob::addItems( BuildType t, const QList<ProjectBaseItem*>& items )
{
Q_D(BuilderJob);
for (ProjectBaseItem* item : items) {
d->addJob( t, item );
}
......@@ -160,6 +162,8 @@ void BuilderJob::addItems( BuildType t, const QList<ProjectBaseItem*>& items )
void BuilderJob::addProjects( BuildType t, const QList<IProject*>& projects )
{
Q_D(BuilderJob);
for (IProject* project : projects) {
d->addJob( t, project->projectItem() );
}
......@@ -167,14 +171,18 @@ void BuilderJob::addProjects( BuildType t, const QList<IProject*>& projects )
void BuilderJob::addItem( BuildType t, ProjectBaseItem* item )
{
Q_D(BuilderJob);
d->addJob( t, item );
}
void BuilderJob::addCustomJob( BuilderJob::BuildType type, KJob* job, ProjectBaseItem* item )
{
Q_D(BuilderJob);
if (auto* builderJob = qobject_cast<BuilderJob*>(job)) {
// If a subjob is a builder job itself, re-own its job list to avoid having recursive composite jobs.
const QVector<SubJobData> subjobs = builderJob->d->takeJobList();
const QVector<SubJobData> subjobs = builderJob->d_func()->takeJobList();
builderJob->deleteLater();
for (const SubJobData& subjob : subjobs) {
subjob.job->setParent(this);
......@@ -204,6 +212,8 @@ QVector< SubJobData > BuilderJobPrivate::takeJobList()
void BuilderJob::updateJobName()
{
Q_D(BuilderJob);
// Which items are mentioned in the set
// Make it a list to preserve ordering; search overhead (n^2) isn't too big
QList< ProjectBaseItem* > registeredItems;
......
......@@ -29,6 +29,7 @@ namespace KDevelop
{
class ProjectBaseItem;
class IProject;
class BuilderJobPrivate;
/**
* Allows to build a list of project items or projects sequentially, where
......@@ -108,7 +109,8 @@ public:
void start() override;
private:
const QScopedPointer<class BuilderJobPrivate> d;
const QScopedPointer<class BuilderJobPrivate> d_ptr;
Q_DECLARE_PRIVATE(BuilderJob)
friend class BuilderJobPrivate;
};
......
......@@ -106,7 +106,7 @@ public:
ProjectBuildSetModel::ProjectBuildSetModel( QObject* parent )
: QAbstractTableModel( parent )
, d(new ProjectBuildSetModelPrivate)
, d_ptr(new ProjectBuildSetModelPrivate)
{
}
......@@ -114,6 +114,8 @@ ProjectBuildSetModel::~ProjectBuildSetModel() = default;
void ProjectBuildSetModel::loadFromSession( ISession* session )
{
Q_D(ProjectBuildSetModel);
if (!session) {
return;
}
......@@ -129,6 +131,8 @@ void ProjectBuildSetModel::loadFromSession( ISession* session )
void ProjectBuildSetModel::storeToSession( ISession* session )
{
Q_D(ProjectBuildSetModel);
if (!session) {
return;
}
......@@ -161,6 +165,8 @@ int ProjectBuildSetModel::findInsertionPlace( const QStringList& itemPath )
* If an item cannot be found in the ordering list, we append it to the list.
*/
Q_D(ProjectBuildSetModel);
int insertionIndex = 0;
bool found = false;
QList<QStringList>::iterator orderingCacheIterator = d->orderingCache.begin();
......@@ -198,6 +204,8 @@ void ProjectBuildSetModel::removeItemsWithCache( const QList<int>& itemIndices )
* Indices in the list shall be sorted.
*/
Q_D(ProjectBuildSetModel);
QList<int> itemIndicesCopy = itemIndices;
beginRemoveRows( QModelIndex(), itemIndices.first(), itemIndices.last() );
......@@ -221,6 +229,8 @@ void ProjectBuildSetModel::removeItemsWithCache( const QList<int>& itemIndices )
void ProjectBuildSetModel::insertItemWithCache( const BuildItem& item )
{
Q_D(ProjectBuildSetModel);
int insertionPlace = findInsertionPlace( item.itemPath() );
beginInsertRows( QModelIndex(), insertionPlace, insertionPlace );
d->items.insert(insertionPlace, item);
......@@ -229,6 +239,8 @@ void ProjectBuildSetModel::insertItemWithCache( const BuildItem& item )
void ProjectBuildSetModel::insertItemsOverrideCache( int index, const QList< BuildItem >& items )
{
Q_D(ProjectBuildSetModel);
Q_ASSERT( index >= 0 && index <= d->items.size() );
if (index == d->items.size()) {
......@@ -255,6 +267,8 @@ void ProjectBuildSetModel::insertItemsOverrideCache( int index, const QList< Bui
QVariant ProjectBuildSetModel::data( const QModelIndex& idx, int role ) const
{
Q_D(const ProjectBuildSetModel);
if( !idx.isValid() || idx.row() < 0 || idx.column() < 0
|| idx.row() >= rowCount() || idx.column() >= columnCount())
{
......@@ -296,6 +310,8 @@ QVariant ProjectBuildSetModel::headerData( int section, Qt::Orientation orientat
int ProjectBuildSetModel::rowCount( const QModelIndex& parent ) const
{
Q_D(const ProjectBuildSetModel);
if( parent.isValid() )
return 0;
return d->items.count();
......@@ -310,6 +326,8 @@ int ProjectBuildSetModel::columnCount( const QModelIndex& parent ) const
void ProjectBuildSetModel::addProjectItem( KDevelop::ProjectBaseItem* item )
{
Q_D(ProjectBuildSetModel);
BuildItem buildItem( item );
if (d->items.contains(buildItem))
return;
......@@ -332,13 +350,17 @@ bool ProjectBuildSetModel::removeRows( int row, int count, const QModelIndex& pa
return true;
}
QList<BuildItem> ProjectBuildSetModel::items()
QList<BuildItem> ProjectBuildSetModel::items() const
{
Q_D(const ProjectBuildSetModel);
return d->items;
}
void ProjectBuildSetModel::projectClosed( KDevelop::IProject* project )
{
Q_D(ProjectBuildSetModel);
for (int i = d->items.count() - 1; i >= 0; --i) {
if (d->items.at(i).itemProject() == project->name()) {
beginRemoveRows( QModelIndex(), i, i );
......@@ -350,6 +372,8 @@ void ProjectBuildSetModel::projectClosed( KDevelop::IProject* project )
void ProjectBuildSetModel::saveToProject( KDevelop::IProject* project ) const
{
Q_D(const ProjectBuildSetModel);
QVariantList paths;
for (const BuildItem& item : qAsConst(d->items)) {
if( item.itemProject() == project->name() )
......@@ -377,6 +401,8 @@ void ProjectBuildSetModel::loadFromProject( KDevelop::IProject* project )
void ProjectBuildSetModel::moveRowsDown(int row, int count)
{
Q_D(ProjectBuildSetModel);
QList<BuildItem> items = d->items.mid(row, count);
removeRows( row, count );
insertItemsOverrideCache( row + 1, items );
......@@ -384,6 +410,8 @@ void ProjectBuildSetModel::moveRowsDown(int row, int count)
void ProjectBuildSetModel::moveRowsToBottom(int row, int count)
{
Q_D(ProjectBuildSetModel);
QList<BuildItem> items = d->items.mid(row, count);
removeRows( row, count );
insertItemsOverrideCache( rowCount(), items );
......@@ -391,6 +419,8 @@ void ProjectBuildSetModel::moveRowsToBottom(int row, int count)
void ProjectBuildSetModel::moveRowsUp(int row, int count)
{
Q_D(ProjectBuildSetModel);
QList<BuildItem> items = d->items.mid(row, count);
removeRows( row, count );
insertItemsOverrideCache( row - 1, items );
......@@ -398,6 +428,8 @@ void ProjectBuildSetModel::moveRowsUp(int row, int count)
void ProjectBuildSetModel::moveRowsToTop(int row, int count)
{
Q_D(ProjectBuildSetModel);
QList<BuildItem> items = d->items.mid(row, count);
removeRows( row, count );
insertItemsOverrideCache( 0, items );
......
......@@ -32,6 +32,7 @@ class ProjectBaseItem;
class ICore;
class IProject;
class ISession;
class ProjectBuildSetModelPrivate;
class KDEVPLATFORMPROJECT_EXPORT BuildItem
{
......@@ -72,7 +73,7 @@ public:
void moveRowsDown( int row, int count );
void moveRowsToTop( int row, int count );
void moveRowsToBottom( int row, int count );
QList<BuildItem> items();
QList<BuildItem> items() const;
public Q_SLOTS:
void saveToProject( KDevelop::IProject* ) const;
void loadFromProject( KDevelop::IProject* );
......@@ -84,7 +85,8 @@ private:
void insertItemsOverrideCache( int index, const QList<KDevelop::BuildItem>& items );
private:
const QScopedPointer<class ProjectBuildSetModelPrivate> d;
const QScopedPointer<class ProjectBuildSetModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(ProjectBuildSetModel)
};
}
......
......@@ -39,14 +39,20 @@ public:
};
ProjectConfigSkeleton::ProjectConfigSkeleton( const QString & configname )
: KConfigSkeleton( configname ), d( new ProjectConfigSkeletonPrivate )
: KConfigSkeleton(configname)
, d_ptr(new ProjectConfigSkeletonPrivate)
{
Q_D(ProjectConfigSkeleton);
d->m_developerTempFile = configname;
}
ProjectConfigSkeleton::ProjectConfigSkeleton( KSharedConfigPtr config )
: KConfigSkeleton( config ), d( new ProjectConfigSkeletonPrivate )
: KConfigSkeleton(config)
, d_ptr(new ProjectConfigSkeletonPrivate)
{
Q_D(ProjectConfigSkeleton);
Q_ASSERT(config);
d->m_developerTempFile = config->name();
}
......@@ -55,12 +61,16 @@ ProjectConfigSkeleton::~ProjectConfigSkeleton() = default;
void ProjectConfigSkeleton::setDeveloperTempFile( const QString& cfg )
{
Q_D(ProjectConfigSkeleton);
d->m_developerTempFile = cfg;
setSharedConfig( KSharedConfig::openConfig( cfg ) );
}
void ProjectConfigSkeleton::setProjectTempFile( const QString& cfg )
{
Q_D(ProjectConfigSkeleton);
d->m_projectTempFile = cfg;
config()->addConfigSources( QStringList() << cfg );
load();
......@@ -68,26 +78,36 @@ void ProjectConfigSkeleton::setProjectTempFile( const QString& cfg )
void ProjectConfigSkeleton::setProjectFile( const Path& cfg )
{
Q_D(ProjectConfigSkeleton);
d->m_projectFile = cfg;
}
void ProjectConfigSkeleton::setDeveloperFile( const Path& cfg )
{
Q_D(ProjectConfigSkeleton);
d->m_developerFile = cfg;
}
Path ProjectConfigSkeleton::projectFile() const
{
Q_D(const ProjectConfigSkeleton);
return d->m_projectFile;
}
Path ProjectConfigSkeleton::developerFile() const
{
Q_D(const ProjectConfigSkeleton);
return d->m_developerFile;
}
void ProjectConfigSkeleton::setDefaults()
{
Q_D(ProjectConfigSkeleton);
qCDebug(PROJECT) << "Setting Defaults";
KConfig cfg( d->m_projectTempFile );
const auto items = this->items();
......@@ -104,6 +124,8 @@ void ProjectConfigSkeleton::setDefaults()
bool ProjectConfigSkeleton::useDefaults( bool b )
{
Q_D(ProjectConfigSkeleton);
if( b == d->mUseDefaults )
return d->mUseDefaults;
......@@ -150,6 +172,8 @@ bool ProjectConfigSkeleton::useDefaults( bool b )
bool ProjectConfigSkeleton::writeConfig()
{
Q_D(ProjectConfigSkeleton);
KConfigSkeletonItem::List myitems = items();
KConfigSkeletonItem::List::ConstIterator it;
for( it = myitems.constBegin(); it != myitems.constEnd(); ++it )
......
......@@ -29,6 +29,7 @@ namespace KDevelop
{
class Path;
class ProjectConfigSkeletonPrivate;
class KDEVPLATFORMPROJECT_EXPORT ProjectConfigSkeleton: public KConfigSkeleton
{
......@@ -60,7 +61,8 @@ protected:
explicit ProjectConfigSkeleton( const QString & configname );
private:
const QScopedPointer<class ProjectConfigSkeletonPrivate> d;
const QScopedPointer<class ProjectConfigSkeletonPrivate> d_ptr;
Q_DECLARE_PRIVATE(ProjectConfigSkeleton)
};
}
......
......@@ -131,14 +131,16 @@ void ProjectFilterManagerPrivate::filterChanged(IProjectFilterProvider* provider
//BEGIN
ProjectFilterManager::ProjectFilterManager(QObject* parent)
: QObject(parent)
, d(new ProjectFilterManagerPrivate)
, d_ptr(new ProjectFilterManagerPrivate)
{
Q_D(ProjectFilterManager);
d->q = this;
connect(ICore::self()->pluginController(), &IPluginController::pluginLoaded,
this, [&] (IPlugin* plugin) { d->pluginLoaded(plugin); });
this, [this] (IPlugin* plugin) { Q_D(ProjectFilterManager);d->pluginLoaded(plugin); });
connect(ICore::self()->pluginController(), &IPluginController::unloadingPlugin,
this, [&] (IPlugin* plugin) { d->unloadingPlugin(plugin); });
this, [this] (IPlugin* plugin) { Q_D(ProjectFilterManager);d->unloadingPlugin(plugin); });
const auto plugins = ICore::self()->pluginController()->loadedPlugins();
for (IPlugin* plugin : plugins) {
......@@ -153,6 +155,8 @@ ProjectFilterManager::~ProjectFilterManager()
void ProjectFilterManager::add(IProject* project)
{
Q_D(ProjectFilterManager);
QVector<Filter> filters;
filters.reserve(d->m_filterProvider.size());
for (IProjectFilterProvider* provider : qAsConst(d->m_filterProvider)) {
......@@ -166,16 +170,22 @@ void ProjectFilterManager::add(IProject* project)
void ProjectFilterManager::remove(IProject* project)
{
Q_D(ProjectFilterManager);
d->m_filters.remove(project);
}
bool ProjectFilterManager::isManaged(IProject* project) const
{
Q_D(const ProjectFilterManager);
return d->m_filters.contains(project);
}
bool ProjectFilterManager::isValid(const Path& path, bool isFolder, IProject* project) const
{
Q_D(const ProjectFilterManager);
const auto filters = d->m_filters[project];
return std::all_of(filters.begin(), filters.end(), [&](const Filter& filter) {
return (filter.filter->isValid(path, isFolder));
......@@ -184,6 +194,8 @@ bool ProjectFilterManager::isValid(const Path& path, bool isFolder, IProject* pr
QVector< QSharedPointer< IProjectFilter > > ProjectFilterManager::filtersForProject(IProject* project) const
{
Q_D(const ProjectFilterManager);
QVector< QSharedPointer< IProjectFilter > > ret;
const QVector<Filter>& filters = d->m_filters[project];
ret.reserve(filters.size());
......
......@@ -35,6 +35,7 @@ class IProjectFilterProvider;
class IPlugin;
class IProject;
class Path;
class ProjectFilterManagerPrivate;
/**
* @short A helper class to manage project filtering in file managers.
......@@ -87,9 +88,10 @@ public:
QVector<QSharedPointer<IProjectFilter> > filtersForProject(IProject* project) const;
private:
const QScopedPointer<class ProjectFilterManagerPrivate> d;
const QScopedPointer<class ProjectFilterManagerPrivate> d_ptr;
Q_DECLARE_PRIVATE(ProjectFilterManager)
Q_PRIVATE_SLOT(d, void filterChanged( KDevelop::IProjectFilterProvider*, KDevelop::IProject* ) )
Q_PRIVATE_SLOT(d_func(), void filterChanged( KDevelop::IProjectFilterProvider*, KDevelop::IProject* ) )
};
}
......
......@@ -160,8 +160,10 @@ public:
ProjectItemLineEdit::ProjectItemLineEdit(QWidget* parent)
: QLineEdit(parent),
d(new ProjectItemLineEditPrivate(this))
d_ptr(new ProjectItemLineEditPrivate(this))
{
Q_D(ProjectItemLineEdit);
setCompleter(d->completer);
setValidator(d->validator);
setPlaceholderText( i18n("Enter the path to an item from the projects tree" ) );
......@@ -185,6 +187,8 @@ void ProjectItemLineEdit::showCtxMenu(const QPoint& p)
bool ProjectItemLineEdit::selectItemDialog()
{
Q_D(ProjectItemLineEdit);
KDevelop::ProjectModel* model=KDevelop::ICore::self()->projectController()->projectModel();
QDialog dialog;
......@@ -228,16 +232,22 @@ bool ProjectItemLineEdit::selectItemDialog()
void ProjectItemLineEdit::setItemPath(const QStringList& list)