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

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

parent 3eff6251
......@@ -64,8 +64,11 @@ public:
};
DVcsJob::DVcsJob(const QDir& workingDir, IPlugin* parent, OutputJob::OutputJobVerbosity verbosity)
: VcsJob(parent, verbosity), d(new DVcsJobPrivate)
: VcsJob(parent, verbosity)
, d_ptr(new DVcsJobPrivate)
{
Q_D(DVcsJob);
Q_ASSERT(workingDir.exists());
d->status = JobNotStarted;
d->vcsplugin = parent;
......@@ -89,34 +92,46 @@ DVcsJob::~DVcsJob() = default;
QDir DVcsJob::directory() const
{
Q_D(const DVcsJob);
return QDir(d->childproc->workingDirectory());
}
DVcsJob& DVcsJob::operator<<(const QString& arg)
{
Q_D(DVcsJob);
*d->childproc << arg;
return *this;
}
DVcsJob& DVcsJob::operator<<(const char* arg)
{
Q_D(DVcsJob);
*d->childproc << QString::fromUtf8(arg);
return *this;
}
DVcsJob& DVcsJob::operator<<(const QStringList& args)
{
Q_D(DVcsJob);
*d->childproc << args;
return *this;
}
QStringList DVcsJob::dvcsCommand() const
{
Q_D(const DVcsJob);
return d->childproc->program();
}
QString DVcsJob::output() const
{
Q_D(const DVcsJob);
QByteArray stdoutbuf = rawOutput();
int endpos = stdoutbuf.size();
if (d->status==JobRunning) { // We may have received only part of a code-point. apol: ASSERT?
......@@ -128,31 +143,43 @@ QString DVcsJob::output() const
QByteArray DVcsJob::rawOutput() const
{
Q_D(const DVcsJob);
return d->output;
}
QByteArray DVcsJob::errorOutput() const
{
Q_D(const DVcsJob);
return d->errorOutput;
}
void DVcsJob::setIgnoreError(bool ignore)
{
Q_D(DVcsJob);
d->ignoreError = ignore;
}
void DVcsJob::setResults(const QVariant &res)
{
Q_D(DVcsJob);
d->results = res;
}
QVariant DVcsJob::fetchResults()
{
Q_D(DVcsJob);
return d->results;
}
void DVcsJob::start()
{
Q_D(DVcsJob);
Q_ASSERT_X(d->status != JobRunning, "DVCSjob::start", "Another process was started using this job class");
const QDir& workingdir = directory();
......@@ -193,16 +220,22 @@ void DVcsJob::start()
void DVcsJob::setCommunicationMode(KProcess::OutputChannelMode comm)
{
Q_D(DVcsJob);
d->childproc->setOutputChannelMode(comm);
}
void DVcsJob::cancel()
{
Q_D(DVcsJob);
d->childproc->kill();
}
void DVcsJob::slotProcessError( QProcess::ProcessError err )
{
Q_D(DVcsJob);
d->status = JobFailed;
setError(OutputJob::FailedShownError); //we don't want to trigger a message box
......@@ -252,6 +285,8 @@ void DVcsJob::slotProcessError( QProcess::ProcessError err )
void DVcsJob::slotProcessExited(int exitCode, QProcess::ExitStatus exitStatus)
{
Q_D(DVcsJob);
d->status = JobSucceeded;
d->model->appendLine(i18n("Command exited with value %1.", exitCode));
......@@ -267,11 +302,15 @@ void DVcsJob::slotProcessExited(int exitCode, QProcess::ExitStatus exitStatus)
void DVcsJob::displayOutput(const QString& data)
{
Q_D(DVcsJob);
d->model->appendLines(data.split(QLatin1Char('\n')));
}
void DVcsJob::slotReceivedStdout()
{
Q_D(DVcsJob);
QByteArray output = d->childproc->readAllStandardOutput();
// accumulate output
......@@ -282,22 +321,30 @@ void DVcsJob::slotReceivedStdout()
VcsJob::JobStatus DVcsJob::status() const
{
Q_D(const DVcsJob);
return d->status;
}
IPlugin* DVcsJob::vcsPlugin() const
{
Q_D(const DVcsJob);
return d->vcsplugin;
}
DVcsJob& DVcsJob::operator<<(const QUrl& url)
{
Q_D(DVcsJob);
*d->childproc << url.toLocalFile();
return *this;
}
DVcsJob& DVcsJob::operator<<(const QList< QUrl >& urls)
{
Q_D(DVcsJob);
for (const QUrl& url : urls) {
operator<<(url);
}
......@@ -306,6 +353,8 @@ DVcsJob& DVcsJob::operator<<(const QList< QUrl >& urls)
bool DVcsJob::doKill()
{
Q_D(DVcsJob);
if (d->childproc->state() == QProcess::NotRunning) {
return true;
}
......@@ -327,4 +376,9 @@ void DVcsJob::jobIsReady()
emit resultsReady(this); //VcsJob
}
KProcess* DVcsJob::process() {return d->childproc;}
KProcess* DVcsJob::process() const
{
Q_D(const DVcsJob);
return d->childproc;
}
......@@ -37,6 +37,11 @@
class QDir;
class QStringList;
namespace KDevelop
{
class DVcsJobPrivate;
/**
* This class is capable of running our dvcs commands.
* Most of all DVcsJob are created in DVCS executors, but executed in DistributedVersionControlPlugin or
......@@ -79,10 +84,6 @@ class QStringList;
* @author Robert Gruber <rgruber@users.sourceforge.net>
* @author Evgeniy Ivanov <powerfox@kde.ru>
*/
namespace KDevelop
{
class KDEVPLATFORMVCS_EXPORT DVcsJob : public KDevelop::VcsJob
{
Q_OBJECT
......@@ -197,7 +198,7 @@ public:
KDevelop::IPlugin* vcsPlugin() const override;
// End: KDevelop::VcsJob
KProcess *process();
KProcess* process() const;
void displayOutput(const QString& output);
......@@ -224,7 +225,8 @@ private:
void jobIsReady();
private:
const QScopedPointer<class DVcsJobPrivate> d;
const QScopedPointer<class DVcsJobPrivate> d_ptr;
Q_DECLARE_PRIVATE(DVcsJob)
};
}
......
......@@ -62,7 +62,7 @@ public:
//class DistributedVersionControlPlugin
DistributedVersionControlPlugin::DistributedVersionControlPlugin(QObject *parent, const QString& componentName)
: IPlugin(componentName, parent)
, d(new DistributedVersionControlPluginPrivate(this))
, d_ptr(new DistributedVersionControlPluginPrivate(this))
{}
DistributedVersionControlPlugin::~DistributedVersionControlPlugin()
......@@ -87,6 +87,8 @@ DistributedVersionControlPlugin::createImportMetadataWidget(QWidget* parent)
KDevelop::ContextMenuExtension
DistributedVersionControlPlugin::contextMenuExtension(Context* context, QWidget* parent)
{
Q_D(DistributedVersionControlPlugin);
d->m_common->setupFromContext(context);
QList<QUrl> const & ctxUrlList = d->m_common->contextUrlList();
......@@ -125,6 +127,8 @@ static QString stripPathToDir(const QString &path)
void DistributedVersionControlPlugin::ctxBranchManager()
{
Q_D(DistributedVersionControlPlugin);
QList<QUrl> const & ctxUrlList = d->m_common->contextUrlList();
Q_ASSERT(!ctxUrlList.isEmpty());
......
......@@ -36,6 +36,7 @@ class QMenu;
namespace KDevelop
{
class DVcsJob;
class DistributedVersionControlPluginPrivate;
/**
* DistributedVersionControlPlugin is a base class for git/hg/bzr plugins. This class implements
......@@ -93,7 +94,8 @@ protected:
virtual bool isValidDirectory(const QUrl &dirPath) = 0;
private:
const QScopedPointer<class DistributedVersionControlPluginPrivate> d;
const QScopedPointer<class DistributedVersionControlPluginPrivate> d_ptr;
Q_DECLARE_PRIVATE(DistributedVersionControlPlugin)
};
}
......
......@@ -33,7 +33,7 @@ class CheckInRepositoryJobPrivate
CheckInRepositoryJob::CheckInRepositoryJob(KTextEditor::Document* document)
: KJob()
, d(new CheckInRepositoryJobPrivate(document))
, d_ptr(new CheckInRepositoryJobPrivate(document))
{
connect(this, &CheckInRepositoryJob::finished, this, &CheckInRepositoryJob::deleteLater);
setCapabilities(Killable);
......@@ -43,6 +43,8 @@ CheckInRepositoryJob::~CheckInRepositoryJob() = default;
KTextEditor::Document* CheckInRepositoryJob::document() const
{
Q_D(const CheckInRepositoryJob);
return d->document;
}
......
......@@ -30,6 +30,7 @@ namespace KTextEditor {
}
namespace KDevelop {
class CheckInRepositoryJobPrivate;
class KDEVPLATFORMVCS_EXPORT CheckInRepositoryJob : public KJob
{
......@@ -47,8 +48,9 @@ public Q_SLOTS:
Q_SIGNALS:
void finished(bool canRecreate);
protected:
const QScopedPointer<class CheckInRepositoryJobPrivate> d;
private:
const QScopedPointer<class CheckInRepositoryJobPrivate> d_ptr;
Q_DECLARE_PRIVATE(CheckInRepositoryJob)
};
/**
......
......@@ -108,7 +108,8 @@ static QVariant runSynchronously(KDevelop::VcsJob* job)
}
BranchesListModel::BranchesListModel(QObject* parent)
: QStandardItemModel(parent), d(new BranchesListModelPrivate())
: QStandardItemModel(parent)
, d_ptr(new BranchesListModelPrivate())
{
}
......@@ -125,6 +126,8 @@ QHash<int, QByteArray> BranchesListModel::roleNames() const
void BranchesListModel::createBranch(const QString& baseBranch, const QString& newBranch)
{
Q_D(BranchesListModel);
qCDebug(VCS) << "Creating " << baseBranch << " based on " << newBranch;
KDevelop::VcsRevision rev;
rev.setRevisionValue(baseBranch, KDevelop::VcsRevision::GlobalNumber);
......@@ -137,6 +140,8 @@ void BranchesListModel::createBranch(const QString& baseBranch, const QString& n
void BranchesListModel::removeBranch(const QString& branch)
{
Q_D(BranchesListModel);
KDevelop::VcsJob *branchJob = d->dvcsplugin->deleteBranch(d->repo, branch);
qCDebug(VCS) << "Removing branch:" << branch;
......@@ -150,16 +155,22 @@ void BranchesListModel::removeBranch(const QString& branch)
QUrl BranchesListModel::repository() const
{
Q_D(const BranchesListModel);
return d->repo;
}
KDevelop::IBranchingVersionControl* BranchesListModel::interface()
KDevelop::IBranchingVersionControl* BranchesListModel::interface() const
{
Q_D(const BranchesListModel);
return d->dvcsplugin;
}
void BranchesListModel::initialize(KDevelop::IBranchingVersionControl* branching, const QUrl& r)
{
Q_D(BranchesListModel);
d->dvcsplugin = branching;
d->repo = r;
refresh();
......@@ -167,6 +178,8 @@ void BranchesListModel::initialize(KDevelop::IBranchingVersionControl* branching
void BranchesListModel::refresh()
{
Q_D(BranchesListModel);
const QStringList branches = runSynchronously(d->dvcsplugin->branches(d->repo)).toStringList();
QString curBranch = runSynchronously(d->dvcsplugin->currentBranch(d->repo)).toString();
......@@ -183,11 +196,15 @@ void BranchesListModel::resetCurrent()
QString BranchesListModel::currentBranch() const
{
Q_D(const BranchesListModel);
return runSynchronously(d->dvcsplugin->currentBranch(d->repo)).toString();
}
KDevelop::IProject* BranchesListModel::project() const
{
Q_D(const BranchesListModel);
return KDevelop::ICore::self()->projectController()->findProjectForUrl(d->repo);
}
......@@ -207,6 +224,8 @@ void BranchesListModel::setProject(KDevelop::IProject* p)
void BranchesListModel::setCurrentBranch(const QString& branch)
{
Q_D(BranchesListModel);
KDevelop::VcsJob* job = d->dvcsplugin->switchBranch(d->repo, branch);
connect(job, &VcsJob::finished, this, &BranchesListModel::currentBranchChanged);
KDevelop::ICore::self()->runController()->registerJob(job);
......
......@@ -30,6 +30,7 @@
namespace KDevelop {
class IBranchingVersionControl;
class IProject;
class BranchesListModelPrivate;
class KDEVPLATFORMVCS_EXPORT BranchesListModel : public QStandardItemModel
{
......@@ -50,7 +51,7 @@ class KDEVPLATFORMVCS_EXPORT BranchesListModel : public QStandardItemModel
Q_INVOKABLE void removeBranch(const QString& branch);
QUrl repository() const;
KDevelop::IBranchingVersionControl* interface();
KDevelop::IBranchingVersionControl* interface() const;
void refresh();
QString currentBranch() const;
void setCurrentBranch(const QString& branch);
......@@ -65,7 +66,8 @@ class KDEVPLATFORMVCS_EXPORT BranchesListModel : public QStandardItemModel
void currentBranchChanged();
private:
const QScopedPointer<class BranchesListModelPrivate> d;
const QScopedPointer<class BranchesListModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(BranchesListModel)
};
}
......
......@@ -88,15 +88,17 @@ public:
VcsAnnotationModel::VcsAnnotationModel(VcsJob *job, const QUrl& url, QObject* parent,
const QColor &foreground, const QColor &background)
: d( new VcsAnnotationModelPrivate( this ) )
: d_ptr(new VcsAnnotationModelPrivate(this))
{
Q_D(VcsAnnotationModel);
setParent( parent );
d->m_annotation.setLocation( url );
d->job = job;
d->foreground = foreground;
d->background = background;
qsrand( QDateTime().toTime_t() );
connect( d->job, &VcsJob::resultsReady,this, [&] (VcsJob* job) { d->addLines(job); } );
connect( d->job, &VcsJob::resultsReady,this, [this] (VcsJob* job) { Q_D(VcsAnnotationModel); d->addLines(job); } );
ICore::self()->runController()->registerJob( d->job );
}
......@@ -144,6 +146,8 @@ static QString annotationToolTip(const VcsAnnotationLine& aline)
QVariant VcsAnnotationModel::data( int line, Qt::ItemDataRole role ) const
{
Q_D(const VcsAnnotationModel);
if( line < 0 || !d->m_annotation.containsLine( line ) )
{
return QVariant();
......@@ -172,6 +176,8 @@ QVariant VcsAnnotationModel::data( int line, Qt::ItemDataRole role ) const
VcsRevision VcsAnnotationModel::revisionForLine( int line ) const
{
Q_D(const VcsAnnotationModel);
///FIXME: update the annotation bar on edit/reload somehow
///BUG: https://bugs.kde.org/show_bug.cgi?id=269757
if (!d->m_annotation.containsLine(line)) {
......@@ -184,6 +190,8 @@ VcsRevision VcsAnnotationModel::revisionForLine( int line ) const
VcsAnnotationLine VcsAnnotationModel::annotationLine(int line) const
{
Q_D(const VcsAnnotationModel);
if (line < 0 || !d->m_annotation.containsLine(line)) {
return VcsAnnotationLine();
}
......
......@@ -36,7 +36,8 @@ namespace KDevelop
class VcsJob;
class VcsAnnotationLine;
class VcsAnnotationModelPrivate;
class KDEVPLATFORMVCS_EXPORT VcsAnnotationModel : public KTextEditor::AnnotationModel
{
Q_OBJECT
......@@ -54,7 +55,8 @@ public:
VcsAnnotationLine annotationLine(int line) const;
private:
const QScopedPointer<class VcsAnnotationModelPrivate> d;
const QScopedPointer<class VcsAnnotationModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(VcsAnnotationModel)
friend class VcsAnnotationModelPrivate;
};
......
......@@ -45,7 +45,8 @@ public:
};
VcsBasicEventModel::VcsBasicEventModel(QObject* parent)
: QAbstractTableModel(parent), d(new VcsBasicEventModelPrivate)
: QAbstractTableModel(parent)
, d_ptr(new VcsBasicEventModelPrivate)
{
}
......@@ -53,6 +54,8 @@ VcsBasicEventModel::~VcsBasicEventModel() = default;
int VcsBasicEventModel::rowCount(const QModelIndex& parent) const
{
Q_D(const VcsBasicEventModel);
return parent.isValid() ? 0 : d->m_events.count();
}
......@@ -63,6 +66,8 @@ int VcsBasicEventModel::columnCount(const QModelIndex& parent) const
QVariant VcsBasicEventModel::data(const QModelIndex& idx, int role) const
{
Q_D(const VcsBasicEventModel);
if( !idx.isValid() || role != Qt::DisplayRole )
return QVariant();
......@@ -109,6 +114,8 @@ QVariant VcsBasicEventModel::headerData(int section, Qt::Orientation orientation
void VcsBasicEventModel::addEvents(const QList<KDevelop::VcsEvent>& list)
{
Q_D(VcsBasicEventModel);
if( list.isEmpty() )
return;
......@@ -119,6 +126,8 @@ void VcsBasicEventModel::addEvents(const QList<KDevelop::VcsEvent>& list)
KDevelop::VcsEvent VcsBasicEventModel::eventForIndex(const QModelIndex& idx) const
{
Q_D(const VcsBasicEventModel);
if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() )
{
return KDevelop::VcsEvent();
......@@ -137,8 +146,11 @@ public:
};
VcsEventLogModel::VcsEventLogModel(KDevelop::IBasicVersionControl* iface, const VcsRevision& rev, const QUrl& url, QObject* parent)
: KDevelop::VcsBasicEventModel(parent), d(new VcsEventLogModelPrivate)
: KDevelop::VcsBasicEventModel(parent)
, d_ptr(new VcsEventLogModelPrivate)
{
Q_D(VcsEventLogModel);
d->m_iface = iface;
d->m_rev = rev;
d->m_url = url;
......@@ -150,11 +162,15 @@ VcsEventLogModel::~VcsEventLogModel() = default;
bool VcsEventLogModel::canFetchMore(const QModelIndex& parent) const
{
Q_D(const VcsEventLogModel);
return !d->done && !d->fetching && !parent.isValid();
}
void VcsEventLogModel::fetchMore(const QModelIndex& parent)
{
Q_D(VcsEventLogModel);
d->fetching = true;
Q_ASSERT(!parent.isValid());
Q_UNUSED(parent);
......@@ -166,6 +182,8 @@ void VcsEventLogModel::fetchMore(const QModelIndex& parent)
void VcsEventLogModel::jobReceivedResults(KJob* job)
{
Q_D(VcsEventLogModel);
const QList<QVariant> l = qobject_cast<KDevelop::VcsJob *>(job)->fetchResults().toList();
if(l.isEmpty() || job->error()!=0) {
d->done = true;
......
......@@ -34,6 +34,8 @@ namespace KDevelop
class VcsRevision;
class IBasicVersionControl;
class VcsEvent;
class VcsEventLogModelPrivate;
class VcsBasicEventModelPrivate;
/**
* This is a generic model to store a list of VcsEvents.
......@@ -64,7 +66,8 @@ protected:
void addEvents(const QList<KDevelop::VcsEvent>&);
private:
const QScopedPointer<class VcsBasicEventModelPrivate> d;
const QScopedPointer<class VcsBasicEventModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(VcsBasicEventModel)
};
/**
......@@ -88,7 +91,8 @@ private Q_SLOTS:
void jobReceivedResults( KJob* job );
private:
const QScopedPointer<class VcsEventLogModelPrivate> d;
const QScopedPointer<class VcsEventLogModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(VcsEventLogModel)
};
}
......
......@@ -137,7 +137,8 @@ public:
};
VcsFileChangesModel::VcsFileChangesModel(QObject *parent, bool allowSelection)
: QStandardItemModel(parent), d(new VcsFileChangesModelPrivate {allowSelection} )
: QStandardItemModel(parent)
, d_ptr(new VcsFileChangesModelPrivate{allowSelection})
{
setColumnCount(2);
setHeaderData(0, Qt::Horizontal, i18n("Filename"));
......@@ -150,7 +151,9 @@ VcsFileChangesModel::~VcsFileChangesModel()