Kexi/Junior Jobs/Add d-pointers: Difference between revisions
< Kexi | Junior Jobs
No edit summary |
|||
Line 3: | Line 3: | ||
*maintainer of this task: staniek at kde.org | *maintainer of this task: staniek at kde.org | ||
*OPEN, DIFFICULTY=2/5 | *OPEN, DIFFICULTY=2/5 | ||
* | *Offered within [http://www.google-melange.com/gci/homepage/google/gci2012 Google Code-IN] program; splitted to two tasks: | ||
**[http://www.google-melange.com/gci/task/view/google/gci2012/7971213 Part 1] | |||
**[https://google-melange.appspot.com/gci/task/view/google/gci2012/8009216 Part 2] | |||
==Goal== | ==Goal== |
Revision as of 10:19, 29 November 2012
- maintainer of this task: staniek at kde.org
- OPEN, DIFFICULTY=2/5
- Offered within Google Code-IN program; splitted to two tasks:
Goal
Improve internal APIs in Kexi. This can be done easily by introducing d-pointers to classes that lack them.
Introduction
Read section about d-pointers on Techbase (d-pointers only, not shared d-pointers).
Classes that have to be converted are in this form:
// MyClass.h
class MyClass {
public:
MyClass();
private:
Foo m_foo;
};
// MyClass.cpp
MyClass::MyClass() {
m_foo/doSomething();
}
After converting to d-pointer it should be:
// MyClass.h
class MyClass {
public:
MyClass();
private:
class Private;
Private * const d;
};
// MyClass.cpp
class MyClass::Private {
public:
Private()
Foo foo;
};
MyClass::MyClass()
: d(new Private)
{
d->foo.doSomething();
}
MyClass::~MyClass()
{
delete d;
}
Further tasks
Converting non-trivial classes to use d-pointer may also require:
- any code in the class' .cpp file referring to m_foo attribute should be changed to d->foo
- if there were public or protected member variables, move them to the d-pointer class and add accessors and setters for them as in the example below. Read about guildelines for accessors and setters on Techbase.
// MyClass.h
class MyClass {
public:
MyClass();
bool isBlack;
};
After converting to d-pointer it should be:
// MyClass.h
class MyClass {
public:
MyClass();
bool isBlack() const; // notice the const
void setBlack(bool black);
private:
class Private;
Private * const d;
};
// MyClass.cpp
class MyClass::Private {
public:
Private()
bool isBlack;
};
MyClass::MyClass()
: d(new Private)
{
d->foo.doSomething();
}
MyClass::~MyClass()
{
delete d;
}
bool isBlack() const
{
return d->isBlack;
}
void setBlack(bool black)
{
d->isBlack = black;
}
- The class typically should be "non-copyable" and thus add Q_DISABLE_COPY(...) line in private section of the class as presented below to avoid copying what would conflict with the d-pointer. This macro disables copy constructor and assignment operator. See the Qt docs for more information.
class MyClass
{
// ...
private:
Q_DISABLE_COPY(MyClass)
// ...
};
- Alter any code outside of the class that uses the class' API so that the code compiles and runs in exactly the same way as before.
- If there is inline code in header file that uses member variable, move the variable to d-pointer class if you know for sure the inline code isn't there for optimization. If unsure, ask the mentor or the task maintainer.
- After the work is done, the code should be compiled and possibly the program should be executed to check if there are no regressions.
List of files
This list is not complete. If you're looking for more please contact the maintainer. Please prepend assigned items with with [assigned] tag and done items with [done] tag.
- kexi/core/
- kexiinternalpart.*
- kexipartmanager.*
- kexiprojectconnectiondata.*
- kexistartupdata.*
- kexitextmsghandler.*
- KexiView.*
- kexi/kexiutils/
- FlowLayout.* (note: move all inline code to .cpp)
- longlongvalidator.*
- SmallToolButton.* (KexiToolBarSeparator)
- styleproxy.*
- kexi/formeditor/
- connectiondialog.*
- container.*
- events.*
- FormWidget.*
- kexiformeventhandler.*
- libactionwidget.*
- objecttree.*
- resizehandle.*
- richtextdialog.*
- tabstopdialog.*
- widgetfactory.*
- WidgetTreeWidget.*
- widgetwithsubpropertiesinterface.*
- kexi/widget/
- kexicharencodingcombobox.*
- kexidbconnectionwidget.*
- kexidbdrivercombobox.*
- KexiProjectSelectorWidget.*
- kexiscrollview.*
TODO: ask the maintainer for more...
Required skills
Average C++ needed, at least beginner, Qt knowledge welcome.
Notes to mentor
- This task can be naturally splited to many students but please have consistency in mind
- Results are stored within a new branch kexi-dpointers-gci, should be created and maintained by mentor
- Single commit should be only related to single class
- The resulting patche(s) should be also uploaded to http://git.reviewboard.kde.org; there is no need to split patches per-class
- Mentor should synchronize students' work within the single branch
- Please always emphasize importance of coding style to students and check that - it's so easier to maintain the style from day one instead of fixing afterwards. Show Techbase articles for that.
- Take care of coding practices too (see Techbase articles)