Commit 5ed76b96 authored by Daniel Molkentin's avatar Daniel Molkentin
Browse files

Merge branch 'master' of git://scm.dev.nokia.troll.no/creator/mainline into make_install/master

parents aec1e262 592560b5
......@@ -265,6 +265,7 @@ Whitespace
Always use only one blank line
Always use a single space after a keyword, and before a curly brace.
\code
// Wrong
if(foo){
}
......@@ -272,18 +273,24 @@ Whitespace
// Correct
if (foo) {
}
\endcode
For pointers or references, always use a single space before '*' or '&', but never after.
Avoid C-style casts when possible.
\code
// Wrong
char* blockOfMemory = (char* ) malloc(data.size());
// Correct
char *blockOfMemory = (char *)malloc(data.size());
char *blockOfMemory = reinterpret_cast<char *>(malloc(data.size()));
\endcode
Of course, in this particulare case, using \c new might be an even better
option.
Braces
As a base rule, the left curly brace goes on the same line as the start of the statement:
\code
// Wrong
if (codec)
{
......@@ -292,8 +299,10 @@ Braces
// Correct
if (codec) {
}
\endcode
Exception: Function implementations and class declarations always have the left brace on the start of a line:
\code
static void foo(int g)
{
qDebug("foo: %i", g);
......@@ -302,8 +311,10 @@ Braces
class Moo
{
};
\endcode
Use curly braces when the body of a conditional statement contains more than one line, and also if a single line statement is somewhat complex.
\code
// Wrong
if (address.isEmpty()) {
return false;
......@@ -319,15 +330,19 @@ Braces
for (int i = 0; i < 10; ++i)
qDebug("%i", i);
\endcode
Exception 1: Use braces also if the parent statement covers several lines / wraps
\code
// Correct
if (address.isEmpty() || !isValid()
|| !codec) {
return false;
}
\endcode
Exception 2: Use braces also in if-then-else blocks where either the if-code or the else-code covers several lines
\code
// Wrong
if (address.isEmpty())
--it;
......@@ -358,16 +373,20 @@ Braces
else
...
}
\endcode
Use curly braces when the body of a conditional statement is empty
\code
// Wrong
while (a);
// Correct
while (a) {}
\endcode
Parentheses
Use parentheses to group expressions:
\code
// Wrong
if (a && b || c)
......@@ -379,10 +398,12 @@ Parentheses
// Correct
(a + b) & c
\endcode
Line breaks
Keep lines shorter than 100 characters; insert line breaks if necessary.
Commas go at the end of a broken line; operators start at the beginning of the new line. The operator is at the end of the line to avoid having to scroll if your editor is too narrow.
\code
// Wrong
if (longExpression +
otherLongExpression +
......@@ -394,10 +415,7 @@ Line breaks
+ otherLongExpression
+ otherOtherLongExpression) {
}
\endcode
\section2 Declarations
......@@ -424,6 +442,32 @@ Line breaks
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 Include order
Always go from less general to more general. In a typical implementation
file that would look like
\code
#include "myownheader.h"
...
#include "other_headers_from_my_own_plugin.h"
...
#include <other_plugin/headers_from_other_plugin.h>
...
#include <QtCore/QSomeCoreClass>
...
#include <QtGui/QSomeGuiClass>
...
#include <some_system_C++_header>
...
#include <some_system_C_header>
\endcode
This order ensures that the headers are self-contained.
Using <...> instead of "..." for headers from other plugins helps
spotting plugin-external dependencies in the sources.
Using empty lines between blocks of "peer" headers are encouraged.
\section2 Documentation
The documentation is generated from source and header files.
......
......@@ -36,24 +36,42 @@
// this relies on contents copied from qobject_p.h
#define PRIVATE_OBJECT_ALLOWED 1
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QHash>
#include <QLinkedList>
#include <QLocale>
#include <QMap>
#include <QMetaObject>
#include <QMetaProperty>
#include <QModelIndex>
#include <QObject>
#include <QPointer>
#include <QString>
#include <QTextCodec>
#include <QVector>
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QHash>
#include <QtCore/QLinkedList>
#include <QtCore/QLocale>
#include <QtCore/QMap>
#include <QtCore/QMetaObject>
#include <QtCore/QMetaProperty>
#include <QtCore/QModelIndex>
#include <QtCore/QObject>
#include <QtCore/QPointer>
#include <QtCore/QString>
#include <QtCore/QTextCodec>
#include <QtCore/QVector>
int qtGhVersion = QT_VERSION;
#ifdef QT_GUI_LIB
# include <QtGui/QPixmap>
# include <QtGui/QImage>
#endif
#include <list>
#include <map>
#include <string>
#include <vector>
#include <ctype.h>
#include <stdio.h>
#ifdef Q_OS_WIN
# include <windows.h>
#endif
/*!
\class QDumper
......@@ -91,7 +109,7 @@
'P(d, name, value)' roughly expands to:
d << (name) << "=\"" << value << "\"";
d << (name) << "='" << value << "'";
Useful (i.e. understood by the IDE) names include:
......@@ -117,25 +135,6 @@
*/
int qtGhVersion = QT_VERSION;
#ifdef QT_GUI_LIB
# include <QPixmap>
# include <QImage>
#endif
#include <list>
#include <map>
#include <string>
#include <vector>
#include <ctype.h>
#include <stdio.h>
#ifdef Q_OS_WIN
# include <windows.h>
#endif
#undef NS
#ifdef QT_NAMESPACE
# define STRINGIFY0(s) #s
......@@ -216,7 +215,8 @@ QT_END_NAMESPACE
// this can be mangled typenames of nested templates, each char-by-char
// comma-separated integer list
static char qDumpInBuffer[10000];
static char qDumpBuffer[1000];
static char qDumpOutBuffer[100000];
static char qDumpSize[20];
namespace {
......@@ -385,7 +385,6 @@ struct QDumper
{
explicit QDumper();
~QDumper();
void flush();
void checkFill();
QDumper &operator<<(long c);
QDumper &operator<<(int i);
......@@ -407,8 +406,6 @@ struct QDumper
void beginHash(); // start of data hash output
void endHash(); // start of data hash output
void write(const void *buf, int len); // raw write to stdout
// the dumper arguments
int protocolVersion; // dumper protocol version
int token; // some token to show on success
......@@ -427,6 +424,7 @@ struct QDumper
// internal state
bool success; // are we finished?
bool full;
int pos;
int extraInt[4];
......@@ -436,34 +434,16 @@ struct QDumper
QDumper::QDumper()
{
success = false;
pos = 0;
full = false;
qDumpOutBuffer[0] = 'f'; // marks output as 'wrong'
pos = 1;
}
QDumper::~QDumper()
{
flush();
char buf[30];
int len = qsnprintf(buf, sizeof(buf) - 1, "%d^done\n", token);
write(buf, len);
}
void QDumper::write(const void *buf, int len)
{
::fwrite(buf, len, 1, stdout);
::fflush(stdout);
}
void QDumper::flush()
{
if (pos != 0) {
char buf[30];
int len = qsnprintf(buf, sizeof(buf) - 1, "%d#%d,", token, pos);
write(buf, len);
write(qDumpBuffer, pos);
write("\n", 1);
pos = 0;
}
qDumpOutBuffer[pos++] = '\0';
if (success)
qDumpOutBuffer[0] = (full ? '+' : 't');
}
void QDumper::setupTemplateParameters()
......@@ -489,49 +469,49 @@ void QDumper::setupTemplateParameters()
QDumper &QDumper::operator<<(unsigned long long c)
{
checkFill();
pos += sprintf(qDumpBuffer + pos, "%llu", c);
pos += sprintf(qDumpOutBuffer + pos, "%llu", c);
return *this;
}
QDumper &QDumper::operator<<(unsigned long c)
{
checkFill();
pos += sprintf(qDumpBuffer + pos, "%lu", c);
pos += sprintf(qDumpOutBuffer + pos, "%lu", c);
return *this;
}
QDumper &QDumper::operator<<(float d)
{
checkFill();
pos += sprintf(qDumpBuffer + pos, "%f", d);
pos += sprintf(qDumpOutBuffer + pos, "%f", d);
return *this;
}
QDumper &QDumper::operator<<(double d)
{
checkFill();
pos += sprintf(qDumpBuffer + pos, "%f", d);
pos += sprintf(qDumpOutBuffer + pos, "%f", d);
return *this;
}
QDumper &QDumper::operator<<(unsigned int i)
{
checkFill();
pos += sprintf(qDumpBuffer + pos, "%u", i);
pos += sprintf(qDumpOutBuffer + pos, "%u", i);
return *this;
}
QDumper &QDumper::operator<<(long c)
{
checkFill();
pos += sprintf(qDumpBuffer + pos, "%ld", c);
pos += sprintf(qDumpOutBuffer + pos, "%ld", c);
return *this;
}
QDumper &QDumper::operator<<(int i)
{
checkFill();
pos += sprintf(qDumpBuffer + pos, "%d", i);
pos += sprintf(qDumpOutBuffer + pos, "%d", i);
return *this;
}
......@@ -555,22 +535,23 @@ QDumper &QDumper::operator<<(const void *p)
void QDumper::checkFill()
{
if (pos >= int(sizeof(qDumpBuffer)) - 100)
flush();
if (pos >= int(sizeof(qDumpOutBuffer)) - 100)
full = true;
}
void QDumper::put(char c)
{
checkFill();
qDumpBuffer[pos++] = c;
if (!full)
qDumpOutBuffer[pos++] = c;
}
void QDumper::addCommaIfNeeded()
{
if (pos == 0)
return;
char c = qDumpBuffer[pos - 1];
if (c == '}' || c == '"' || c == ']')
char c = qDumpOutBuffer[pos - 1];
if (c == '}' || c == '\'' || c == ']')
put(',');
}
......@@ -632,7 +613,6 @@ QDumper &QDumper::operator<<(const QString &str)
void QDumper::disarm()
{
flush();
success = true;
}
......@@ -650,7 +630,7 @@ void QDumper::endHash()
void QDumper::putEllipsis()
{
addCommaIfNeeded();
*this << "{name=\"<incomplete>\",value=\"\",type=\"" << innertype << "\"}";
*this << "{name='<incomplete>',value='',type='" << innertype << "'}";
}
//
......@@ -662,7 +642,7 @@ void QDumper::putEllipsis()
#define P(dumper,name,value) \
do { \
dumper.addCommaIfNeeded(); \
dumper << (name) << "=\"" << value << "\""; \
dumper << (name) << "='" << value << "'"; \
} while (0)
// simple string property
......@@ -760,7 +740,7 @@ static void qDumpInnerValueHelper(QDumper &d, const char *type, const void *addr
return;
case 'B':
if (isEqual(type, "QByteArray")) {
d << key << "encoded=\"1\",";
d << key << "encoded='1',";
P(d, key, *(QByteArray*)addr);
}
return;
......@@ -789,7 +769,7 @@ static void qDumpInnerValueHelper(QDumper &d, const char *type, const void *addr
return;
case 'S':
if (isEqual(type, "QString")) {
d << key << "encoded=\"1\",";
d << key << "encoded='1',";
P(d, key, *(QString*)addr);
}
return;
......@@ -856,7 +836,7 @@ static void qDumpQByteArray(QDumper &d)
char buf[20];
for (int i = 0; i != ba.size(); ++i) {
unsigned char c = ba.at(i);
unsigned char u = isprint(c) && c != '"' ? c : '?';
unsigned char u = (isprint(c) && c != '\'' && c != '"') ? c : '?';
sprintf(buf, "%02x (%u '%c')", c, c, u);
d.beginHash();
P(d, "name", "[" << i << "]");
......@@ -2028,7 +2008,7 @@ static void qDumpQVariantHelper(const void *data, QString *value,
*numchild = 0;
break;
case QVariant::String:
*value = QLatin1Char('"') + v.toString() + QLatin1Char('"');
*value = QLatin1Char('\'') + v.toString() + QLatin1Char('\'');
*numchild = 0;
break;
case QVariant::StringList:
......@@ -2260,9 +2240,9 @@ static void qDumpStdString(QDumper &d)
qCheckAccess(str.c_str() + str.size() - 1);
}
d << ",value=\"";
d << ",value='";
d.putBase64Encoded(str.c_str(), str.size());
d << "\"";
d << "'";
P(d, "valueencoded", "1");
P(d, "type", "std::string");
P(d, "numchild", "0");
......@@ -2279,9 +2259,9 @@ static void qDumpStdWString(QDumper &d)
qCheckAccess(str.c_str() + str.size() - 1);
}
d << "value=\"";
d << "value='";
d.putBase64Encoded((const char *)str.c_str(), str.size() * sizeof(wchar_t));
d << "\"";
d << "'";
P(d, "valueencoded", (sizeof(wchar_t) == 2 ? "2" : "3"));
P(d, "type", "std::wstring");
P(d, "numchild", "0");
......@@ -2502,54 +2482,54 @@ void qDumpObjectData440(
// They are mentioned here nevertheless. For types that not listed
// here, dumpers won't be used.
d << "dumpers=["
"\""NS"QByteArray\","
"\""NS"QDateTime\","
"\""NS"QDir\","
"\""NS"QFile\","
"\""NS"QFileInfo\","
"\""NS"QHash\","
"\""NS"QHashNode\","
"\""NS"QImage\","
"\""NS"QLinkedList\","
"\""NS"QList\","
"\""NS"QLocale\","
"\""NS"QMap\","
"\""NS"QMapNode\","
"\""NS"QModelIndex\","
"'"NS"QByteArray',"
"'"NS"QDateTime',"
"'"NS"QDir',"
"'"NS"QFile',"
"'"NS"QFileInfo',"
"'"NS"QHash',"
"'"NS"QHashNode',"
"'"NS"QImage',"
"'"NS"QLinkedList',"
"'"NS"QList',"
"'"NS"QLocale',"
"'"NS"QMap',"
"'"NS"QMapNode',"
"'"NS"QModelIndex',"
#if QT_VERSION >= 0x040500
"\""NS"QMultiMap\","
"'"NS"QMultiMap',"
#endif
"\""NS"QObject\","
"\""NS"QObjectMethodList\"," // hack to get nested properties display
"\""NS"QObjectPropertyList\","
"'"NS"QObject',"
"'"NS"QObjectMethodList'," // hack to get nested properties display
"'"NS"QObjectPropertyList',"
#if PRIVATE_OBJECT_ALLOWED
"\""NS"QObjectSignal\","
"\""NS"QObjectSignalList\","
"\""NS"QObjectSlot\","
"\""NS"QObjectSlotList\","
"'"NS"QObjectSignal',"
"'"NS"QObjectSignalList',"
"'"NS"QObjectSlot',"
"'"NS"QObjectSlotList',"
#endif // PRIVATE_OBJECT_ALLOWED
// << "\""NS"QRegion\","
"\""NS"QSet\","
"\""NS"QString\","
"\""NS"QStringList\","
"\""NS"QTextCodec\","
"\""NS"QVariant\","
"\""NS"QVector\","
"\""NS"QWidget\","
"\"string\","
"\"wstring\","
"\"std::basic_string\","
"\"std::list\","
"\"std::map\","
"\"std::string\","
"\"std::vector\","
"\"std::wstring\","
// << "'"NS"QRegion',"
"'"NS"QSet',"
"'"NS"QString',"
"'"NS"QStringList',"
"'"NS"QTextCodec',"
"'"NS"QVariant',"
"'"NS"QVector',"
"'"NS"QWidget',"
"'string',"
"'wstring',"
"'std::basic_string',"
"'std::list',"
"'std::map',"
"'std::string',"
"'std::vector',"
"'std::wstring',"
"]";
d << ",qtversion=["
"\"" << ((QT_VERSION >> 16) & 255) << "\","
"\"" << ((QT_VERSION >> 8) & 255) << "\","
"\"" << ((QT_VERSION) & 255) << "\"]";
d << ",namespace=\""NS"\"";
"'" << ((QT_VERSION >> 16) & 255) << "',"
"'" << ((QT_VERSION >> 8) & 255) << "',"
"'" << ((QT_VERSION) & 255) << "']";
d << ",namespace='"NS"'";
d.disarm();
}
......
......@@ -234,12 +234,11 @@ public:
BinEditorInterface(BinEditor *parent)
: Core::IEditor(parent)
{
Core::ICore *core = Core::ICore::instance();
Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance();
m_editor = parent;
m_file = new BinEditorFile(parent);
m_context << core->uniqueIDManager()->
uniqueIdentifier(Core::Constants::K_DEFAULT_BINARY_EDITOR);
m_context << core->uniqueIDManager()->uniqueIdentifier(Constants::C_BINEDITOR);
m_context << uidm->uniqueIdentifier(Core::Constants::K_DEFAULT_BINARY_EDITOR);
m_context << uidm->uniqueIdentifier(Constants::C_BINEDITOR);
m_cursorPositionLabel = new Core::Utils::LineColumnLabel;
QHBoxLayout *l = new QHBoxLayout;
......@@ -276,10 +275,10 @@ public:
void setDisplayName(const QString &title) { m_displayName = title; emit changed(); }
bool duplicateSupported() const { return false; }
IEditor *duplicate(QWidget */*parent*/) { return 0; }
IEditor *duplicate(QWidget * /* parent */) { return 0; }
QByteArray saveState() const { return QByteArray();} // TODO
bool restoreState(const QByteArray &/*state*/) {return false;} // TODO
QByteArray saveState() const { return QByteArray(); } // TODO
bool restoreState(const QByteArray & /* state */) { return false; } // TODO
QToolBar *toolBar() { return m_toolBar; }
......@@ -320,8 +319,8 @@ QString BinEditorFactory::kind() const
Core::IFile *BinEditorFactory::open(const QString &fileName)
{