[Differential] [Commented On] D4435: Feature: Add file template for QObject with pimpl
Friedrich W. H. Kossebau
noreply at phabricator.kde.org
Sat Feb 4 21:53:08 UTC 2017
kossebau added a comment.
The QObject non-pimpl changes are supposed to be in a different commit, only added here for the big picture. That commit extracts reusable snippets and adds creation of signals for the properties,
Example generation:
name: KDevelop::Foo
member: QString bar
methods selected: constructor, copy constructor, destructor, event()
foo.h:
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright (C) 2017 Hans Entwickler <email>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef KDEVELOP_FOO_H
#define KDEVELOP_FOO_H
#include <qt5/QtCore/QObject>
namespace KDevelop {
/**
* @todo write docs
*/
class Foo : public QObject
{
Q_OBJECT
Q_PROPERTY(QString bar READ bar WRITE setBar NOTIFY barChanged)
public:
/**
* Default constructor
*/
Foo();
/**
* Copy Constructor
*
* @param other TODO
*/
Foo(const Foo& other);
/**
* Destructor
*/
~Foo();
/**
* @todo write docs
*
* @param event TODO
* @return TODO
*/
virtual bool event(QEvent* event);
/**
* @return the bar
*/
QString bar() const;
public Q_SLOTS:
/**
* Sets the bar.
*
* @param bar the new bar
*/
void setBar(const QString& bar);
Q_SIGNALS:
void barChanged(const QString& bar);
private:
class FooPrivate* const d_ptr;
Q_DECLARE_PRIVATE(Foo)
};
}
#endif // KDEVELOP_FOO_H
foo_p.h:
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright (C) 2017 Hans Entwickler <email>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef KDEVELOP_FOO_P_H
#define KDEVELOP_FOO_P_H
namespace KDevelop {
/**
* @todo write docs
*/
class FooPrivate
{
public:
QString bar;
};
}
#endif // KDEVELOP_FOO_P_H
foo.cpp:
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright (C) 2017 Hans Entwickler <email>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "foo.h"
#include "foo_p.h"
using namespace KDevelop;
Foo::Foo()
: d_ptr(new FooPrivate())
{
}
Foo::Foo(const Foo& other)
: d_ptr(new FooPrivate())
{
}
Foo::~Foo()
{
delete d_ptr;
}
bool Foo::event(QEvent* event)
{
}
QString Foo::bar() const
{
Q_D(const Foo);
return d->bar;
}
void Foo::setBar(const QString& bar)
{
Q_D(Foo);
if (d->bar == bar) {
return;
}
d->bar = bar;
emit barChanged(d->bar);
}
REPOSITORY
R32 KDevelop
REVISION DETAIL
https://phabricator.kde.org/D4435
EMAIL PREFERENCES
https://phabricator.kde.org/settings/panel/emailpreferences/
To: kossebau, #kdevelop
Cc: kdevelop-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20170204/4b4c0d16/attachment.html>
More information about the KDevelop-devel
mailing list