Merge branch 'origin/2.0' (early part)

This commit is contained in:
Erik Verbruggen
2010-06-15 11:30:51 +02:00
21 changed files with 411 additions and 389 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -39,7 +39,7 @@ using namespace CPlusPlus;
enum { MAX_NUM_LINES = 20 }; enum { MAX_NUM_LINES = 20 };
static bool shouldOverrideChar(const QChar &ch) static bool shouldOverrideChar(QChar ch)
{ {
switch (ch.unicode()) { switch (ch.unicode()) {
case ')': case ']': case ';': case '"': case '\'': case ')': case ']': case ';': case '"': case '\'':
@@ -86,7 +86,7 @@ bool MatchingText::shouldInsertMatchingText(const QTextCursor &tc)
return shouldInsertMatchingText(doc->characterAt(tc.selectionEnd())); return shouldInsertMatchingText(doc->characterAt(tc.selectionEnd()));
} }
bool MatchingText::shouldInsertMatchingText(const QChar &lookAhead) bool MatchingText::shouldInsertMatchingText(QChar lookAhead)
{ {
switch (lookAhead.unicode()) { switch (lookAhead.unicode()) {
case '{': case '}': case '{': case '}':
@@ -103,7 +103,7 @@ bool MatchingText::shouldInsertMatchingText(const QChar &lookAhead)
} }
QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QString &textToProcess, QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QString &textToProcess,
const QChar &la, int *skippedChars) const QChar la, int *skippedChars) const
{ {
QTextCursor tc = cursor; QTextCursor tc = cursor;
QTextDocument *doc = tc.document(); QTextDocument *doc = tc.document();

View File

@@ -43,10 +43,10 @@ public:
MatchingText(TokenCache *tokenCache); MatchingText(TokenCache *tokenCache);
static bool shouldInsertMatchingText(const QTextCursor &tc); static bool shouldInsertMatchingText(const QTextCursor &tc);
static bool shouldInsertMatchingText(const QChar &lookAhead); static bool shouldInsertMatchingText(QChar lookAhead);
QString insertMatchingBrace(const QTextCursor &tc, const QString &text, QString insertMatchingBrace(const QTextCursor &tc, const QString &text,
const QChar &la, int *skippedChars) const; QChar la, int *skippedChars) const;
QString insertParagraphSeparator(const QTextCursor &tc) const; QString insertParagraphSeparator(const QTextCursor &tc) const;
private: private:

View File

@@ -1380,7 +1380,7 @@ SemanticInfo CPPEditor::semanticInfo() const
return m_lastSemanticInfo; return m_lastSemanticInfo;
} }
bool CPPEditor::isElectricCharacter(const QChar &ch) const bool CPPEditor::isElectricCharacter(QChar ch) const
{ {
if (ch == QLatin1Char('{') || if (ch == QLatin1Char('{') ||
ch == QLatin1Char('}') || ch == QLatin1Char('}') ||
@@ -1392,7 +1392,7 @@ bool CPPEditor::isElectricCharacter(const QChar &ch) const
} }
QString CPPEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text, QString CPPEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text,
const QChar &la, int *skippedChars) const QChar la, int *skippedChars) const
{ {
MatchingText m(tokenCache()); MatchingText m(tokenCache());
return m.insertMatchingBrace(tc, text, la, skippedChars); return m.insertMatchingBrace(tc, text, la, skippedChars);

View File

@@ -222,10 +222,10 @@ protected:
TextEditor::BaseTextEditorEditable *createEditableInterface(); TextEditor::BaseTextEditorEditable *createEditableInterface();
// These override BaseTextEditor // These override BaseTextEditor
virtual bool isElectricCharacter(const QChar &ch) const; virtual bool isElectricCharacter(QChar ch) const;
virtual QString insertMatchingBrace(const QTextCursor &tc, const QString &text, virtual QString insertMatchingBrace(const QTextCursor &tc, const QString &text,
const QChar &la, int *skippedChars) const; QChar la, int *skippedChars) const;
virtual QString insertParagraphSeparator(const QTextCursor &tc) const; virtual QString insertParagraphSeparator(const QTextCursor &tc) const;

View File

@@ -120,7 +120,7 @@ void FilterSettingsPage::updateFilterPage()
foreach (const QString &attribute, attributes) foreach (const QString &attribute, attributes)
new QTreeWidgetItem(m_ui.attributeWidget, QStringList(attribute)); new QTreeWidgetItem(m_ui.attributeWidget, QStringList(attribute));
if (m_filterMap.keys().isEmpty()) { if (!m_filterMap.keys().isEmpty()) {
m_ui.filterWidget->setCurrentRow(0); m_ui.filterWidget->setCurrentRow(0);
updateAttributes(m_ui.filterWidget->currentItem()); updateAttributes(m_ui.filterWidget->currentItem());
} }

View File

@@ -819,16 +819,8 @@ void HelpPlugin::handleHelpRequest(const QUrl &url)
if (HelpViewer::launchWithExternalApp(url)) if (HelpViewer::launchWithExternalApp(url))
return; return;
if (Core::HelpManager::instance()->findFile(url).isValid()) {
if (url.queryItemValue(QLatin1String("view")) == QLatin1String("split")) {
if (HelpViewer* viewer = viewerForContextMode())
viewer->setSource(url);
} else {
activateHelpMode();
m_centralWidget->setSource(url);
}
} else {
QString address = url.toString(); QString address = url.toString();
if (!Core::HelpManager::instance()->findFile(url).isValid()) {
if (address.startsWith(HelpViewer::NsNokia) if (address.startsWith(HelpViewer::NsNokia)
|| address.startsWith(HelpViewer::NsTrolltech)) { || address.startsWith(HelpViewer::NsTrolltech)) {
// local help not installed, resort to external web help // local help not installed, resort to external web help
@@ -840,7 +832,15 @@ void HelpPlugin::handleHelpRequest(const QUrl &url)
} }
address = urlPrefix + address.mid(address.lastIndexOf(QLatin1Char('/'))); address = urlPrefix + address.mid(address.lastIndexOf(QLatin1Char('/')));
} }
QDesktopServices::openUrl(address); }
const QUrl newUrl(address);
if (newUrl.queryItemValue(QLatin1String("view")) == QLatin1String("split")) {
if (HelpViewer* viewer = viewerForContextMode())
viewer->setSource(newUrl);
} else {
activateHelpMode();
m_centralWidget->setSource(newUrl);
} }
} }

