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

parent 2269deb3
......@@ -56,7 +56,7 @@ OutputDelegatePrivate::OutputDelegatePrivate()
OutputDelegate::OutputDelegate( QObject* parent )
: QItemDelegate( parent )
, d(new OutputDelegatePrivate)
, d_ptr(new OutputDelegatePrivate)
{
}
......@@ -64,6 +64,8 @@ OutputDelegate::~OutputDelegate() = default;
void OutputDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
Q_D(const OutputDelegate);
QStyleOptionViewItem opt = option;
QVariant status = index.data(OutputModel::OutputItemTypeRole);
if( status.isValid() ) {
......
......@@ -28,6 +28,7 @@
namespace KDevelop
{
class OutputDelegatePrivate;
class KDEVPLATFORMOUTPUTVIEW_EXPORT OutputDelegate : public QItemDelegate
{
......@@ -38,7 +39,8 @@ public:
void paint( QPainter*, const QStyleOptionViewItem&, const QModelIndex& ) const override;
private:
const QScopedPointer<class OutputDelegatePrivate> d;
const QScopedPointer<class OutputDelegatePrivate> d_ptr;
Q_DECLARE_PRIVATE(OutputDelegate)
};
}
......
......@@ -85,8 +85,10 @@ OutputExecuteJobPrivate::OutputExecuteJobPrivate( OutputExecuteJob* owner ) :
OutputExecuteJob::OutputExecuteJob( QObject* parent, OutputJob::OutputJobVerbosity verbosity ):
OutputJob( parent, verbosity ),
d( new OutputExecuteJobPrivate( this ) )
d_ptr(new OutputExecuteJobPrivate(this))
{
Q_D(OutputExecuteJob);
d->m_process->setOutputChannelMode( KProcess::SeparateChannels );
connect( d->m_process, QOverload<int,QProcess::ExitStatus>::of(&QProcess::finished),
......@@ -94,13 +96,15 @@ OutputExecuteJob::OutputExecuteJob( QObject* parent, OutputJob::OutputJobVerbosi
connect( d->m_process, &QProcess::errorOccurred,
this, &OutputExecuteJob::childProcessError );
connect( d->m_process, &KProcess::readyReadStandardOutput,
this, [=] { d->childProcessStdout(); } );
this, [this] { Q_D(OutputExecuteJob); d->childProcessStdout(); } );
connect( d->m_process, &KProcess::readyReadStandardError,
this, [=] { d->childProcessStderr(); } );
this, [this] { Q_D(OutputExecuteJob); d->childProcessStderr(); } );
}
OutputExecuteJob::~OutputExecuteJob()
{
Q_D(OutputExecuteJob);
// indicates if process is running and survives kill, then we cannot do anything
bool killSuccessful = d->m_process->state() == QProcess::NotRunning;
if( !killSuccessful ) {
......@@ -112,6 +116,8 @@ OutputExecuteJob::~OutputExecuteJob()
OutputExecuteJob::JobStatus OutputExecuteJob::status() const
{
Q_D(const OutputExecuteJob);
return d->m_status;
}
......@@ -122,33 +128,45 @@ OutputModel* OutputExecuteJob::model() const
QStringList OutputExecuteJob::commandLine() const
{
Q_D(const OutputExecuteJob);
return d->m_arguments;
}
OutputExecuteJob& OutputExecuteJob::operator<<( const QString& argument )
{
Q_D(OutputExecuteJob);
d->m_arguments << argument;
return *this;
}
OutputExecuteJob& OutputExecuteJob::operator<<( const QStringList& arguments )
{
Q_D(OutputExecuteJob);
d->m_arguments << arguments;
return *this;
}
QStringList OutputExecuteJob::privilegedExecutionCommand() const
{
Q_D(const OutputExecuteJob);
return d->m_privilegedExecutionCommand;
}
void OutputExecuteJob::setPrivilegedExecutionCommand( const QStringList& command )
{
Q_D(OutputExecuteJob);
d->m_privilegedExecutionCommand = command;
}
void OutputExecuteJob::setJobName( const QString& name )
{
Q_D(OutputExecuteJob);
d->m_jobName = name;
const QString jobDisplayName = d->jobDisplayName();
......@@ -159,16 +177,22 @@ void OutputExecuteJob::setJobName( const QString& name )
QUrl OutputExecuteJob::workingDirectory() const
{
Q_D(const OutputExecuteJob);
return d->m_workingDirectory;
}
void OutputExecuteJob::setWorkingDirectory( const QUrl& url )
{
Q_D(OutputExecuteJob);
d->m_workingDirectory = url;
}
void OutputExecuteJob::start()
{
Q_D(OutputExecuteJob);
Q_ASSERT( d->m_status == JobNotStarted );
d->m_status = JobRunning;
......@@ -245,7 +269,8 @@ void OutputExecuteJob::start()
setDelegate( new OutputDelegate );
connect(model(), &OutputModel::progress, this, [&](const IFilterStrategy::Progress& progress) {
connect(model(), &OutputModel::progress, this, [this](const IFilterStrategy::Progress& progress) {
Q_D(OutputExecuteJob);
d->emitProgress(progress);
});
......@@ -296,6 +321,8 @@ void OutputExecuteJob::start()
bool OutputExecuteJob::doKill()
{
Q_D(OutputExecuteJob);
const int terminateKillTimeout = 1000; // msecs
if( d->m_status != JobRunning ) {
......@@ -323,6 +350,8 @@ bool OutputExecuteJob::doKill()
void OutputExecuteJob::childProcessError( QProcess::ProcessError processError )
{
Q_D(OutputExecuteJob);
// This can be called twice: one time via an error() signal, and second - from childProcessExited().
// Avoid doing things in second time.
if( d->m_status != OutputExecuteJob::JobRunning )
......@@ -371,6 +400,8 @@ void OutputExecuteJob::childProcessError( QProcess::ProcessError processError )
void OutputExecuteJob::childProcessExited( int exitCode, QProcess::ExitStatus exitStatus )
{
Q_D(OutputExecuteJob);
if( d->m_status != JobRunning )
return;
......@@ -424,6 +455,8 @@ void OutputExecuteJob::postProcessStderr( const QStringList& lines )
void OutputExecuteJob::setFilteringStrategy( OutputModel::OutputFilterStrategy strategy )
{
Q_D(OutputExecuteJob);
d->m_filteringStrategy = strategy;
// clear the other
......@@ -432,6 +465,8 @@ void OutputExecuteJob::setFilteringStrategy( OutputModel::OutputFilterStrategy s
void OutputExecuteJob::setFilteringStrategy(IFilterStrategy* filterStrategy)
{
Q_D(OutputExecuteJob);
d->m_filteringStrategyPtr.reset(filterStrategy);
// clear the other
......@@ -440,11 +475,15 @@ void OutputExecuteJob::setFilteringStrategy(IFilterStrategy* filterStrategy)
OutputExecuteJob::JobProperties OutputExecuteJob::properties() const
{
Q_D(const OutputExecuteJob);
return d->m_properties;
}
void OutputExecuteJob::setProperties( OutputExecuteJob::JobProperties properties, bool override )
{
Q_D(OutputExecuteJob);
if( override ) {
d->m_properties = properties;
} else {
......@@ -454,47 +493,65 @@ void OutputExecuteJob::setProperties( OutputExecuteJob::JobProperties properties
void OutputExecuteJob::unsetProperties( OutputExecuteJob::JobProperties properties )
{
Q_D(OutputExecuteJob);
d->m_properties &= ~properties;
}
QString OutputExecuteJob::environmentProfile() const
{
Q_D(const OutputExecuteJob);
return d->m_environmentProfile;
}
void OutputExecuteJob::setEnvironmentProfile( const QString& profile )
{
Q_D(OutputExecuteJob);
d->m_environmentProfile = profile;
}
void OutputExecuteJob::addEnvironmentOverride( const QString& name, const QString& value )
{
Q_D(OutputExecuteJob);
d->m_environmentOverrides[name] = value;
}
void OutputExecuteJob::removeEnvironmentOverride( const QString& name )
{
Q_D(OutputExecuteJob);
d->m_environmentOverrides.remove( name );
}
void OutputExecuteJob::setExecuteOnHost(bool executeHost)
{
Q_D(OutputExecuteJob);
d->m_executeOnHost = executeHost;
}
bool OutputExecuteJob::executeOnHost() const
{
Q_D(const OutputExecuteJob);
return d->m_executeOnHost;
}
bool OutputExecuteJob::checkExitCode() const
{
Q_D(const OutputExecuteJob);
return d->m_checkExitCode;
}
void OutputExecuteJob::setCheckExitCode(bool check)
{
Q_D(OutputExecuteJob);
d->m_checkExitCode = check;
}
......
......@@ -27,6 +27,7 @@
namespace KDevelop
{
class OutputExecuteJobPrivate;
class KDEVPLATFORMOUTPUTVIEW_EXPORT OutputExecuteJob : public OutputJob
{
......@@ -256,7 +257,8 @@ protected Q_SLOTS:
virtual void childProcessError( QProcess::ProcessError processError );
private:
const QScopedPointer<class OutputExecuteJobPrivate> d;
const QScopedPointer<class OutputExecuteJobPrivate> d_ptr;
Q_DECLARE_PRIVATE(OutputExecuteJob)
friend class OutputExecuteJobPrivate;
};
......
......@@ -142,7 +142,7 @@ void CompilerFilterStrategyPrivate::putDirAtEnd(const Path& pathToInsert)
}
CompilerFilterStrategy::CompilerFilterStrategy(const QUrl& buildDir)
: d(new CompilerFilterStrategyPrivate( buildDir ))
: d_ptr(new CompilerFilterStrategyPrivate(buildDir))
{
}
......@@ -150,6 +150,8 @@ CompilerFilterStrategy::~CompilerFilterStrategy() = default;
QVector<QString> CompilerFilterStrategy::currentDirs() const
{
Q_D(const CompilerFilterStrategy);
QVector<QString> ret;
ret.reserve(d->m_currentDirs.size());
for (const auto& path : qAsConst(d->m_currentDirs)) {
......@@ -160,6 +162,8 @@ QVector<QString> CompilerFilterStrategy::currentDirs() const
FilteredItem CompilerFilterStrategy::actionInLine(const QString& line)
{
Q_D(CompilerFilterStrategy);
// A list of filters for possible compiler, linker, and make actions
static const ActionFormat ACTION_FILTERS[] = {
ActionFormat( 2,
......@@ -233,6 +237,8 @@ FilteredItem CompilerFilterStrategy::actionInLine(const QString& line)
FilteredItem CompilerFilterStrategy::errorInLine(const QString& line)
{
Q_D(CompilerFilterStrategy);
// All the possible string that indicate an error if we via Regex have been able to
// extract file and linenumber from a given outputline
// TODO: This seems clumsy -- and requires another scan of the line.
......
......@@ -36,6 +36,7 @@
namespace KDevelop
{
class CompilerFilterStrategyPrivate;
/**
* This filter strategy is for not applying any filtering at all. Implementation of the
......@@ -71,7 +72,8 @@ public:
QVector<QString> currentDirs() const;
private:
const QScopedPointer<class CompilerFilterStrategyPrivate> d;
const QScopedPointer<class CompilerFilterStrategyPrivate> d_ptr;
Q_DECLARE_PRIVATE(CompilerFilterStrategy)
};
/**
......
......@@ -50,7 +50,7 @@ public:
OutputJob::OutputJob(QObject* parent, OutputJobVerbosity verbosity)
: KJob(parent)
, d(new OutputJobPrivate(verbosity))
, d_ptr(new OutputJobPrivate(verbosity))
{
}
......@@ -58,6 +58,8 @@ OutputJob::~OutputJob() = default;
void OutputJob::startOutput()
{
Q_D(OutputJob);
IPlugin* i = ICore::self()->pluginController()->pluginForExtension(QStringLiteral("org.kdevelop.IOutputView"));
if( i )
{
......@@ -102,6 +104,8 @@ void OutputJob::startOutput()
void OutputJob::outputViewRemoved(int toolViewId, int id)
{
Q_D(OutputJob);
Q_UNUSED(toolViewId);
if (id == d->outputId && d->killJobOnOutputClose) {
// Make sure that the job emits result signal as the job
......@@ -114,6 +118,8 @@ void OutputJob::outputViewRemoved(int toolViewId, int id)
void KDevelop::OutputJob::setTitle(const QString & title)
{
Q_D(OutputJob);
d->title = title;
if (d->outputId >= 0 && d->standardToolView >= 0) {
IPlugin* i = ICore::self()->pluginController()->pluginForExtension(QStringLiteral("org.kdevelop.IOutputView"));
......@@ -130,21 +136,29 @@ void KDevelop::OutputJob::setTitle(const QString & title)
void KDevelop::OutputJob::setViewType(IOutputView::ViewType type)
{
Q_D(OutputJob);
d->type = type;
}
void KDevelop::OutputJob::setBehaviours(IOutputView::Behaviours behaviours)
{
Q_D(OutputJob);
d->behaviours = behaviours;
}
void KDevelop::OutputJob::setKillJobOnOutputClose(bool killJobOnOutputClose)
{
Q_D(OutputJob);
d->killJobOnOutputClose = killJobOnOutputClose;
}
void KDevelop::OutputJob::setModel(QAbstractItemModel * model)
{
Q_D(OutputJob);
if (d->outputModel) {
delete d->outputModel;
}
......@@ -158,41 +172,57 @@ void KDevelop::OutputJob::setModel(QAbstractItemModel * model)
void KDevelop::OutputJob::setDelegate(QAbstractItemDelegate * delegate)
{
Q_D(OutputJob);
d->outputDelegate = delegate;
}
QAbstractItemModel * KDevelop::OutputJob::model() const
{
Q_D(const OutputJob);
return d->outputModel;
}
void KDevelop::OutputJob::setStandardToolView(IOutputView::StandardToolView standard)
{
Q_D(OutputJob);
d->standardToolView = standard;
}
void OutputJob::setToolTitle(const QString& title)
{
Q_D(OutputJob);
d->toolTitle = title;
}
void OutputJob::setToolIcon(const QIcon& icon)
{
Q_D(OutputJob);
d->toolIcon = icon;
}
int OutputJob::outputId() const
{
Q_D(const OutputJob);
return d->outputId;
}
OutputJob::OutputJobVerbosity OutputJob::verbosity() const
{
Q_D(const OutputJob);
return d->verbosity;
}
void OutputJob::setVerbosity(OutputJob::OutputJobVerbosity verbosity)
{
Q_D(OutputJob);
d->verbosity = verbosity;
}
......@@ -29,6 +29,7 @@ class QIcon;
namespace KDevelop
{
class OutputJobPrivate;
class KDEVPLATFORMOUTPUTVIEW_EXPORT OutputJob : public KJob
{
......@@ -89,7 +90,8 @@ private Q_SLOTS:
void outputViewRemoved(int , int id);
private:
const QScopedPointer<class OutputJobPrivate> d;
const QScopedPointer<class OutputJobPrivate> d_ptr;
Q_DECLARE_PRIVATE(OutputJob)
};
}
......
......@@ -240,13 +240,13 @@ OutputModelPrivate::~OutputModelPrivate()
OutputModel::OutputModel( const QUrl& builddir, QObject* parent )
: QAbstractListModel(parent)
, d( new OutputModelPrivate( this, builddir ) )
, d_ptr(new OutputModelPrivate(this, builddir))
{
}
OutputModel::OutputModel( QObject* parent )
: QAbstractListModel(parent)
, d( new OutputModelPrivate( this ) )
, d_ptr(new OutputModelPrivate(this))
{
}
......@@ -254,6 +254,8 @@ OutputModel::~OutputModel() = default;
QVariant OutputModel::data(const QModelIndex& idx , int role ) const
{
Q_D(const OutputModel);
if( d->isValidIndex(idx, rowCount()) )
{
switch( role )
......@@ -271,6 +273,8 @@ QVariant OutputModel::data(const QModelIndex& idx , int role ) const
int OutputModel::rowCount( const QModelIndex& parent ) const
{
Q_D(const OutputModel);
if( !parent.isValid() )
return d->m_filteredItems.count();
return 0;
......@@ -283,6 +287,8 @@ QVariant OutputModel::headerData( int, Qt::Orientation, int ) const
void OutputModel::activate( const QModelIndex& index )
{
Q_D(OutputModel);
if( index.model() != this || !d->isValidIndex(index, rowCount()) )
{
return;
......@@ -313,6 +319,8 @@ void OutputModel::activate( const QModelIndex& index )
QModelIndex OutputModel::firstHighlightIndex()
{
Q_D(OutputModel);
if( !d->m_errorItems.empty() ) {
return index( *d->m_errorItems.begin(), 0, QModelIndex() );
}
......@@ -328,6 +336,8 @@ QModelIndex OutputModel::firstHighlightIndex()
QModelIndex OutputModel::nextHighlightIndex( const QModelIndex &currentIdx )
{
Q_D(OutputModel);
int startrow = d->isValidIndex(currentIdx, rowCount()) ? currentIdx.row() + 1 : 0;
if( !d->m_errorItems.empty() )
......@@ -354,6 +364,8 @@ QModelIndex OutputModel::nextHighlightIndex( const QModelIndex &currentIdx )
QModelIndex OutputModel::previousHighlightIndex( const QModelIndex &currentIdx )
{
Q_D(OutputModel);
//We have to ensure that startrow is >= rowCount - 1 to get a positive value from the % operation.
int startrow = rowCount() + (d->isValidIndex(currentIdx, rowCount()) ? currentIdx.row() : rowCount()) - 1;
......@@ -385,6 +397,8 @@ QModelIndex OutputModel::previousHighlightIndex( const QModelIndex &currentIdx )
QModelIndex OutputModel::lastHighlightIndex()
{
Q_D(OutputModel);
if( !d->m_errorItems.empty() ) {
return index( *d->m_errorItems.rbegin(), 0, QModelIndex() );
}
......@@ -400,6 +414,8 @@ QModelIndex OutputModel::lastHighlightIndex()
void OutputModel::setFilteringStrategy(const OutputFilterStrategy& currentStrategy)
{
Q_D(OutputModel);
// TODO: Turn into factory, decouple from OutputModel
IFilterStrategy* filter = nullptr;
switch( currentStrategy )
......@@ -430,12 +446,16 @@ void OutputModel::setFilteringStrategy(const OutputFilterStrategy& currentStrate
void OutputModel::setFilteringStrategy(IFilterStrategy* filterStrategy)
{
Q_D(OutputModel);
QMetaObject::invokeMethod(d->worker, "changeFilterStrategy",
Q_ARG(KDevelop::IFilterStrategy*, filterStrategy));
}
void OutputModel::appendLines( const QStringList& lines )
{
Q_D(OutputModel);
if( lines.isEmpty() )
return;
......@@ -450,11 +470,15 @@ void OutputModel::appendLine( const QString& line )
void OutputModel::ensureAllDone()
{
Q_D(OutputModel);
QMetaObject::invokeMethod(d->worker, "flushBuffers");
}
void OutputModel::clear()
{
Q_D(OutputModel);
ensureAllDone();
beginResetModel();
d->m_filteredItems.clear();
......
......@@ -32,6 +32,7 @@ class QUrl;
namespace KDevelop
{
class OutputModelPrivate;
class KDEVPLATFORMOUTPUTVIEW_EXPORT OutputModel : public QAbstractListModel, public KDevelop::IOutputViewModel
{
......@@ -82,7 +83,8 @@ Q_SIGNALS:
void allDone();
private:
const QScopedPointer<class OutputModelPrivate> d;
const QScopedPointer<class OutputModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(OutputModel)
friend class OutputModelPrivate;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment