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

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

parent 11009380
......@@ -50,7 +50,7 @@ public:
AggregateModel::AggregateModel(QObject *parent)
:QAbstractItemModel(parent)
,d(new AggregateModelPrivate())
,d_ptr(new AggregateModelPrivate())
{
}
......@@ -58,6 +58,8 @@ AggregateModel::~AggregateModel() = default;
void AggregateModel::addModel(const QString &name, QStandardItemModel *model)
{
Q_D(AggregateModel);
beginResetModel();
d->modelList << model;
d->modelNames[model] = name;
......@@ -66,6 +68,8 @@ void AggregateModel::addModel(const QString &name, QStandardItemModel *model)
void AggregateModel::removeModel(QStandardItemModel *model)
{
Q_D(AggregateModel);
beginResetModel();
d->modelList.removeAll(model);
d->modelNames.remove(model);
......@@ -102,6 +106,8 @@ int AggregateModel::columnCount(const QModelIndex &parent) const
int AggregateModel::rowCount(const QModelIndex &parent) const
{
Q_D(const AggregateModel);
if (!parent.isValid())
{
//toplevel items represent aggregated models
......@@ -130,6 +136,8 @@ int AggregateModel::rowCount(const QModelIndex &parent) const
QVariant AggregateModel::data(const QModelIndex &index, int role) const
{
Q_D(const AggregateModel);
if (!index.isValid() || (role != Qt::DisplayRole))
return QVariant();
......@@ -148,6 +156,8 @@ QVariant AggregateModel::data(const QModelIndex &index, int role) const
QModelIndex AggregateModel::parent(const QModelIndex &index) const
{
Q_D(const AggregateModel);
if (!index.isValid())
return QModelIndex();
......@@ -179,6 +189,8 @@ QModelIndex AggregateModel::parent(const QModelIndex &index) const
QModelIndex AggregateModel::index(int row, int column, const QModelIndex &parent) const
{
Q_D(const AggregateModel);
if (row < 0 || column < 0)
return QModelIndex();
......
......@@ -26,6 +26,8 @@ class QStandardItemModel;
namespace Sublime {
class AggregateModelPrivate;
/**
@short A model to combine several QStandardItemModel's into one.
Combine standard models into the aggregate model to display them in the one view.
......@@ -87,7 +89,8 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
private:
const QScopedPointer<class AggregateModelPrivate> d;
const QScopedPointer<class AggregateModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(AggregateModel)
};
}
......
......@@ -102,8 +102,11 @@ public:
// class Area
Area::Area(Controller *controller, const QString &name, const QString &title)
:QObject(controller), d( new AreaPrivate() )
: QObject(controller)
, d_ptr(new AreaPrivate())
{
Q_D(Area);
// FIXME: using objectName seems fishy. Introduce areaType method,
// or some such.
setObjectName(name);
......@@ -116,8 +119,11 @@ Area::Area(Controller *controller, const QString &name, const QString &title)
}
Area::Area(const Area &area)
: QObject(area.controller()), d( new AreaPrivate( *(area.d) ) )
: QObject(area.controller())
, d_ptr(new AreaPrivate(*(area.d_ptr)))
{
Q_D(Area);
setObjectName(area.objectName());
//clone tool views
......@@ -130,6 +136,8 @@ Area::Area(const Area &area)
void Area::initialize()
{
Q_D(Area);
connect(this, &Area::viewAdded,
d->controller, &Controller::notifyViewAdded);
connect(this, &Area::aboutToRemoveView,
......@@ -154,16 +162,22 @@ Area::~Area() = default;
View* Area::activeView()
{
Q_D(Area);
return d->activeView.data();
}
void Area::setActiveView(View* view)
{
Q_D(Area);
d->activeView = view;
}
void Area::addView(View *view, AreaIndex *index, View *after)
{
Q_D(Area);
//View *after = 0;
if (!after && controller()->openAfterCurrent()) {
after = activeView();
......@@ -177,6 +191,8 @@ void Area::addView(View *view, AreaIndex *index, View *after)
void Area::addView(View *view, View *after)
{
Q_D(Area);
AreaIndex *index = d->currentIndex;
if (after)
{
......@@ -215,6 +231,8 @@ View* Area::removeView(View *view)
AreaIndex *Area::indexOf(View *view)
{
Q_D(Area);
AreaPrivate::ViewFinder f(view);
walkViews(f, d->rootIndex.data());
return f.index;
......@@ -222,11 +240,15 @@ AreaIndex *Area::indexOf(View *view)
RootAreaIndex *Area::rootIndex() const
{
Q_D(const Area);
return d->rootIndex.data();
}
void Area::addToolView(View *view, Position defaultPosition)
{
Q_D(Area);
d->toolViews.append(view);
const QString id = view->document()->documentSpecifier();
const Position position = d->desiredToolViews.value(id, defaultPosition);
......@@ -242,6 +264,8 @@ void Sublime::Area::raiseToolView(View * toolView)
View* Area::removeToolView(View *view)
{
Q_D(Area);
if (!d->toolViews.contains(view))
return nullptr;
......@@ -256,6 +280,8 @@ View* Area::removeToolView(View *view)
void Area::moveToolView(View *toolView, Position newPosition)
{
Q_D(Area);
if (!d->toolViews.contains(toolView))
return;
......@@ -265,23 +291,31 @@ void Area::moveToolView(View *toolView, Position newPosition)
emit toolViewMoved(toolView, newPosition);
}
QList<View*> &Area::toolViews() const
const QList<View*> &Area::toolViews() const
{
Q_D(const Area);
return d->toolViews;
}
Position Area::toolViewPosition(View *toolView) const
{
Q_D(const Area);
return d->toolViewPositions[toolView];
}
Controller *Area::controller() const
{
Q_D(const Area);
return d->controller;
}
QList<View*> Sublime::Area::views()
{
Q_D(Area);
AreaPrivate::ViewLister lister;
walkViews(lister, d->rootIndex.data());
return lister.views;
......@@ -289,21 +323,25 @@ QList<View*> Sublime::Area::views()
QString Area::title() const
{
Q_D(const Area);
return d->title;
}
void Area::setTitle(const QString &title)
{
Q_D(Area);
d->title = title;
}
void Area::save(KConfigGroup& group) const
{
Q_D(const Area);
QStringList desired;
desired.reserve(d->desiredToolViews.size());
QMap<QString, Sublime::Position>::iterator i, e;
for (i = d->desiredToolViews.begin(), e = d->desiredToolViews.end(); i != e; ++i)
{
for (auto i = d->desiredToolViews.begin(), e = d->desiredToolViews.end(); i != e; ++i) {
desired << i.key() + QLatin1Char(':') + QString::number(static_cast<int>(i.value()));
}
group.writeEntry("desired views", desired);
......@@ -317,6 +355,8 @@ void Area::save(KConfigGroup& group) const
void Area::load(const KConfigGroup& group)
{
Q_D(Area);
qCDebug(SUBLIME) << "loading areas config";
d->desiredToolViews.clear();
const QStringList desired = group.readEntry("desired views", QStringList());
......@@ -346,16 +386,22 @@ void Area::load(const KConfigGroup& group)
bool Area::wantToolView(const QString& id)
{
Q_D(Area);
return (d->desiredToolViews.contains(id));
}
void Area::setShownToolViews(Sublime::Position pos, const QStringList& ids)
{
Q_D(Area);
d->shownToolViews[pos] = ids;
}
QStringList Area::shownToolViews(Sublime::Position pos) const
{
Q_D(const Area);
if (pos == Sublime::AllPositions) {
QStringList allIds;
allIds.reserve(d->shownToolViews.size());
......@@ -371,16 +417,22 @@ QStringList Area::shownToolViews(Sublime::Position pos) const
void Area::setDesiredToolViews(
const QMap<QString, Sublime::Position>& desiredToolViews)
{
Q_D(Area);
d->desiredToolViews = desiredToolViews;
}
QString Area::iconName() const
{
Q_D(const Area);
return d->iconName;
}
void Area::setIconName(const QString& iconName)
{
Q_D(Area);
d->iconName = iconName;
}
......@@ -388,18 +440,22 @@ void Area::positionChanged(View *view, int newPos)
{
qCDebug(SUBLIME) << view << newPos;
AreaIndex *index = indexOf(view);
index->views().move(index->views().indexOf(view), newPos);
index->moveViewPosition(view, newPos);
}
QString Area::workingSet() const
{
Q_D(const Area);
return d->workingSet;
}
void Area::setWorkingSet(const QString& name)
{
Q_D(Area);
if(name != d->workingSet) {
qCDebug(SUBLIME) << this << "setting new working-set" << name;
QString oldName = d->workingSet;
......@@ -466,11 +522,15 @@ void Area::clearDocuments()
QList<QAction*> Area::actions() const
{
Q_D(const Area);
return d->m_actions;
}
void Area::addAction(QAction* action)
{
Q_D(Area);
Q_ASSERT(!d->m_actions.contains(action));
connect(action, &QAction::destroyed, this, &Area::actionDestroyed);
d->m_actions.append(action);
......@@ -478,6 +538,8 @@ void Area::addAction(QAction* action)
void Area::actionDestroyed(QObject* action)
{
Q_D(Area);
d->m_actions.removeAll(qobject_cast<QAction*>(action));
}
......
......@@ -35,6 +35,7 @@ class AreaIndex;
class RootAreaIndex;
class Controller;
class View;
class AreaPrivate;
/**
@short Area - the universal view container
......@@ -152,7 +153,7 @@ public:
/**Raise tool view.*/
void raiseToolView(View *toolView);
/**@return the list of tool views in the area. No particular sort order is guaranteed.*/
QList<View*> &toolViews() const;
const QList<View*> &toolViews() const;
/**@return the current position of @p toolView in the area.*/
Position toolViewPosition(View *toolView) const;
......@@ -276,7 +277,8 @@ private:
void initialize();
private:
const QScopedPointer<class AreaPrivate> d;
const QScopedPointer<class AreaPrivate> d_ptr;
Q_DECLARE_PRIVATE(Area)
};
}
......
......@@ -70,17 +70,24 @@ public:
// class AreaIndex
AreaIndex::AreaIndex() : d(new AreaIndexPrivate)
AreaIndex::AreaIndex()
: d_ptr(new AreaIndexPrivate)
{
}
AreaIndex::AreaIndex(AreaIndex *parent) : d(new AreaIndexPrivate)
AreaIndex::AreaIndex(AreaIndex *parent)
: d_ptr(new AreaIndexPrivate)
{
Q_D(AreaIndex);
d->parent = parent;
}
AreaIndex::AreaIndex(const AreaIndex &index) : d(new AreaIndexPrivate( *(index.d) ) )
AreaIndex::AreaIndex(const AreaIndex &index)
: d_ptr(new AreaIndexPrivate(*(index.d_ptr)))
{
Q_D(AreaIndex);
qCDebug(SUBLIME) << "copying area index";
if (d->first)
d->first->setParent(this);
......@@ -97,6 +104,8 @@ AreaIndex::~AreaIndex() = default;
void AreaIndex::add(View *view, View *after)
{
Q_D(AreaIndex);
//we can not add views to the areas that have already been split
if (d->isSplit())
return;
......@@ -109,6 +118,8 @@ void AreaIndex::add(View *view, View *after)
void AreaIndex::remove(View *view)
{
Q_D(AreaIndex);
if (d->isSplit())
return;
......@@ -119,6 +130,8 @@ void AreaIndex::remove(View *view)
void AreaIndex::split(Qt::Orientation orientation, bool moveViewsToSecond)
{
Q_D(AreaIndex);
//we can not split areas that have already been split
if (d->isSplit())
return;
......@@ -135,6 +148,8 @@ void AreaIndex::split(Qt::Orientation orientation, bool moveViewsToSecond)
void AreaIndex::split(View *newView, Qt::Orientation orientation)
{
Q_D(AreaIndex);
split(orientation);
//make new view as second widget in splitter
......@@ -143,6 +158,8 @@ void AreaIndex::split(View *newView, Qt::Orientation orientation)
void AreaIndex::unsplit(AreaIndex *childToRemove)
{
Q_D(AreaIndex);
if (!d->isSplit())
return;
......@@ -159,12 +176,14 @@ void AreaIndex::unsplit(AreaIndex *childToRemove)
void AreaIndex::copyChildrenTo(AreaIndex *target)
{
Q_D(AreaIndex);
if (!d->first || !d->second)
return;
target->d->first = d->first;
target->d->second = d->second;
target->d->first->setParent(target);
target->d->second->setParent(target);
target->d_ptr->first = d->first;
target->d_ptr->second = d->second;
target->d_ptr->first->setParent(target);
target->d_ptr->second->setParent(target);
d->first = nullptr;
d->second = nullptr;
......@@ -172,62 +191,95 @@ void AreaIndex::copyChildrenTo(AreaIndex *target)
void AreaIndex::moveViewsTo(AreaIndex *target)
{
target->d->views = d->views;
Q_D(AreaIndex);
target->d_ptr->views = d->views;
d->views.clear();
}
QList<View*> &AreaIndex::views() const
void AreaIndex::moveViewPosition(View* view, int newPos)
{
Q_D(AreaIndex);
const auto oldPos = d->views.indexOf(view);
d->views.move(oldPos, newPos);
}
const QList<View*>& AreaIndex::views() const
{
Q_D(const AreaIndex);
return d->views;
}
View *AreaIndex::viewAt(int position) const
{
Q_D(const AreaIndex);
return d->views.value(position, nullptr);
}
int AreaIndex::viewCount() const
{
Q_D(const AreaIndex);
return d->views.count();
}
bool AreaIndex::hasView(View *view) const
{
Q_D(const AreaIndex);
return d->views.contains(view);
}
AreaIndex *AreaIndex::parent() const
{
Q_D(const AreaIndex);
return d->parent;
}
void AreaIndex::setParent(AreaIndex *parent)
{
Q_D(AreaIndex);
d->parent = parent;
}
AreaIndex *AreaIndex::first() const
{
Q_D(const AreaIndex);
return d->first;
}
AreaIndex *AreaIndex::second() const
{
Q_D(const AreaIndex);
return d->second;
}
Qt::Orientation AreaIndex::orientation() const
{
Q_D(const AreaIndex);
return d->orientation;
}
bool Sublime::AreaIndex::isSplit() const
{
Q_D(const AreaIndex);
return d->isSplit();
}
void Sublime::AreaIndex::setOrientation(Qt::Orientation orientation) const
void Sublime::AreaIndex::setOrientation(Qt::Orientation orientation)
{
Q_D(AreaIndex);
d->orientation = orientation;
}
......
......@@ -28,6 +28,7 @@
namespace Sublime {
class View;
class AreaIndexPrivate;
/**
@short Index denotes the position of the view in the split area.
......@@ -119,7 +120,7 @@ public:
/**@return the orientation of the splitter for this index.*/
Qt::Orientation orientation() const;
/**Set the orientation of the splitter for this index.*/
void setOrientation(Qt::Orientation orientation) const;
void setOrientation(Qt::Orientation orientation);
/**Adds view to the list of views in this position.
Does nothing if the view is already split.
......@@ -154,7 +155,9 @@ public:
/**@return true if there's a stacked @p view at this index.*/
bool hasView(View *view) const;
/**@return the list of views at this index.*/
QList<View*> &views() const;
const QList<View*>& views() const;
/** Moves @p view to position @p newPos */
void moveViewPosition(View* view, int newPos);
protected:
/**Constructor for Root index.*/
......@@ -173,7 +176,8 @@ private:
void copyChildrenTo(AreaIndex *target);
private:
const QScopedPointer<class AreaIndexPrivate> d;
const QScopedPointer<class AreaIndexPrivate> d_ptr;
Q_DECLARE_PRIVATE(AreaIndex)
};
/**
......
......@@ -301,8 +301,11 @@ public:
// class Container
Container::Container(QWidget *parent)
:QWidget(parent), d(new ContainerPrivate())
: QWidget(parent)
, d_ptr(new ContainerPrivate())
{
Q_D(Container);
KAcceleratorManager::setNoAccel(this);
auto *l = new QBoxLayout(QBoxLayout::TopToBottom, this);
......@@ -378,6 +381,8 @@ bool Container::configTabBarVisible()
void Container::setLeftCornerWidget(QWidget* widget)
{
Q_D(Container);
if(d->leftCornerWidget.data() == widget) {
if(d->leftCornerWidget)
d->leftCornerWidget.data()->setParent(nullptr);
......@@ -395,6 +400,8 @@ void Container::setLeftCornerWidget(QWidget* widget)
QList<View*> Container::views() const
{
Q_D(const Container);