View File

@@ -147,8 +147,6 @@ bool HelpViewer::launchWithExternalApp(const QUrl &url)
actualTmpFile.close(); actualTmpFile.close();
return QDesktopServices::openUrl(QUrl(actualTmpFile.fileName())); return QDesktopServices::openUrl(QUrl(actualTmpFile.fileName()));
} }
} else if (url.scheme() == QLatin1String("http")) {
return QDesktopServices::openUrl(url);
} }
return false; return false;
} }

View File

@@ -41,7 +41,7 @@
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtHelp/QHelpEngineCore> #include <QtHelp/QHelpEngine>
using namespace Find; using namespace Find;
using namespace Help; using namespace Help;
@@ -78,7 +78,7 @@ HelpViewer::~HelpViewer()
QFont HelpViewer::viewerFont() const QFont HelpViewer::viewerFont() const
{ {
const QHelpEngineCore &engine = HelpManager::helpEngineCore(); const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
return qVariantValue<QFont>(engine.customValue(QLatin1String("font"), return qVariantValue<QFont>(engine.customValue(QLatin1String("font"),
qApp->font())); qApp->font()));
} }
@@ -149,8 +149,15 @@ void HelpViewer::setSource(const QUrl &url)
if (launchWithExternalApp(url)) if (launchWithExternalApp(url))
return; return;
const QHelpEngineCore &engine = HelpManager::instance().helpEngineCore(); QUrl resolvedUrl;
const QUrl &resolvedUrl = engine.findFile(url); if (url.scheme() == QLatin1String("http"))
resolvedUrl = url;
if (!resolvedUrl.isValid()) {
const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
resolvedUrl = engine.findFile(url);
}
if (resolvedUrl.isValid()) { if (resolvedUrl.isValid()) {
QTextBrowser::setSource(resolvedUrl); QTextBrowser::setSource(resolvedUrl);
emit loadFinished(true); emit loadFinished(true);
@@ -345,7 +352,7 @@ QVariant HelpViewer::loadResource(int type, const QUrl &name)
{ {
QByteArray ba; QByteArray ba;
if (type < 4) { if (type < 4) {
const QHelpEngineCore &engine = HelpManager::instance().helpEngineCore(); const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
ba = engine.fileData(name); ba = engine.fileData(name);
if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) { if (name.toString().endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)) {
QImage image; QImage image;

View File

@@ -121,9 +121,14 @@ HelpNetworkAccessManager::HelpNetworkAccessManager(QObject *parent)
{ {
} }
QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, QNetworkReply *HelpNetworkAccessManager::createRequest(Operation op,
const QNetworkRequest &request, QIODevice* /*outgoingData*/) const QNetworkRequest &request, QIODevice* outgoingData)
{ {
if (!HelpViewer::isLocalUrl(request.url())
&& request.url().scheme() == QLatin1String("http")) {
return QNetworkAccessManager::createRequest(op, request, outgoingData);
}
QString url = request.url().toString(); QString url = request.url().toString();
const QHelpEngineCore &engine = LocalHelpManager::helpEngine(); const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
// TODO: For some reason the url to load is already wrong (passed from webkit) // TODO: For some reason the url to load is already wrong (passed from webkit)

View File

@@ -36,8 +36,25 @@ InvalidIdException::InvalidIdException(int line,
const QString &function, const QString &function,
const QString &file, const QString &file,
const QString &id, const QString &id,
bool duplicate) : Reason reason) :
InvalidArgumentException(line, function, file, "id"), m_id(id), m_duplicate(duplicate) InvalidArgumentException(line, function, file, "id"),
m_id(id)
{
if (reason == InvalidCharacters) {
m_description = QCoreApplication::translate("InvalidIdException", "Only alphanumeric characters and underscore allowed.\nIds must begin with a lowercase letter.");
} else {
m_description = QCoreApplication::translate("InvalidIdException", "Ids have to be unique.");
}
}
InvalidIdException::InvalidIdException(int line,
const QString &function,
const QString &file,
const QString &id,
const QString &description) :
InvalidArgumentException(line, function, file, "id"),
m_id(id),
m_description(description)
{ {
} }
@@ -48,22 +65,7 @@ QString InvalidIdException::type() const
QString InvalidIdException::description() const QString InvalidIdException::description() const
{ {
if (m_duplicate) return QCoreApplication::translate("InvalidIdException", "Invalid Id: %1\n%2").arg(m_id, m_description);
return duplicateErrorMessage(m_id);
return invalidErrorMessage(m_id);
}
QString InvalidIdException::duplicateErrorMessage(const QString &id)
{
return QCoreApplication::translate("InvalidIdException", "Ids have to be unique: ") + id;
}
QString InvalidIdException::invalidErrorMessage(const QString &id)
{
return QCoreApplication::translate("InvalidIdException", "Invalid Id: ") +
id + QCoreApplication::translate("InvalidIdException",
"\nOnly alphanumeric characters and underscore allowed.\nIds must begin with a lowercase letter.");
} }
} }

View File

@@ -37,22 +37,26 @@ namespace QmlDesigner {
class CORESHARED_EXPORT InvalidIdException : public InvalidArgumentException class CORESHARED_EXPORT InvalidIdException : public InvalidArgumentException
{ {
public: public:
enum Reason { InvalidCharacters, DuplicateId };
InvalidIdException(int line, InvalidIdException(int line,
const QString &function, const QString &function,
const QString &file, const QString &file,
const QString &id, const QString &id,
bool duplicate = false); Reason reason);
InvalidIdException(int line,
const QString &function,
const QString &file,
const QString &id,
const QString &description);
QString type() const; QString type() const;
QString description() const; QString description() const;
static QString duplicateErrorMessage(const QString &id);
static QString invalidErrorMessage(const QString &id);
private: private:
QString m_id; QString m_id;
bool m_duplicate; QString m_description;
}; };
} }

View File

@@ -65,6 +65,7 @@
#include "rewritertransaction.h" #include "rewritertransaction.h"
#include "rewriterview.h" #include "rewriterview.h"
#include "rewritingexception.h" #include "rewritingexception.h"
#include "invalididexception.h"
/*! /*!
\defgroup CoreModel \defgroup CoreModel
@@ -259,7 +260,12 @@ void ModelPrivate::changeNodeId(const InternalNode::Pointer& internalNodePointer
m_idNodeHash.remove(oldId); m_idNodeHash.remove(oldId);
if (!id.isEmpty()) if (!id.isEmpty())
m_idNodeHash.insert(id, internalNodePointer); m_idNodeHash.insert(id, internalNodePointer);
try {
notifyNodeIdChanged(internalNodePointer, id, oldId); notifyNodeIdChanged(internalNodePointer, id, oldId);
} catch (RewritingException &e) {
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id, e.description());
}
} }
void ModelPrivate::checkPropertyName(const QString &propertyName) void ModelPrivate::checkPropertyName(const QString &propertyName)

View File

@@ -180,13 +180,13 @@ void ModelNode::setId(const QString& id)
} }
if (!isValidId(id)) if (!isValidId(id))
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id); throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id, InvalidIdException::InvalidCharacters);
if (id == ModelNode::id()) if (id == ModelNode::id())
return; return;
if (view()->hasId(id)) if (view()->hasId(id))
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id, true); throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id, InvalidIdException::DuplicateId);
m_model.data()->m_d->changeNodeId(internalNode(), id); m_model.data()->m_d->changeNodeId(internalNode(), id);
} }

View File

@@ -577,7 +577,7 @@ bool CodeCompletion::maybeTriggersCompletion(TextEditor::ITextEditable *editor)
return false; return false;
} }
bool CodeCompletion::isDelimiter(const QChar &ch) const bool CodeCompletion::isDelimiter(QChar ch) const
{ {
switch (ch.unicode()) { switch (ch.unicode()) {
case '{': case '{':

View File

@@ -78,7 +78,7 @@ private:
void updateSnippets(); void updateSnippets();
bool maybeTriggersCompletion(TextEditor::ITextEditable *editor); bool maybeTriggersCompletion(TextEditor::ITextEditable *editor);
bool isDelimiter(const QChar &ch) const; bool isDelimiter(QChar ch) const;
void addCompletions(const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions, void addCompletions(const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
const QIcon &icon, int relevance); const QIcon &icon, int relevance);

View File

@@ -82,9 +82,7 @@ using namespace QmlJS;
using namespace QmlJS::AST; using namespace QmlJS::AST;
using namespace QmlJSEditor::Internal; using namespace QmlJSEditor::Internal;
namespace { static int blockBraceDepth(const QTextBlock &block)
int blockBraceDepth(const QTextBlock &block)
{ {
int state = block.userState(); int state = block.userState();
if (state == -1) if (state == -1)
@@ -93,7 +91,7 @@ int blockBraceDepth(const QTextBlock &block)
return (state >> 8) & 0xFF; return (state >> 8) & 0xFF;
} }
int blockStartState(const QTextBlock &block) static int blockStartState(const QTextBlock &block)
{ {
int state = block.userState(); int state = block.userState();
@@ -103,7 +101,7 @@ int blockStartState(const QTextBlock &block)
return state & 0xff; return state & 0xff;
} }
bool shouldInsertMatchingText(const QChar &lookAhead) static bool shouldInsertMatchingText(QChar lookAhead)
{ {
switch (lookAhead.unicode()) { switch (lookAhead.unicode()) {
case '{': case '}': case '{': case '}':
@@ -120,12 +118,14 @@ bool shouldInsertMatchingText(const QChar &lookAhead)
} // switch } // switch
} }
bool shouldInsertMatchingText(const QTextCursor &tc) static bool shouldInsertMatchingText(const QTextCursor &tc)
{ {
QTextDocument *doc = tc.document(); QTextDocument *doc = tc.document();
return shouldInsertMatchingText(doc->characterAt(tc.selectionEnd())); return shouldInsertMatchingText(doc->characterAt(tc.selectionEnd()));
} }
namespace {
class FindIdDeclarations: protected Visitor class FindIdDeclarations: protected Visitor
{ {
public: public:
@@ -945,7 +945,7 @@ QString QmlJSTextEditor::wordUnderCursor() const
return word; return word;
} }
bool QmlJSTextEditor::isElectricCharacter(const QChar &ch) const bool QmlJSTextEditor::isElectricCharacter(QChar ch) const
{ {
if (ch == QLatin1Char('}') if (ch == QLatin1Char('}')
|| ch == QLatin1Char(']') || ch == QLatin1Char(']')
@@ -1184,7 +1184,7 @@ bool QmlJSTextEditor::isInComment(const QTextCursor &) const
return false; return false;
} }
QString QmlJSTextEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text, const QChar &, int *skippedChars) const QString QmlJSTextEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text, QChar, int *skippedChars) const
{ {
if (text.length() != 1) if (text.length() != 1)
return QString(); return QString();

View File

@@ -249,11 +249,11 @@ protected:
//// brace matching //// brace matching
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const; virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const;
virtual bool isInComment(const QTextCursor &cursor) const; virtual bool isInComment(const QTextCursor &cursor) const;
virtual QString insertMatchingBrace(const QTextCursor &tc, const QString &text, const QChar &la, int *skippedChars) const; virtual QString insertMatchingBrace(const QTextCursor &tc, const QString &text, QChar la, int *skippedChars) const;
virtual QString insertParagraphSeparator(const QTextCursor &tc) const; virtual QString insertParagraphSeparator(const QTextCursor &tc) const;
private: private:
virtual bool isElectricCharacter(const QChar &ch) const; virtual bool isElectricCharacter(QChar ch) const;
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar); virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
bool isClosingBrace(const QList<QmlJS::Token> &tokens) const; bool isClosingBrace(const QList<QmlJS::Token> &tokens) const;

View File

@@ -3774,7 +3774,7 @@ void BaseTextEditor::zoomReset()
emit requestZoomReset(); emit requestZoomReset();
} }
bool BaseTextEditor::isElectricCharacter(const QChar &) const bool BaseTextEditor::isElectricCharacter(QChar) const
{ {
return false; return false;
} }
@@ -3831,7 +3831,7 @@ bool BaseTextEditor::isInComment(const QTextCursor &cursor) const
} }
QString BaseTextEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text, QString BaseTextEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text,
const QChar &la, int *skippedChars) const QChar la, int *skippedChars) const
{ {
Q_UNUSED(tc); Q_UNUSED(tc);
Q_UNUSED(text); Q_UNUSED(text);

View File

@@ -389,7 +389,7 @@ protected:
public: public:
// Returns true if key triggers an indent. // Returns true if key triggers an indent.
virtual bool isElectricCharacter(const QChar &ch) const; virtual bool isElectricCharacter(QChar ch) const;
void indentInsertedText(const QTextCursor &tc); void indentInsertedText(const QTextCursor &tc);
@@ -411,7 +411,7 @@ public:
// Returns true if the cursor is inside a comment. // Returns true if the cursor is inside a comment.
virtual bool isInComment(const QTextCursor &cursor) const; virtual bool isInComment(const QTextCursor &cursor) const;
virtual QString insertMatchingBrace(const QTextCursor &tc, const QString &text, const QChar &la, int *skippedChars) const; virtual QString insertMatchingBrace(const QTextCursor &tc, const QString &text, QChar la, int *skippedChars) const;
// Returns the text that needs to be inserted // Returns the text that needs to be inserted
virtual QString insertParagraphSeparator(const QTextCursor &tc) const; virtual QString insertParagraphSeparator(const QTextCursor &tc) const;

View File

@@ -176,7 +176,7 @@ QString IoUtils::shellQuote(const QString &arg)
#else // Q_OS_WIN #else // Q_OS_WIN
inline static bool isSpecial(const QChar &cUnicode) inline static bool isSpecial(QChar cUnicode)
{ {
static const uchar iqm[] = { static const uchar iqm[] = {
0xff, 0xff, 0xff, 0xff, 0xdf, 0x07, 0x00, 0xd8, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x07, 0x00, 0xd8,