[Examples] Fix build
* Add QStringLiteral et al where appropriate * Also add override keyword to avoid warnings * Minor style changes and cleanups Differential Revision: https://phabricator.kde.org/D10092
This commit is contained in:
parent
f906178713
commit
595fd88054
@ -49,7 +49,7 @@ bool DataContainersEngine::sourceRequestEvent(const QString &source)
|
||||
// the source to make sure it is indeed an http URL.
|
||||
QUrl url(source);
|
||||
qDebug() << "goin to fetch" << source << url << url.scheme();
|
||||
if (!url.scheme().startsWith("http", Qt::CaseInsensitive)) {
|
||||
if (!url.scheme().startsWith(QLatin1String("http"), Qt::CaseInsensitive)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,8 @@ public:
|
||||
DataContainersEngine(QObject *parent, const QVariantList &args);
|
||||
|
||||
protected:
|
||||
bool sourceRequestEvent(const QString &source);
|
||||
bool updateSourceEvent(const QString &source);
|
||||
bool sourceRequestEvent(const QString &source) override;
|
||||
bool updateSourceEvent(const QString &source) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -74,15 +74,15 @@ void HttpContainer::fetchFinished(KJob *job)
|
||||
// additional stats. Note that we don't include the source name, as that
|
||||
// is implied as this object *is* the DataContainer. setData is called
|
||||
// with just key/value pairs.
|
||||
setData("Contents", m_data);
|
||||
setData("Size", job->processedAmount(KJob::Bytes));
|
||||
setData(QStringLiteral("Contents"), m_data);
|
||||
setData(QStringLiteral("Size"), job->processedAmount(KJob::Bytes));
|
||||
|
||||
// Since we only create TransferJobs, it's safe to just static_cast here.
|
||||
// In many real-world situations, this isn't the safest thing to do and a
|
||||
// qobject_cast with a test on the result is often safer and cleaner.
|
||||
KIO::TransferJob *tjob = static_cast<KIO::TransferJob *>(job);
|
||||
setData("Error Page", tjob->isErrorPage());
|
||||
setData("Mimetype", tjob->mimetype());
|
||||
setData(QStringLiteral("Error Page"), tjob->isErrorPage());
|
||||
setData(QStringLiteral("Mimetype"), tjob->mimetype());
|
||||
|
||||
// Let DataContainer know we have data that needs storing
|
||||
setNeedsToBeStored(true);
|
||||
|
@ -33,7 +33,7 @@
|
||||
namespace KIO
|
||||
{
|
||||
class Job;
|
||||
};
|
||||
}
|
||||
|
||||
class HttpContainer : public Plasma::DataContainer
|
||||
{
|
||||
|
@ -56,21 +56,21 @@ void SimpleEngine::init()
|
||||
// This is the simplest form, with source name and one bit of data.
|
||||
// Note how the source name is not translated! They can be marked with
|
||||
// I18N_NOOP, however, if they should be translatable in a visualization.
|
||||
setData("Simple Source", i18n("Very simple data"));
|
||||
setData(QStringLiteral("Simple Source"), i18n("Very simple data"));
|
||||
|
||||
// a source can have multiple entries, differentiated by key names,
|
||||
// which are also not translated:
|
||||
setData("Multiple Source", "First", i18n("First"));
|
||||
setData("Multiple Source", "Second", i18n("Second"));
|
||||
setData(QStringLiteral("Multiple Source"), QStringLiteral("First"), i18n("First"));
|
||||
setData(QStringLiteral("Multiple Source"), QStringLiteral("Second"), i18n("Second"));
|
||||
|
||||
// We can also set the data up first and apply it all at once
|
||||
// Note how data types other than strings can be used as well; anything
|
||||
// that works with QVariant, in fact.
|
||||
Plasma::DataEngine::Data data;
|
||||
data.insert("Cow", "mooo");
|
||||
data.insert("Black", QColor(0, 0, 0));
|
||||
data.insert("Time", QTime::currentTime());
|
||||
setData("Another Source", data);
|
||||
data.insert(QStringLiteral("Cow"), QStringLiteral("mooo"));
|
||||
data.insert(QStringLiteral("Black"), QColor(0, 0, 0));
|
||||
data.insert(QStringLiteral("Time"), QTime::currentTime());
|
||||
setData(QStringLiteral("Another Source"), data);
|
||||
}
|
||||
|
||||
// export the plugin; use the plugin name and the class name
|
||||
|
@ -51,7 +51,7 @@ bool SourcesOnRequestEngine::sourceRequestEvent(const QString &source)
|
||||
|
||||
// We're going to reject any sources that start with the letter 'a'
|
||||
// to demonstrate how to reject a request in a DataEngine.
|
||||
if (source.startsWith('a') || source.startsWith('A')) {
|
||||
if (source.startsWith(QLatin1Char('a')) || source.startsWith(QLatin1Char('A'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -62,13 +62,13 @@ bool SourcesOnRequestEngine::sourceRequestEvent(const QString &source)
|
||||
// In such a case the DataEngine will remain happy and Do The Right Thing(tm)
|
||||
// but the visualization will not get the source connected to it as it
|
||||
// expects. So ALWAYS key the new data by the source string as below:
|
||||
setData(source, "Update Count", 0);
|
||||
setData(source, QStringLiteral("Update Count"), 0);
|
||||
|
||||
if (!modelForSource(source)) {
|
||||
QStandardItemModel *m = new QStandardItemModel;
|
||||
m->appendRow(new QStandardItem("Item1, first update"));
|
||||
m->appendRow(new QStandardItem("Item2, first update"));
|
||||
m->appendRow(new QStandardItem("Item3, first update"));
|
||||
m->appendRow(new QStandardItem(QStringLiteral("Item1, first update")));
|
||||
m->appendRow(new QStandardItem(QStringLiteral("Item2, first update")));
|
||||
m->appendRow(new QStandardItem(QStringLiteral("Item3, first update")));
|
||||
setModel(source, m);
|
||||
}
|
||||
|
||||
@ -92,15 +92,15 @@ bool SourcesOnRequestEngine::updateSourceEvent(const QString &source)
|
||||
// sourceRequestEvent, however, this will result in expected behavior: visualizations
|
||||
// connected to the sources which have setData called for them will be notified
|
||||
// of these changes.
|
||||
const int updateCount = containerForSource(source)->data().value("Update Count").toInt() + 1;
|
||||
setData(source, "Update Count", updateCount);
|
||||
const int updateCount = containerForSource(source)->data().value(QStringLiteral("Update Count")).toInt() + 1;
|
||||
setData(source, QStringLiteral("Update Count"), updateCount);
|
||||
|
||||
QStandardItemModel *m = qobject_cast<QStandardItemModel *>(modelForSource(source));
|
||||
if (m) {
|
||||
m->clear();
|
||||
m->appendRow(new QStandardItem(QString("Item1, update %1").arg(updateCount)));
|
||||
m->appendRow(new QStandardItem(QString("Item2, update %1").arg(updateCount)));
|
||||
m->appendRow(new QStandardItem(QString("Item3, update %1").arg(updateCount)));
|
||||
m->appendRow(new QStandardItem(QStringLiteral("Item1, update %1").arg(updateCount)));
|
||||
m->appendRow(new QStandardItem(QStringLiteral("Item2, update %1").arg(updateCount)));
|
||||
m->appendRow(new QStandardItem(QStringLiteral("Item3, update %1").arg(updateCount)));
|
||||
}
|
||||
|
||||
// Since we updated the source immediately here, we need to return true so the DataEngine
|
||||
|
@ -36,8 +36,8 @@ public:
|
||||
SourcesOnRequestEngine(QObject *parent, const QVariantList &args);
|
||||
|
||||
protected:
|
||||
bool sourceRequestEvent(const QString &source);
|
||||
bool updateSourceEvent(const QString &source);
|
||||
bool sourceRequestEvent(const QString &source) override;
|
||||
bool updateSourceEvent(const QString &source) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -44,8 +44,6 @@ CustomCorona::CustomCorona(QObject *parent)
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
|
||||
QRect CustomCorona::screenGeometry(int id) const
|
||||
{
|
||||
Q_UNUSED(id);
|
||||
@ -57,7 +55,6 @@ void CustomCorona::load()
|
||||
{
|
||||
loadLayout(QStringLiteral("exampleplasmashell-appletsrc"));
|
||||
|
||||
|
||||
bool desktopFound = false;
|
||||
for (auto c : containments()) {
|
||||
if (c->containmentType() == Plasma::Types::DesktopContainment) {
|
||||
@ -69,7 +66,7 @@ void CustomCorona::load()
|
||||
if (!desktopFound) {
|
||||
qDebug() << "Loading default layout";
|
||||
Plasma::Containment *c = createContainment(QStringLiteral("org.kde.desktopcontainment"));
|
||||
c->createApplet("org.kde.plasma.analogclock");
|
||||
c->createApplet(QStringLiteral("org.kde.plasma.analogclock"));
|
||||
saveLayout(QStringLiteral("exampleplasmashell-appletsrc"));
|
||||
}
|
||||
|
||||
@ -77,10 +74,9 @@ void CustomCorona::load()
|
||||
for (auto c : containments()) {
|
||||
if (c->containmentType() == Plasma::Types::DesktopContainment) {
|
||||
//example of a shell without a wallpaper
|
||||
c->setWallpaper("null");
|
||||
c->setWallpaper(QStringLiteral("null"));
|
||||
m_view->setContainment(c);
|
||||
QAction *removeAction = c->actions()->action(QStringLiteral("remove"));
|
||||
if(removeAction) {
|
||||
if (QAction *removeAction = c->actions()->action(QStringLiteral("remove"))) {
|
||||
removeAction->deleteLater();
|
||||
}
|
||||
break;
|
||||
|
@ -29,8 +29,8 @@ class CustomCorona : public Plasma::Corona
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CustomCorona(QObject * parent = nullptr);
|
||||
QRect screenGeometry(int id) const;
|
||||
explicit CustomCorona(QObject *parent = nullptr);
|
||||
QRect screenGeometry(int id) const override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void load();
|
||||
|
@ -27,14 +27,12 @@
|
||||
|
||||
#include "customcorona.h"
|
||||
|
||||
static const char version[] = "1.0";
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QQuickWindow::setDefaultAlphaBuffer(true);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationVersion(version);
|
||||
app.setApplicationVersion(QStringLiteral("1.0"));
|
||||
app.setOrganizationDomain(QStringLiteral("kde.org"));
|
||||
|
||||
KDBusService service(KDBusService::Unique);
|
||||
|
@ -37,7 +37,7 @@ QList<QAction *> ContextTest::contextualActions()
|
||||
Plasma::Containment *c = containment();
|
||||
Q_ASSERT(c);
|
||||
QList<QAction *> actions;
|
||||
actions << c->actions()->action("configure");
|
||||
actions << c->actions()->action(QStringLiteral("configure"));
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ public:
|
||||
|
||||
void init(const KConfigGroup &config);
|
||||
|
||||
QList<QAction *> contextualActions();
|
||||
QList<QAction *> contextualActions() override;
|
||||
|
||||
void performNextAction();
|
||||
void performPreviousAction();
|
||||
void performNextAction() override;
|
||||
void performPreviousAction() override;
|
||||
|
||||
QWidget *createConfigurationInterface(QWidget *parent);
|
||||
void configurationAccepted();
|
||||
void save(KConfigGroup &config);
|
||||
QWidget *createConfigurationInterface(QWidget *parent) override;
|
||||
void configurationAccepted() override;
|
||||
void save(KConfigGroup &config) override;
|
||||
|
||||
private:
|
||||
Ui::Config m_ui;
|
||||
|
Loading…
x
Reference in New Issue
Block a user