Add missing #pragma once + missing include * speeds up incremental builds as changes to a header will not always need the full mocs_compilation.cpp for all the target's headers rebuild, while having a moc file sourced into a source file only adds minor extra costs, due to small own code and the used headers usually already covered by the source file, being for the same class/struct * seems to not slow down clean builds, due to empty mocs_compilation.cpp resulting in those quickly processed, while the minor extra cost of the sourced moc files does not outweigh that in summary. Measured times actually improved by some percent points. (ideally CMake would just skip empty mocs_compilation.cpp & its object file one day) * enables compiler to see all methods of a class in same compilation unit to do some sanity checks * potentially more inlining in general, due to more in the compilation unit * allows to keep using more forward declarations in the header, as with the moc code being sourced into the cpp file there definitions can be ensured and often are already for the needs of the normal class methods
49 lines
964 B
C++
49 lines
964 B
C++
// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
#include <KColorSchemeManager>
|
|
#include <QAbstractItemModel>
|
|
|
|
#include "colorschemer.h"
|
|
|
|
ColorSchemer::ColorSchemer(QObject *parent)
|
|
: QObject(parent)
|
|
, c(new KColorSchemeManager(this))
|
|
{
|
|
}
|
|
|
|
ColorSchemer::~ColorSchemer()
|
|
{
|
|
}
|
|
|
|
QAbstractItemModel *ColorSchemer::model() const
|
|
{
|
|
return c->model();
|
|
}
|
|
|
|
void ColorSchemer::apply(int idx)
|
|
{
|
|
c->activateScheme(c->model()->index(idx, 0));
|
|
}
|
|
|
|
void ColorSchemer::apply(const QString &name)
|
|
{
|
|
c->activateScheme(c->indexForScheme(name));
|
|
}
|
|
|
|
int ColorSchemer::indexForScheme(const QString &name) const
|
|
{
|
|
auto index = c->indexForScheme(name).row();
|
|
if (index == -1) {
|
|
index = 0;
|
|
}
|
|
return index;
|
|
}
|
|
|
|
QString ColorSchemer::nameForIndex(int index) const
|
|
{
|
|
return c->model()->data(c->model()->index(index, 0), Qt::DisplayRole).toString();
|
|
}
|
|
|
|
#include "moc_colorschemer.cpp"
|