Commit b8378498 authored by mae's avatar mae
Browse files

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

parents c9445676 20c8899e
......@@ -2187,6 +2187,44 @@ static void qDumpQVector(QDumper &d)
d.disarm();
}
static void qDumpQWeakPointer(QDumper &d)
{
const int v = sizeof(void *);
const void *value = deref(addOffset(d.data, v));
if (isSimpleType(d.innertype))
qDumpInnerValueHelper(d, d.innertype, value);
else
P(d, "value", "");
P(d, "valuedisabled", "true");
P(d, "numchild", 1);
if (d.dumpChildren) {
d << ",children=[";
d.beginHash();
P(d, "name", "data");
qDumpInnerValue(d, d.innertype, value);
d.endHash();
d.beginHash();
const void *weak = addOffset(deref(d.data), v);
P(d, "name", "weakref");
P(d, "value", *static_cast<const int *>(weak));
P(d, "type", "int");
P(d, "addr", weak);
P(d, "numchild", "0");
d.endHash();
d.beginHash();
const void *strong = addOffset(weak, sizeof(int));
P(d, "name", "strongref");
P(d, "value", *static_cast<const int *>(strong));
P(d, "type", "int");
P(d, "addr", strong);
P(d, "numchild", "0");
d.endHash();
d << "]";
}
d.disarm();
}
static void qDumpStdList(QDumper &d)
{
const std::list<int> &list = *reinterpret_cast<const std::list<int> *>(d.data);
......@@ -2559,16 +2597,6 @@ static void handleProtocolVersion2and3(QDumper & d)
else if (isEqual(type, "QStringList"))
qDumpQStringList(d);
break;
case 'T':
if (isEqual(type, "QTextCodec"))
qDumpQTextCodec(d);
break;
case 'V':
if (isEqual(type, "QVariant"))
qDumpQVariant(d);
else if (isEqual(type, "QVector"))
qDumpQVector(d);
break;
case 's':
if (isEqual(type, "wstring"))
qDumpStdWString(d);
......@@ -2589,6 +2617,19 @@ static void handleProtocolVersion2and3(QDumper & d)
else if (isEqual(type, "std::wstring"))
qDumpStdWString(d);
break;
case 'T':
if (isEqual(type, "QTextCodec"))
qDumpQTextCodec(d);
break;
case 'V':
if (isEqual(type, "QVariant"))
qDumpQVariant(d);
else if (isEqual(type, "QVector"))
qDumpQVector(d);
break;
case 'W':
if (isEqual(type, "QWeakPointer"))
qDumpQWeakPointer(d);
}
if (!d.success)
......@@ -2664,6 +2705,7 @@ void *qDumpObjectData440(
"\""NS"QTextCodec\","
"\""NS"QVariant\","
"\""NS"QVector\","
"\""NS"QWeakPointer\","
"\""NS"QWidget\","
#ifdef Q_OS_WIN
"\"basic_string\","
......
......@@ -71,7 +71,7 @@ bool ConsoleProcess::start(const QString &program, const QStringList &args)
QString err = stubServerListen();
if (!err.isEmpty()) {
emit processError(tr("Cannot set up comm channel: %1").arg(err));
emit processError(tr("Cannot set up communication channel: %1").arg(err));
return false;
}
......@@ -79,7 +79,7 @@ bool ConsoleProcess::start(const QString &program, const QStringList &args)
m_tempFile = new QTemporaryFile();
if (!m_tempFile->open()) {
stubServerShutdown();
emit processError(tr("Cannot create temp file: %1").arg(m_tempFile->errorString()));
emit processError(tr("Cannot create temporary file: %1").arg(m_tempFile->errorString()));
delete m_tempFile;
m_tempFile = 0;
return false;
......@@ -109,7 +109,7 @@ bool ConsoleProcess::start(const QString &program, const QStringList &args)
m_process.start(xterm, xtermArgs);
if (!m_process.waitForStarted()) {
stubServerShutdown();
emit processError(tr("Cannot start terminal emulator %1.").arg(xterm));
emit processError(tr("Cannot start the terminal emulator '%1'.").arg(xterm));
delete m_tempFile;
m_tempFile = 0;
return false;
......@@ -145,7 +145,7 @@ QString ConsoleProcess::stubServerListen()
{
QTemporaryFile tf;
if (!tf.open())
return tr("Cannot create temporary file: %2").arg(tf.errorString());
return tr("Cannot create temporary file: %1").arg(tf.errorString());
stubFifoDir = QFile::encodeName(tf.fileName());
}
// By now the temp file was deleted again
......@@ -153,12 +153,12 @@ QString ConsoleProcess::stubServerListen()
if (!::mkdir(m_stubServerDir.constData(), 0700))
break;
if (errno != EEXIST)
return tr("Cannot create temporary directory %1: %2").arg(stubFifoDir, strerror(errno));
return tr("Cannot create temporary directory '%1': %2").arg(stubFifoDir, strerror(errno));
}
QString stubServer = stubFifoDir + "/stub-socket";
if (!m_stubServer.listen(stubServer)) {
::rmdir(m_stubServerDir.constData());
return tr("Cannot create socket %1: %2").arg(stubServer, m_stubServer.errorString());
return tr("Cannot create socket '%1': %2").arg(stubServer, m_stubServer.errorString());
}
return QString();
}
......@@ -190,10 +190,10 @@ void ConsoleProcess::readStubOutput()
QByteArray out = m_stubSocket->readLine();
out.chop(1); // \n
if (out.startsWith("err:chdir ")) {
emit processError(tr("Cannot change to working directory %1: %2")
emit processError(tr("Cannot change to working directory '%1': %2")
.arg(workingDirectory(), errorMsg(out.mid(10).toInt())));
} else if (out.startsWith("err:exec ")) {
emit processError(tr("Cannot execute %1: %2")
emit processError(tr("Cannot execute '%1': %2")
.arg(m_executable, errorMsg(out.mid(9).toInt())));
} else if (out.startsWith("pid ")) {
// Will not need it any more
......
......@@ -69,7 +69,7 @@ bool ConsoleProcess::start(const QString &program, const QStringList &args)
QString err = stubServerListen();
if (!err.isEmpty()) {
emit processError(tr("Cannot set up comm channel: %1").arg(err));
emit processError(tr("Cannot set up communication channel: %1").arg(err));
return false;
}
......@@ -77,7 +77,7 @@ bool ConsoleProcess::start(const QString &program, const QStringList &args)
m_tempFile = new QTemporaryFile();
if (!m_tempFile->open()) {
stubServerShutdown();
emit processError(tr("Cannot create temp file: %1").arg(m_tempFile->errorString()));
emit processError(tr("Cannot create temporary file: %1").arg(m_tempFile->errorString()));
delete m_tempFile;
m_tempFile = 0;
return false;
......@@ -180,10 +180,10 @@ void ConsoleProcess::readStubOutput()
QByteArray out = m_stubSocket->readLine();
out.chop(2); // \r\n
if (out.startsWith("err:chdir ")) {
emit processError(tr("Cannot change to working directory %1: %2")
emit processError(tr("Cannot change to working directory '%1': %2")
.arg(workingDirectory(), winErrorMessage(out.mid(10).toInt())));
} else if (out.startsWith("err:exec ")) {
emit processError(tr("Cannot execute %1: %2")
emit processError(tr("Cannot execute '%1': %2")
.arg(m_executable, winErrorMessage(out.mid(9).toInt())));
} else if (out.startsWith("pid ")) {
// Will not need it any more
......
......@@ -35,12 +35,36 @@
#include <QtCore/QFutureInterface>
#include <QtCore/QtConcurrentRun>
#include <QtCore/QRegExp>
#include <QtGui/QApplication>
#include <QtCore/QCoreApplication>
#include <qtconcurrent/runextensions.h>
using namespace Core::Utils;
static inline QString msgCanceled(const QString &searchTerm, int numMatches, int numFilesSearched)
{
return QCoreApplication::translate("Core::Utils::FileSearch",
"%1: canceled. %n occurrences found in %2 files.",
0, QCoreApplication::CodecForTr, numMatches).
arg(searchTerm).arg(numFilesSearched);
}
static inline QString msgFound(const QString &searchTerm, int numMatches, int numFilesSearched)
{
return QCoreApplication::translate("Core::Utils::FileSearch",
"%1: %n occurrences found in %2 files.",
0, QCoreApplication::CodecForTr, numMatches).
arg(searchTerm).arg(numFilesSearched);
}
static inline QString msgFound(const QString &searchTerm, int numMatches, int numFilesSearched, int filesSize)
{
return QCoreApplication::translate("Core::Utils::FileSearch",
"%1: %n occurrences found in %2 of %3 files.",
0, QCoreApplication::CodecForTr, numMatches).
arg(searchTerm).arg(numFilesSearched).arg(filesSize);
}
namespace {
void runFileSearch(QFutureInterface<FileSearchResult> &future,
......@@ -71,9 +95,7 @@ void runFileSearch(QFutureInterface<FileSearchResult> &future,
if (future.isPaused())
future.waitForResume();
if (future.isCanceled()) {
future.setProgressValueAndText(numFilesSearched,
QApplication::translate("FileSearch", "%1: canceled. %2 occurrences found in %3 files.").
arg(searchTerm).arg(numMatches).arg(numFilesSearched));
future.setProgressValueAndText(numFilesSearched, msgCanceled(searchTerm, numMatches, numFilesSearched));
break;
}
QFile file(s);
......@@ -146,14 +168,10 @@ void runFileSearch(QFutureInterface<FileSearchResult> &future,
firstChunk = false;
}
++numFilesSearched;
future.setProgressValueAndText(numFilesSearched,
QApplication::translate("FileSearch", "%1: %2 occurrences found in %3 of %4 files.").
arg(searchTerm).arg(numMatches).arg(numFilesSearched).arg(files.size()));
future.setProgressValueAndText(numFilesSearched, msgFound(searchTerm, numMatches, numFilesSearched, files.size()));
}
if (!future.isCanceled())
future.setProgressValueAndText(numFilesSearched,
QApplication::translate("FileSearch", "%1: %2 occurrences found in %3 files.").
arg(searchTerm).arg(numMatches).arg(numFilesSearched));
future.setProgressValueAndText(numFilesSearched, msgFound(searchTerm, numMatches, numFilesSearched));
}
void runFileSearchRegExp(QFutureInterface<FileSearchResult> &future,
......@@ -165,17 +183,15 @@ void runFileSearchRegExp(QFutureInterface<FileSearchResult> &future,
int numFilesSearched = 0;
int numMatches = 0;
if (flags & QTextDocument::FindWholeWords)
searchTerm = QString("\\b%1\\b").arg(searchTerm);
Qt::CaseSensitivity caseSensitivity = (flags & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive;
QRegExp expression(searchTerm, caseSensitivity);
searchTerm = QString::fromLatin1("\\b%1\\b").arg(searchTerm);
const Qt::CaseSensitivity caseSensitivity = (flags & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive;
const QRegExp expression(searchTerm, caseSensitivity);
foreach (QString s, files) {
foreach (const QString &s, files) {
if (future.isPaused())
future.waitForResume();
if (future.isCanceled()) {
future.setProgressValueAndText(numFilesSearched,
QApplication::translate("FileSearch", "%1: canceled. %2 occurrences found in %3 files.").
arg(searchTerm).arg(numMatches).arg(numFilesSearched));
future.setProgressValueAndText(numFilesSearched, msgCanceled(searchTerm, numMatches, numFilesSearched));
break;
}
QFile file(s);
......@@ -195,14 +211,10 @@ void runFileSearchRegExp(QFutureInterface<FileSearchResult> &future,
++lineNr;
}
++numFilesSearched;
future.setProgressValueAndText(numFilesSearched,
QApplication::translate("FileSearch", "%1: %2 occurrences found in %3 of %4 files.").
arg(searchTerm).arg(numMatches).arg(numFilesSearched).arg(files.size()));
future.setProgressValueAndText(numFilesSearched, msgFound(searchTerm, numMatches, numFilesSearched, files.size()));
}
if (!future.isCanceled())
future.setProgressValueAndText(numFilesSearched,
QApplication::translate("FileSearch", "%1: %2 occurrences found in %3 files.").
arg(searchTerm).arg(numMatches).arg(numFilesSearched));
future.setProgressValueAndText(numFilesSearched, msgFound(searchTerm, numMatches, numFilesSearched));
}
} // namespace
......
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the $MODULE$ of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qstringbuilder.h"
/*!
\class QLatin1Literal
\reentrant
\brief The QLatin1Literal class provides a thin wrapper of string literal
used in source codes.
The main use of \c QLatin1Literal is in conjunction with \c QStringBuilder
to reduce the number of reallocations needed to build up a string from
smaller chunks.
Contrary to \c QLatin1String, a \c QLatin1Literal can retrieve its size
int \i{O(1)}.
\ingroup tools
\ingroup shared
\ingroup text
\mainclass
\sa QStringBuilder, QLatin1String, QString
*/
/*! \fn QLatin1Literal::QLatin1Literal(const char(&literal)[])
The only constructor of the class.
*/
/*! \fn int QLatin1Literal::size() const
Returns the number of characters in the literal \i{not} including
the trailing NUL char.
*/
/*! \fn char *QLatin1Literal::size() const
Returns a pointer to the first character of the string literal.
The string literal is terminated by a NUL character.
*/
/*! \fn QLatin1Literal::operator QString() const
Converts the \c QLatin1Literal into a \c QString object.
*/
/*!
\class QStringBuilderPair
\reentrant
\brief QStringBuilderPair is a helper class template for building
QStringBuilder objects wrapping two smaller QStringBuilder object.
*/
/*!
\class QStringBuilder
\reentrant
\brief QStringBuilder is a template class providing a facility to build
up QStrings from smaller chunks.
\ingroup tools
\ingroup shared
\ingroup text
\mainclass
When creating strings from smaller chunks, typically \c QString::operator+()
is used, resulting \i{n - 1} reallocations when operating on \i{n} chunks.
QStringBuilder uses expression
templates to collect the individual parts, compute the total size,
allocate memory for the resulting QString object, and copy the contents
of the chunks into the result.
Using \c QStringBuilder::operator%() yield generally better performance then
using \c QString::operator+() on the same chunks if there are three or
more of them, and equal performance otherwise.
\sa QLatin1Literal, QString
*/
/* !fn template <class A, class B> QStringBuilder< QStringBuilderPair<A, B> > operator%(const A &a, const B &b)
Creates a helper object containing both parameters.
This is the main function to build up
*/
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the $MODULE$ of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QSTRINGBUILDER_H
#define QSTRINGBUILDER_H
#include <QtCore/qstring.h>
#include <string.h>
class QLatin1Literal
{
public:
template <int N>
QLatin1Literal(const char (&str)[N]) : m_size(N - 1), m_data(str) {}
int size() const { return m_size; }
const char *data() const { return m_data; }
void append(QChar *&out) const
{
const char *s = m_data;
for (int i = m_size; --i >= 0;)
*out++ = *s++;
}
operator QString() const
{
QString s;
s.resize(m_size);
QChar *d = s.data();
append(d);
return s;
}
private:
const int m_size;
const char *m_data;
};
template <class A>
class QStringBuilder : public A
{
public:
QStringBuilder(A a_) : A(a_) {}
operator QString() const
{
QString s;
s.resize(this->size());
QChar *d = s.data();
this->append(d);
return s;
}
};
template <>
class QStringBuilder<QString>
{
public:
QStringBuilder(const QString &a_) : a(&a_) {}
inline int size() const { return a->size(); }
inline void append(QChar *&out) const
{
const int n = a->size();
memcpy(out, (char*)a->constData(), sizeof(QChar) * n);
out += n;
}
inline operator QString() const { return *a; }
private:
const QString *a;
};
template <>
class QStringBuilder<char>
{
public:
QStringBuilder(char c_) : c(c_) {}
inline int size() const { return 1; }
inline void append(QChar *&out) const { *out++ = QLatin1Char(c); }
private:
const char c;
};
template <class A, class B>
class QStringBuilderPair
{
public:
QStringBuilderPair(A a_, B b_) : a(a_), b(b_) {}
inline int size() const { return a.size() + b.size(); }
inline void append(QChar *&out) const { a.append(out); b.append(out); }
private:
A a;
B b;
};
template <class A, class B>
QStringBuilder< QStringBuilderPair<A, B> >
operator%(const A &a, const B &b)
{
return QStringBuilderPair<A, B> (a, b);
}
// QString related specializations
template <class A>
inline QStringBuilder< QStringBuilderPair<A, QStringBuilder<QString> > >
operator%(const A &a, const QString &b)
{
return QStringBuilderPair<A, QStringBuilder<QString> > (a, b);
}
template <class B>
inline QStringBuilder< QStringBuilderPair<QStringBuilder<QString>, B> >
operator%(const QString &a, const B &b)
{
return QStringBuilderPair<QStringBuilder<QString>, B> (a, b);
}
inline QStringBuilder<
QStringBuilderPair<QStringBuilder<QString>, QStringBuilder<QString> >
>
operator%(const QString &a, const QString &b)
{
return QStringBuilderPair< QStringBuilder<QString>,
QStringBuilder<QString> > (a, b);
}
// char related specializations
template <class A>
inline QStringBuilder< QStringBuilderPair<A, QStringBuilder<char> > >
operator%(const A &a, char b)
{
return QStringBuilderPair<A, QStringBuilder<char> > (a, b);
}