Commit f26f458f authored by goro's avatar goro
Browse files

Merge branch '0.9.1-beta' of into 0.9.1-beta

parents 9042ff32 c4b22269
\contentpage{index.html}{Qt Creator}
\page coding-style.html
\title Qt Creator Coding Rules
\section1 Introduction
The aim of this section is to serve as a guide for the developers, to aid us
to build understandable and maintainable code, to create less confusion and
surprises when working on Qt Creator.
As usual: Rules are not set in stone. If there's a good reason to break one,
do it, preferably after making sure that there are others agreeing.
This document is incomplete.
In general, if you want to contribute to the main source, we expect at least
that you:
\list 1
\o The most important rule first: KISS (keep it simple ...): always
use a simple implementation in favor of a more complicated one.
This eases maintenance a lot.
\o Write good C++ code: Readable, well commented when necessary,
and taking advantage of the OO model. Follow the \l{Formatting} guidelines.
There are also certain \l{Code Constructs} that we try to follow.
\o Adapt the code to the structures already existing in Qt Creator, or in
the case that you have better ideas, discuss them with other developers
before writing the code.
\o Take advantage of Qt. Don't re-invent the wheel. Think about what parts
of your code are generic enough that they might be incorporated into
Qt proper.
\o Document interfaces. Right now we use qdoc, but changing to doxygen
is being considered.
\section1 Submitting Code
It is implicitly understood that all patches contributed to The Qt Creator
Project are made under under the Gnu General Public License, version 2 or later
If you have a problem with that, don't contribute code.
Also please don't just pop up out of the blue with a huge patch (or
small) that changes something substantial in Qt Creator. Always discuss your
ideas with the other developers on mailing list first.
When you create the patch, please use git or use "diff -up" since we find
that a lot easier to read than the other diff formats. Also please do not
send patches that implements or fixes several different things; several
patches is a much better option.
We also require you to provide a commit message entry with every patch,
this describes in detail what the patch is doing.
\section1 Code Constructs
We have several guidelines on code constructs, some of these exist to
make the code faster, others to make the code clearer. Yet others
exist to allow us to take advantage of the strong type checking
in C++.
\list 1
\o Declaration of variables should wait as long as possible. The rule
is: "Don't declare it until you need it." In C++ there are a lot of
user defined types, and these can very often be expensive to
initialize. This rule connects to the next rule too.
\o Make the scope of a variable as small as possible.
\o Prefer preincrement to postincrement whenever possible.
Preincrement has potential of being faster than postincrement. Just
think about the obvious implementations of pre/post-increment. This
rule applies to decrement too.
T++; // not used in Qt Creator
U--; // not used in Qt Creator
\o Try to minimize evaluation of the same code over and over. This is
aimed especially at loops.
Container::iterator end = large.end();
for (Container::iterator it = large.begin(); it != end; ++it) {
for (Container::iterator it = large.begin();
it != large.end(); ++it) {
\section1 Formatting
\section2 Declarations
Only one declaration on each line.
int a;
int b;
int a, b; // not used in Qt Creator
This is especially important when initialization is done at the same
QString a = "Joe";
QString b = "Foo";
QString a = "Joe", b = "Foo"; // not used in Qt Creator
[Note that 'QString a = "Joe"' is formally calling a copy constructor
on a temporary constructed from a string literal and therefore has the
potential of being more expensive then direct construction by
'QString a("joe")'. However the compiler is allowed to elide the copy
(even if it had side effects), and modern compilers typically do so.
Given these equal costs, Qt Creator code favours the '=' idiom as it is in
line with the traditional C-style initialization, _and_ cannot be
mistaken as function declaration, _and_ reduces the level of nested
parantheses in more initializations.]
\section2 Pointers and references
char *p = "flop";
char &c = *p;
char* p = "flop"; // not used in Qt Creator
char & c = *p; // not used in Qt Creator
This is simply in line with the official Qt guide lines.
Also note that we will have:
const char *p;
char const * p; // not used in Qt Creator
Using a plain 0 for Null pointer constants is always correct and least effort
to type. So:
void *p = 0;
void *p = NULL; // not used in Qt Creator
void *p = '\0'; // not used in Qt Creator
void *p = 42 - 7 * 6; // also not used in Qt Creator
Note: As an exception, imported third party code as well as code
interfacing the "native" APIs (src/support/os_*) can use NULL.
\section2 Operator names and parentheses
operator == (type) // not used in Qt Creator
The == is part of the function name, separating it makes the
declaration look like an expression.
\section2 Function names and parentheses
void mangle()
void mangle () // not used in Qt Creator
\section2 Naming rules
Simply follow the style of Qt proper. As examples:
\o Use descriptive but simple and short names. Do not abbreviate.
\o Class names are capitalized, and function names lowercased.
Enums are named like Classes, values are in lower-case.
\section2 Formatting
Adapt the formatting of your code to the one used in the
other parts of Qt Creator. In case there is different formatting for
the same construct, use the one used more often.
\section2 Declarations
- Use this order for the access sections of your class: public,
protected, private. The public section is interesting for every
user of the class. The private section is only of interest for the
implementors of the class (you). [Obviously not true since this is
for developers, and we do not want one developer only to be able to
read and understand the implementation of class internals. Lgb]
- Avoid declaring global objects in the declaration file of the class.
If the same variable is used for all objects, use a static member.
- Avoid global or static variables.
\section2 File headers
If you create a new file, the top of the file should include a
header comment equal to the one found in other source files of Qt Creator.
\section2 Documentation
The documentation is generated from source and header files.
You document for the other developers, not for yourself.
In the header you should document interfaces, i.e. what the function does,
not the implementation.
In the .cpp files you document the implementation if the implementation
in non-obvious.
......@@ -107,6 +107,8 @@ void TypeOfExpression::processEnvironment(QMap<QString, Document::Ptr> documents
Document::Ptr doc, Environment *env,
QSet<QString> *processed) const
if (! doc)
if (processed->contains(doc->fileName()))
......@@ -46,11 +46,12 @@
#include <QtGui/QHBoxLayout>
#include <QtGui/QLineEdit>
#include <QtGui/QToolButton>
#include <QtGui/QPushButton>
namespace Core {
namespace Utils {
#ifdef Q_OS_OSX
#ifdef Q_OS_MAC
/*static*/ const char * const PathChooser::browseButtonLabel = "Choose...";
/*static*/ const char * const PathChooser::browseButtonLabel = "Browse...";
......@@ -112,7 +113,11 @@ PathChooser::PathChooser(QWidget *parent) :
#ifdef Q_OS_MAC
QPushButton *browseButton = new QPushButton;
QToolButton *browseButton = new QToolButton;
connect(browseButton, SIGNAL(clicked()), this, SLOT(slotBrowse()));
......@@ -334,6 +334,10 @@ NavigationSubWidget::NavigationSubWidget(NavigationWidget *parentWidget)
m_navigationComboBox = new NavComboBox(this);
m_navigationWidget = 0;
#ifdef Q_OS_MAC
// this is to avoid ugly tool bar behavior
m_toolbar = new QToolBar(this);
m_toolbar->setContentsMargins(0, 0, 0, 0);
......@@ -744,7 +744,8 @@ void CPPEditor::unCommentSelection()
QString endText = endBlock.text();
int endPos = end - endBlock.position();
bool hasTrailingCharacters = !endText.mid(endPos).trimmed().isEmpty();
bool hasTrailingCharacters = !endText.left(endPos).remove(QLatin1String("//")).trimmed().isEmpty()
&& !endText.mid(endPos).trimmed().isEmpty();
if ((endPos <= endText.length() - 2
&& == QLatin1Char('*')
&& == QLatin1Char('/'))) {
......@@ -58,7 +58,6 @@ SOURCES += attachexternaldialog.cpp \
gdbengine.cpp \
gdbmi.cpp \
gdboptionpage.cpp \
gdbtypemacros.cpp \
gdbengine.h \
moduleshandler.cpp \
moduleswindow.cpp \
......@@ -79,7 +78,6 @@ FORMS += attachexternaldialog.ui \
breakcondition.ui \
mode.ui \
gdboptionpage.ui \
gdbtypemacros.ui \
startexternaldialog.ui \
RESOURCES += debugger.qrc
......@@ -183,7 +183,6 @@ DebuggerPlugin::DebuggerPlugin()
m_pm = 0;
m_generalOptionPage = 0;
m_typeMacroPage = 0;
m_locationMark = 0;
m_manager = 0;
......@@ -202,7 +201,6 @@ void DebuggerPlugin::shutdown()
//qDebug() << "DebuggerPlugin::~DebuggerPlugin";
// FIXME: when using the line below, BreakWindow etc gets deleted twice.
// so better leak for now...
......@@ -212,9 +210,6 @@ void DebuggerPlugin::shutdown()
delete m_generalOptionPage;
m_generalOptionPage = 0;
delete m_typeMacroPage;
m_typeMacroPage = 0;
delete m_locationMark;
m_locationMark = 0;
......@@ -409,13 +404,10 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *error_mes
m_generalOptionPage = 0;
m_typeMacroPage = 0;
m_generalOptionPage = new GdbOptionPage(&theGdbSettings());
m_typeMacroPage = new TypeMacroPage(&theGdbSettings());
m_locationMark = 0;
......@@ -54,7 +54,6 @@ namespace Internal {
class DebuggerManager;
class DebugMode;
class GdbOptionPage;
class TypeMacroPage;
class LocationMark;
class DebuggerPlugin : public ExtensionSystem::IPlugin
......@@ -103,7 +102,6 @@ private:
ExtensionSystem::PluginManager *m_pm;
GdbOptionPage *m_generalOptionPage;
TypeMacroPage *m_typeMacroPage;
QString m_previousMode;
LocationMark *m_locationMark;
......@@ -80,7 +80,7 @@ enum DataDumperState
// FIXME: Move to extra file?
class GdbSettings
......@@ -58,7 +58,11 @@ GdbOptionPage::GdbOptionPage(GdbSettings *settings)
#if defined(Q_OS_WIN32)
QString defaultScript = coreIFace->resourcePath() +
m_settings->m_gdbCmd = s->value("Location", defaultCommand).toString();
m_settings->m_scriptFile= s->value("ScriptFile", defaultScript).toString();
m_settings->m_gdbEnv = s->value("Environment", "").toString();
m_settings->m_autoRun = s->value("AutoRun", true).toBool();
m_settings->m_autoQuit = s->value("AutoQuit", true).toBool();
......@@ -72,36 +76,50 @@ QString GdbOptionPage::name() const
QString GdbOptionPage::category() const
return "Debugger|Gdb";
return "Debugger";
QString GdbOptionPage::trCategory() const
return tr("Debugger|Gdb");
return tr("Debugger");
QWidget *GdbOptionPage::createPage(QWidget *parent)
QWidget *w = new QWidget(parent);
m_ui.gdbLocationChooser->setPromptDialogTitle(tr("Choose Gdb Location"));
m_ui.scriptFileChooser->setPromptDialogTitle(tr("Choose Location of Startup Script File"));
connect(m_ui.pushButtonBrowse, SIGNAL(clicked()),
this, SLOT(browse()));
connect(m_ui.gdbLocationChooser, SIGNAL(changed()),
this, SLOT(onGdbLocationChanged()));
connect(m_ui.scriptFileChooser, SIGNAL(changed()),
this, SLOT(onScriptFileChanged()));
return w;
void GdbOptionPage::browse()
void GdbOptionPage::onGdbLocationChanged()
QString fileName = QFileDialog::getOpenFileName(m_ui.pushButtonBrowse,
"Browse for gdb executable");
if (fileName.isEmpty())
m_settings->m_gdbCmd = fileName;
m_settings->m_gdbCmd = m_ui.gdbLocationChooser->path();
void GdbOptionPage::onScriptFileChanged()
m_settings->m_scriptFile = m_ui.scriptFileChooser->path();
void GdbOptionPage::finished(bool accepted)
......@@ -109,10 +127,11 @@ void GdbOptionPage::finished(bool accepted)
if (!accepted)
m_settings->m_gdbCmd = m_ui.gdbEdit->text();
m_settings->m_gdbEnv = m_ui.envEdit->text();
m_settings->m_gdbCmd = m_ui.gdbLocationChooser->path();
m_settings->m_gdbEnv = m_ui.environmentEdit->text();
m_settings->m_autoRun = m_ui.autoStartBox->isChecked();
m_settings->m_autoQuit = m_ui.autoQuitBox->isChecked();
m_settings->m_scriptFile = m_ui.scriptFileChooser->path();
Core::ICore *coreIFace = m_pm->getObject<Core::ICore>();
if (!coreIFace || !coreIFace->settings())
......@@ -35,7 +35,6 @@
#include "ui_gdboptionpage.h"
#include "ui_gdbtypemacros.h"
#include <coreplugin/dialogs/ioptionspage.h>
......@@ -63,7 +62,8 @@ public:
void finished(bool accepted);
public slots:
void browse();
void onGdbLocationChanged();
void onScriptFileChanged();
ExtensionSystem::PluginManager *m_pm;
......@@ -72,6 +72,7 @@ private:
GdbSettings *m_settings;
#if 0
class TypeMacroPage : public Core::IOptionsPage
......@@ -99,6 +100,7 @@ private:
GdbSettings *m_settings;
QWidget *m_widget;
} // namespace Internal
} // namespace Debugger
......@@ -7,7 +7,7 @@
<property name="windowTitle">
......@@ -23,7 +23,7 @@
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Gdb Debug Options</string>
<layout class="QGridLayout">
<property name="margin">
......@@ -32,46 +32,45 @@
<property name="spacing">
<item row="0" column="1">
<widget class="QLineEdit" name="gdbEdit"/>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="envEdit"/>
<item row="1" column="1">
<widget class="QLineEdit" name="environmentEdit"/>
<item row="0" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="labelGdbLocaltion">
<property name="toolTip">
<string>This is either a full abolute path leading to the gdb binary you intend to use or the name of a gdb binary that wiull be searched in your PATH.</string>
<property name="text">
<string>Gdb Location:</string>
<property name="buddy">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="labelEnvironment">
<property name="text">
<property name="buddy">
<item row="0" column="2">
<widget class="QPushButton" name="pushButtonBrowse">
<property name="text">
<item row="2" column="0">
<widget class="QLabel" name="labelGdbStartupScript">
<property name="toolTip">
<string>This is either empty or points to a file containing gdb commands that will be executed immediately after gdb starts up.</string>
<property name="icon">
<iconset resource="../coreplugin/core.qrc">
<property name="checkable">
<property name="text">
<string>Gdb Startup Script:</string>
<item row="2" column="1">
<widget class="Core::Utils::PathChooser" name="scriptFileChooser" native="true"/>
<item row="0" column="1">
<widget class="Core::Utils::PathChooser" name="gdbLocationChooser" native="true"/>
......@@ -104,6 +103,14 @@
<header location="global">utils/pathchooser.h</header>
<include location="../coreplugin/core.qrc"/>
......@@ -20,24 +20,6 @@
<property name="margin">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Script File</string>
<layout class="QHBoxLayout">
<property name="spacing">
<property name="margin">