diff --git a/bin/gdbmacros/gdbmacros.cpp b/bin/gdbmacros/gdbmacros.cpp index 199b783f45d..9ea2a9aff56 100644 --- a/bin/gdbmacros/gdbmacros.cpp +++ b/bin/gdbmacros/gdbmacros.cpp @@ -122,6 +122,7 @@ int qtGhVersion = QT_VERSION; # include #endif +#include #include #include @@ -406,12 +407,13 @@ struct QDumper QDumper &operator<<(unsigned int i); QDumper &operator<<(const void *p); QDumper &operator<<(qulonglong c); - void put(char c); - void addCommaIfNeeded(); - void putBase64Encoded(const char *buf, int n); QDumper &operator<<(const char *str); QDumper &operator<<(const QByteArray &ba); QDumper &operator<<(const QString &str); + void put(char c); + void addCommaIfNeeded(); + void putBase64Encoded(const char *buf, int n); + void putEllipsis(); void disarm(); void beginHash(); // start of data hash output @@ -657,6 +659,11 @@ void QDumper::endHash() put('}'); } +void QDumper::putEllipsis() +{ + addCommaIfNeeded(); + *this << "{name=\"\",value=\"\",type=\"" << innertype << "\"}"; +} // // Some helpers to keep the dumper code short @@ -815,6 +822,27 @@ static void qDumpInnerValue(QDumper &d, const char *type, const void *addr) } +static void qDumpInnerValueOrPointer(QDumper &d, + const char *type, const char *strippedtype, const void *addr) +{ + if (strippedtype) { + if (deref(addr)) { + P(d, "addr", deref(addr)); + P(d, "type", strippedtype); + qDumpInnerValueHelper(d, strippedtype, deref(addr)); + } else { + P(d, "addr", addr); + P(d, "type", strippedtype); + P(d, "value", ""); + P(d, "numchild", "0"); + } + } else { + P(d, "addr", addr); + P(d, "type", type); + qDumpInnerValueHelper(d, type, addr); + } +} + ////////////////////////////////////////////////////////////////////////////// static void qDumpQByteArray(QDumper &d) @@ -1212,9 +1240,8 @@ static void qDumpQList(QDumper &d) bool isInternal = innerSize <= int(sizeof(void*)) && isMovableType(d.innertype); - P(d, "internal", (int)isInternal); - - P(d, "childtype", d.innertype); + P(d, "internal", (int)isInternal); + P(d, "childtype", d.innertype); if (n > 1000) n = 1000; d << ",children=["; @@ -1244,11 +1271,8 @@ static void qDumpQList(QDumper &d) } d.endHash(); } - if (n < nn) { - d.beginHash(); - P(d, "value", ""); - d.endHash(); - } + if (n < nn) + d.putEllipsis(); d << "]"; } d.disarm(); @@ -1490,7 +1514,6 @@ static void qDumpQObject(QDumper &d) d.beginHash(); P(d, "name", "methods"); P(d, "exp", "*(class '"NS"QObject'*)" << d.data); - P(d, "type", NS"QObjectMethodList"); P(d, "value", "<" << mo->methodCount() << " items>"); P(d, "numchild", mo->methodCount()); d.endHash(); @@ -1876,11 +1899,7 @@ static void qDumpQSet(QDumper &d) d.endHash(); ++i; if (i > 10000) { - d.beginHash(); - P(d, "name", "Warning:"); - P(d, "value", ""); - P(d, "type", ""); - d.endHash(); + d.putEllipsis(); break; } } @@ -1935,13 +1954,8 @@ static void qDumpQStringList(QDumper &d) P(d, "valueencoded", "1"); d.endHash(); } - if (n < list.size()) { - d.beginHash(); - P(d, "name", "Warning:"); - P(d, "value", ""); - P(d, "type", ""); - d.endHash(); - } + if (n < list.size()) + d.putEllipsis(); d << "]"; } d.disarm(); @@ -2065,37 +2079,68 @@ static void qDumpQVector(QDumper &d) P(d, "valuedisabled", "true"); P(d, "numchild", n); if (d.dumpChildren) { - bool innerTypeIsPointer = isPointerType(d.innertype); QByteArray strippedInnerType = stripPointerType(d.innertype); - + const char *stripped = + isPointerType(d.innertype) ? strippedInnerType.data() : 0; if (n > 1000) n = 1000; d << ",children=["; for (int i = 0; i != n; ++i) { d.beginHash(); P(d, "name", "[" << i << "]"); - const void *p = addOffset(v, i * innersize + typeddatasize); - if (innerTypeIsPointer) { - if (deref(p)) { - //P(d, "value","@" << p); - qDumpInnerValue(d, strippedInnerType.data(), deref(p)); - } else { - P(d, "type", d.innertype); - P(d, "value", ""); - P(d, "numchild", "0"); - } - } else { - qDumpInnerValue(d, d.innertype, p); - } + qDumpInnerValueOrPointer(d, d.innertype, stripped, + addOffset(v, i * innersize + typeddatasize)); d.endHash(); } - if (n < nn) { + if (n < nn) + d.putEllipsis(); + d << "]"; + } + d.disarm(); +} + +static void qDumpStdList(QDumper &d) +{ + const std::list &list = *reinterpret_cast *>(d.data); + const void *p = d.data; + qCheckAccess(p); + p = deref(p); + qCheckAccess(p); + p = deref(p); + qCheckAccess(p); + p = deref(addOffset(d.data, sizeof(void*))); + qCheckAccess(p); + p = deref(addOffset(p, sizeof(void*))); + qCheckAccess(p); + p = deref(addOffset(p, sizeof(void*))); + qCheckAccess(p); + + int nn = 0; + std::list::const_iterator it = list.begin(); + for (; nn < 101 && it != list.end(); ++nn, ++it) + qCheckAccess(it.operator->()); + + if (nn > 100) + P(d, "value", ""); + else + P(d, "value", "<" << nn << " items>"); + P(d, "numchild", nn); + + P(d, "valuedisabled", "true"); + if (d.dumpChildren) { + QByteArray strippedInnerType = stripPointerType(d.innertype); + const char *stripped = + isPointerType(d.innertype) ? strippedInnerType.data() : 0; + d << ",children=["; + it = list.begin(); + for (int i = 0; i < 1000 && it != list.end(); ++i, ++it) { d.beginHash(); - P(d, "name", "[...]"); - P(d, "value", ""); - P(d, "type", d.innertype); + P(d, "name", "[" << i << "]"); + qDumpInnerValueOrPointer(d, d.innertype, stripped, it.operator->()); d.endHash(); } + if (it != list.end()) + d.putEllipsis(); d << "]"; } d.disarm(); @@ -2167,37 +2212,21 @@ static void qDumpStdVector(QDumper &d) P(d, "numchild", n); if (d.dumpChildren) { unsigned innersize = d.extraInt[0]; - bool innerTypeIsPointer = isPointerType(d.innertype); QByteArray strippedInnerType = stripPointerType(d.innertype); - + const char *stripped = + isPointerType(d.innertype) ? strippedInnerType.data() : 0; if (n > 1000) n = 1000; d << ",children=["; for (int i = 0; i != n; ++i) { d.beginHash(); P(d, "name", "[" << i << "]"); - const void *p = addOffset(v->start, i * innersize); - if (innerTypeIsPointer) { - if (deref(p)) { - //P(d, "value","@" << p); - qDumpInnerValue(d, strippedInnerType.data(), deref(p)); - } else { - P(d, "type", d.innertype); - P(d, "value", ""); - P(d, "numchild", "0"); - } - } else { - qDumpInnerValue(d, d.innertype, p); - } - d.endHash(); - } - if (n < nn) { - d.beginHash(); - P(d, "name", "[...]"); - P(d, "value", ""); - P(d, "type", d.innertype); + qDumpInnerValueOrPointer(d, d.innertype, stripped, + addOffset(v->start, i * innersize)); d.endHash(); } + if (n < nn) + d.putEllipsis(); d << "]"; } d.disarm(); @@ -2325,6 +2354,8 @@ static void handleProtocolVersion2and3(QDumper & d) qDumpStdVector(d); else if (isEqual(type, "std::vector::bool")) qDumpStdVectorBool(d); + else if (isEqual(type, "std::list")) + qDumpStdList(d); else if (isEqual(type, "string")) qDumpStdString(d); else if (isEqual(type, "std::string")) diff --git a/doc/coding-style.qdoc b/doc/coding-style.qdoc new file mode 100644 index 00000000000..f028e56fe74 --- /dev/null +++ b/doc/coding-style.qdoc @@ -0,0 +1,246 @@ +/*! + +\contentpage{index.html}{Qt Creator} +\page coding-style.html + +\title Qt Creator Coding Rules + +THIS IS PRELIMINARY. + +\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. +\endlist + + + +\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 +and + +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. + +\code + ++T; + --U; + -NOT- + T++; // not used in Qt Creator + U--; // not used in Qt Creator +\endcode + +\o Try to minimize evaluation of the same code over and over. This is + aimed especially at loops. + +\code + + Container::iterator end = large.end(); + for (Container::iterator it = large.begin(); it != end; ++it) { + ...; + } + -NOT- + for (Container::iterator it = large.begin(); + it != large.end(); ++it) { + ...; + } +\endcode + + + +\section1 Formatting + +\section2 Declarations + +Only one declaration on each line. +\code + int a; + int b; + -NOT- + int a, b; // not used in Qt Creator +\endcode + + This is especially important when initialization is done at the same + time. +\code + QString a = "Joe"; + QString b = "Foo"; + -NOT- + QString a = "Joe", b = "Foo"; // not used in Qt Creator +\endcode + [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 + +\code + char *p = "flop"; + char &c = *p; + -NOT- + char* p = "flop"; // not used in Qt Creator + char & c = *p; // not used in Qt Creator +\endcode + + This is simply in line with the official Qt guide lines. + + Also note that we will have: +\code + const char *p; + -NOT- + char const * p; // not used in Qt Creator +\endcode + + + Using a plain 0 for Null pointer constants is always correct and least effort + to type. So: +\code + void *p = 0; + -NOT- + void *p = NULL; // not used in Qt Creator + -NOT- + void *p = '\0'; // not used in Qt Creator + -NOT- + void *p = 42 - 7 * 6; // also not used in Qt Creator +\endcode + 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 +\code + operator==(type) + -NOT- + operator == (type) // not used in Qt Creator +\endcode + + The == is part of the function name, separating it makes the + declaration look like an expression. + + +\section2 Function names and parentheses +\code + void mangle() + -NOT- + void mangle () // not used in Qt Creator +\endcode + + + +\section2 Naming rules + + Simply follow the style of Qt proper. As examples: + \list + \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. +\endlist + + + +\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. + + +*/ diff --git a/shared/cplusplus/Keywords.cpp b/shared/cplusplus/Keywords.cpp index 0e19b6b1d4f..d5ec6b5d432 100644 --- a/shared/cplusplus/Keywords.cpp +++ b/shared/cplusplus/Keywords.cpp @@ -1208,4 +1208,141 @@ int Lexer::classify(const char *s, int n, bool q) { } // switch } +static inline int classifyOperator2(const char *s) { + if (s[0] == 'o') { + if (s[1] == 'r') { + return T_OR; + } + } + return T_IDENTIFIER; +} + +static inline int classifyOperator3(const char *s) { + if (s[0] == 'a') { + if (s[1] == 'n') { + if (s[2] == 'd') { + return T_AND; + } + } + } + else if (s[0] == 'n') { + if (s[1] == 'o') { + if (s[2] == 't') { + return T_NOT; + } + } + } + else if (s[0] == 'x') { + if (s[1] == 'o') { + if (s[2] == 'r') { + return T_XOR; + } + } + } + return T_IDENTIFIER; +} + +static inline int classifyOperator5(const char *s) { + if (s[0] == 'b') { + if (s[1] == 'i') { + if (s[2] == 't') { + if (s[3] == 'o') { + if (s[4] == 'r') { + return T_BITOR; + } + } + } + } + } + else if (s[0] == 'c') { + if (s[1] == 'o') { + if (s[2] == 'm') { + if (s[3] == 'p') { + if (s[4] == 'l') { + return T_COMPL; + } + } + } + } + } + else if (s[0] == 'o') { + if (s[1] == 'r') { + if (s[2] == '_') { + if (s[3] == 'e') { + if (s[4] == 'q') { + return T_OR_EQ; + } + } + } + } + } + return T_IDENTIFIER; +} + +static inline int classifyOperator6(const char *s) { + if (s[0] == 'a') { + if (s[1] == 'n') { + if (s[2] == 'd') { + if (s[3] == '_') { + if (s[4] == 'e') { + if (s[5] == 'q') { + return T_AND_EQ; + } + } + } + } + } + } + else if (s[0] == 'b') { + if (s[1] == 'i') { + if (s[2] == 't') { + if (s[3] == 'a') { + if (s[4] == 'n') { + if (s[5] == 'd') { + return T_BITAND; + } + } + } + } + } + } + else if (s[0] == 'n') { + if (s[1] == 'o') { + if (s[2] == 't') { + if (s[3] == '_') { + if (s[4] == 'e') { + if (s[5] == 'q') { + return T_NOT_EQ; + } + } + } + } + } + } + else if (s[0] == 'x') { + if (s[1] == 'o') { + if (s[2] == 'r') { + if (s[3] == '_') { + if (s[4] == 'e') { + if (s[5] == 'q') { + return T_XOR_EQ; + } + } + } + } + } + } + return T_IDENTIFIER; +} + +int Lexer::classifyOperator(const char *s, int n) { + switch (n) { + case 2: return classifyOperator2(s); + case 3: return classifyOperator3(s); + case 5: return classifyOperator5(s); + case 6: return classifyOperator6(s); + default: return T_IDENTIFIER; + } // switch +} + CPLUSPLUS_END_NAMESPACE diff --git a/shared/cplusplus/Lexer.cpp b/shared/cplusplus/Lexer.cpp index af6f09f74d2..2e9ae98c1e0 100644 --- a/shared/cplusplus/Lexer.cpp +++ b/shared/cplusplus/Lexer.cpp @@ -589,8 +589,13 @@ void Lexer::scan_helper(Token *tok) tok->kind = classify(yytext, yylen, _qtMocRunEnabled); else tok->kind = T_IDENTIFIER; - if (tok->kind == T_IDENTIFIER && control()) - tok->identifier = control()->findOrInsertIdentifier(yytext, yylen); + + if (tok->kind == T_IDENTIFIER) { + tok->kind = classifyOperator(yytext, yylen); + + if (control()) + tok->identifier = control()->findOrInsertIdentifier(yytext, yylen); + } break; } else if (std::isdigit(ch)) { const char *yytext = _currentChar - 1; diff --git a/shared/cplusplus/Lexer.h b/shared/cplusplus/Lexer.h index 1d85a58eb9f..57f9d3e1362 100644 --- a/shared/cplusplus/Lexer.h +++ b/shared/cplusplus/Lexer.h @@ -112,6 +112,7 @@ private: void scan_helper(Token *tok); void setSource(const char *firstChar, const char *lastChar); static int classify(const char *string, int length, bool q); + static int classifyOperator(const char *string, int length); inline void yyinp() { diff --git a/shared/cplusplus/Token.h b/shared/cplusplus/Token.h index e172fea5680..f017bbc8e7e 100644 --- a/shared/cplusplus/Token.h +++ b/shared/cplusplus/Token.h @@ -209,7 +209,19 @@ enum Kind { T_LAST_KEYWORD = T_SLOTS, - // ### aliases + // aliases + T_OR = T_PIPE_PIPE, + T_AND = T_AMPER_AMPER, + T_NOT = T_EXCLAIM, + T_XOR = T_CARET, + T_BITOR = T_PIPE, + T_COMPL = T_TILDE, + T_OR_EQ = T_PIPE_EQUAL, + T_AND_EQ = T_AMPER_EQUAL, + T_BITAND = T_AMPER, + T_NOT_EQ = T_EXCLAIM_EQUAL, + T_XOR_EQ = T_CARET_EQUAL, + T___ASM = T_ASM, T___ASM__ = T_ASM, diff --git a/src/app/main.cpp b/src/app/main.cpp index ad61ab0c750..eedc9e13653 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -69,7 +69,7 @@ static const char *HELP_OPTION4 = "--help"; static const char *VERSION_OPTION = "-version"; static const char *CLIENT_OPTION = "-client"; -typedef QSet PluginSpecSet; +typedef QList PluginSpecSet; // Helpers for displaying messages. Note that there is no console on Windows. #ifdef Q_WS_WIN diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp index 3e619548a23..d670e7e0018 100644 --- a/src/libs/cplusplus/CppDocument.cpp +++ b/src/libs/cplusplus/CppDocument.cpp @@ -33,8 +33,6 @@ #include "CppDocument.h" -#include - #include #include #include @@ -133,12 +131,16 @@ QString Document::fileName() const QStringList Document::includedFiles() const { - return _includedFiles; + QStringList files; + foreach (const Include &i, _includes) + files.append(i.fileName()); + files.removeDuplicates(); + return files; } -void Document::addIncludeFile(const QString &fileName) +void Document::addIncludeFile(const QString &fileName, unsigned line) { - _includedFiles.append(fileName); + _includes.append(Include(fileName, line)); } void Document::appendMacro(const Macro ¯o) @@ -273,7 +275,7 @@ bool Document::parse(ParseMode mode) void Document::check() { - QTC_ASSERT(!_globalNamespace, return); + Q_ASSERT(!_globalNamespace); Semantic semantic(_control); diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h index aaca36c18ee..54de3c801ea 100644 --- a/src/libs/cplusplus/CppDocument.h +++ b/src/libs/cplusplus/CppDocument.h @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include #include @@ -65,7 +65,7 @@ public: QString fileName() const; QStringList includedFiles() const; - void addIncludeFile(const QString &fileName); + void addIncludeFile(const QString &fileName, unsigned line); void appendMacro(const Macro ¯o); void addMacroUse(const Macro ¯o, unsigned offset, unsigned length); @@ -181,6 +181,22 @@ public: { return pos >= _begin && pos < _end; } }; + class Include { + QString _fileName; + unsigned _line; + + public: + Include(const QString &fileName, unsigned line) + : _fileName(fileName), _line(line) + { } + + QString fileName() const + { return _fileName; } + + unsigned line() const + { return _line; } + }; + class MacroUse: public Block { Macro _macro; @@ -196,6 +212,9 @@ public: { return _macro; } }; + QList includes() const + { return _includes; } + QList skippedBlocks() const { return _skippedBlocks; } @@ -207,16 +226,26 @@ private: private: QString _fileName; - QStringList _includedFiles; Control *_control; TranslationUnit *_translationUnit; Namespace *_globalNamespace; QList _diagnosticMessages; + QList _includes; QList _definedMacros; QList _skippedBlocks; QList _macroUses; }; +class CPLUSPLUS_EXPORT Snapshot: public QMap +{ +public: + Snapshot() + { } + + ~Snapshot() + { } +}; + } // end of namespace CPlusPlus #endif // CPPDOCUMENT_H diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 67eb05d7f4a..8b24b59f5ef 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -77,7 +77,7 @@ LookupContext::LookupContext(Control *control) LookupContext::LookupContext(Symbol *symbol, Document::Ptr expressionDocument, Document::Ptr thisDocument, - const QMap &documents) + const Snapshot &documents) : _symbol(symbol), _expressionDocument(expressionDocument), _thisDocument(thisDocument), diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index 36ea6a8298f..18754bf6670 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -57,7 +57,7 @@ public: LookupContext(Symbol *symbol, Document::Ptr expressionDocument, Document::Ptr thisDocument, - const QMap &documents); + const Snapshot &documents); LookupContext(Symbol *symbol, const LookupContext &context); @@ -87,7 +87,7 @@ public: QList resolveClassOrNamespace(Name *name) const { return resolveClassOrNamespace(name, visibleScopes()); } - QMap documents() const + Snapshot snapshot() const { return _documents; } enum ResolveMode { @@ -140,7 +140,7 @@ private: Document::Ptr _thisDocument; // All documents. - QMap _documents; + Snapshot _documents; // Visible scopes. QList _visibleScopes; diff --git a/src/libs/cplusplus/OverviewModel.cpp b/src/libs/cplusplus/OverviewModel.cpp index 7f38cb8ba1a..b1b7267027c 100644 --- a/src/libs/cplusplus/OverviewModel.cpp +++ b/src/libs/cplusplus/OverviewModel.cpp @@ -34,8 +34,6 @@ #include "OverviewModel.h" #include "Overview.h" -#include - #include #include #include @@ -83,13 +81,13 @@ QModelIndex OverviewModel::index(int row, int column, const QModelIndex &parent) return createIndex(row, column, symbol); } else { Symbol *parentSymbol = static_cast(parent.internalPointer()); - QTC_ASSERT(parentSymbol, return QModelIndex()); + Q_ASSERT(parentSymbol); ScopedSymbol *scopedSymbol = parentSymbol->asScopedSymbol(); - QTC_ASSERT(scopedSymbol, return QModelIndex()); + Q_ASSERT(scopedSymbol); Scope *scope = scopedSymbol->members(); - QTC_ASSERT(scope, return QModelIndex()); + Q_ASSERT(scope); return createIndex(row, 0, scope->symbolAt(row)); } @@ -126,12 +124,12 @@ int OverviewModel::rowCount(const QModelIndex &parent) const if (!parent.parent().isValid() && parent.row() == 0) // account for no symbol item return 0; Symbol *parentSymbol = static_cast(parent.internalPointer()); - QTC_ASSERT(parentSymbol, return 0); + Q_ASSERT(parentSymbol); if (ScopedSymbol *scopedSymbol = parentSymbol->asScopedSymbol()) { if (!scopedSymbol->isFunction()) { Scope *parentScope = scopedSymbol->members(); - QTC_ASSERT(parentScope, return 0); + Q_ASSERT(parentScope); return parentScope->symbolCount(); } diff --git a/src/libs/cplusplus/ResolveExpression.cpp b/src/libs/cplusplus/ResolveExpression.cpp index 6915e1169b0..0ea9018a353 100644 --- a/src/libs/cplusplus/ResolveExpression.cpp +++ b/src/libs/cplusplus/ResolveExpression.cpp @@ -45,8 +45,6 @@ #include #include -#include - #include #include @@ -100,7 +98,7 @@ protected: // types virtual void visit(PointerToMemberType * /*ty*/) { - QTC_ASSERT(false, /**/); + Q_ASSERT(false); } virtual void visit(PointerType *ty) @@ -152,32 +150,32 @@ protected: { /* nothing to do*/ } virtual void visit(Namespace *) - { QTC_ASSERT(false, /**/); } + { Q_ASSERT(false); } virtual void visit(Class *) - { QTC_ASSERT(false, /**/); } + { Q_ASSERT(false); } virtual void visit(Enum *) - { QTC_ASSERT(false, /**/); } + { Q_ASSERT(false); } // names virtual void visit(NameId *) - { QTC_ASSERT(false, /**/); } + { Q_ASSERT(false); } virtual void visit(TemplateNameId *) - { QTC_ASSERT(false, /**/); } + { Q_ASSERT(false); } virtual void visit(DestructorNameId *) - { QTC_ASSERT(false, /**/); } + { Q_ASSERT(false); } virtual void visit(OperatorNameId *) - { QTC_ASSERT(false, /**/); } + { Q_ASSERT(false); } virtual void visit(ConversionNameId *) - { QTC_ASSERT(false, /**/); } + { Q_ASSERT(false); } virtual void visit(QualifiedNameId *) - { QTC_ASSERT(false, /**/); } + { Q_ASSERT(false); } }; } // end of anonymous namespace diff --git a/src/libs/cplusplus/TypeOfExpression.cpp b/src/libs/cplusplus/TypeOfExpression.cpp index 487c9f8a469..cb373cce027 100644 --- a/src/libs/cplusplus/TypeOfExpression.cpp +++ b/src/libs/cplusplus/TypeOfExpression.cpp @@ -37,6 +37,7 @@ #include #include #include +#include using namespace CPlusPlus; @@ -45,21 +46,25 @@ TypeOfExpression::TypeOfExpression(): { } -void TypeOfExpression::setDocuments(const QMap &documents) +void TypeOfExpression::setSnapshot(const Snapshot &documents) { - m_documents = documents; + m_snapshot = documents; m_lookupContext = LookupContext(); } QList TypeOfExpression::operator()(const QString &expression, Document::Ptr document, - Symbol *lastVisibleSymbol) + Symbol *lastVisibleSymbol, + PreprocessMode mode) { - Document::Ptr expressionDoc = documentForExpression(expression); + QString code = expression; + if (mode == Preprocess) + code = preprocessedExpression(expression, m_snapshot, document); + Document::Ptr expressionDoc = documentForExpression(code); m_ast = extractExpressionAST(expressionDoc); m_lookupContext = LookupContext(lastVisibleSymbol, expressionDoc, - document, m_documents); + document, m_snapshot); ResolveExpression resolveExpression(m_lookupContext); return resolveExpression(m_ast); @@ -97,3 +102,36 @@ Document::Ptr TypeOfExpression::documentForExpression(const QString &expression) doc->parse(Document::ParseExpression); return doc; } + +void TypeOfExpression::processEnvironment(Snapshot documents, + Document::Ptr doc, Environment *env, + QSet *processed) const +{ + if (! doc) + return; + if (processed->contains(doc->fileName())) + return; + processed->insert(doc->fileName()); + foreach (const Document::Include &incl, doc->includes()) { + processEnvironment(documents, + documents.value(incl.fileName()), + env, processed); + } + foreach (const Macro ¯o, doc->definedMacros()) + env->bind(macro); +} + +QString TypeOfExpression::preprocessedExpression(const QString &expression, + Snapshot documents, + Document::Ptr thisDocument) const +{ + Environment env; + QSet processed; + processEnvironment(documents, thisDocument, + &env, &processed); + const QByteArray code = expression.toUtf8(); + pp preproc(0, env); + QByteArray preprocessedCode; + preproc("", code, &preprocessedCode); + return QString::fromUtf8(preprocessedCode); +} diff --git a/src/libs/cplusplus/TypeOfExpression.h b/src/libs/cplusplus/TypeOfExpression.h index cd7a23441fd..87d4113f30e 100644 --- a/src/libs/cplusplus/TypeOfExpression.h +++ b/src/libs/cplusplus/TypeOfExpression.h @@ -43,6 +43,9 @@ namespace CPlusPlus { +class Environment; +class Macro; + class CPLUSPLUS_EXPORT TypeOfExpression { public: @@ -58,7 +61,12 @@ public: * Also clears the lookup context, so can be used to make sure references * to the documents previously used are removed. */ - void setDocuments(const QMap &documents); + void setSnapshot(const Snapshot &documents); + + enum PreprocessMode { + NoPreprocess, + Preprocess + }; /** * Returns a list of possible fully specified types associated with the @@ -73,7 +81,8 @@ public: * @param lastVisibleSymbol The last visible symbol in the document. */ QList operator()(const QString &expression, Document::Ptr document, - Symbol *lastVisibleSymbol); + Symbol *lastVisibleSymbol, + PreprocessMode mode = NoPreprocess); /** * Returns the AST of the last evaluated expression. @@ -91,7 +100,15 @@ private: ExpressionAST *extractExpressionAST(Document::Ptr doc) const; Document::Ptr documentForExpression(const QString &expression) const; - QMap m_documents; + void processEnvironment(CPlusPlus::Snapshot documents, + CPlusPlus::Document::Ptr doc, CPlusPlus::Environment *env, + QSet *processed) const; + + QString preprocessedExpression(const QString &expression, + CPlusPlus::Snapshot documents, + CPlusPlus::Document::Ptr thisDocument) const; + + Snapshot m_snapshot; ExpressionAST *m_ast; LookupContext m_lookupContext; }; diff --git a/src/libs/cplusplus/pp-client.h b/src/libs/cplusplus/pp-client.h index 2fc781f22f5..eead5bf4600 100644 --- a/src/libs/cplusplus/pp-client.h +++ b/src/libs/cplusplus/pp-client.h @@ -63,7 +63,8 @@ public: { } virtual void macroAdded(const Macro ¯o) = 0; - virtual void sourceNeeded(QString &fileName, IncludeType mode) = 0; // ### FIX the signature. + virtual void sourceNeeded(QString &fileName, IncludeType mode, + unsigned line) = 0; // ### FIX the signature. virtual void startExpandingMacro(unsigned offset, const Macro ¯o, diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 83386e8079c..c33fc8cb151 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -818,7 +818,7 @@ void pp::processInclude(bool skipCurentPath, QString fn = QString::fromUtf8(path.constData(), path.length()); if (client) - client->sourceNeeded(fn, Client::IncludeGlobal); + client->sourceNeeded(fn, Client::IncludeGlobal, firstToken->lineno); } else if (tk->is(T_ANGLE_STRING_LITERAL) || tk->is(T_STRING_LITERAL)) { const QByteArray spell = tokenSpell(*tk); const char *beginOfPath = spell.constBegin(); @@ -831,7 +831,7 @@ void pp::processInclude(bool skipCurentPath, QString fn = QString::fromUtf8(path.constData(), path.length()); if (client) - client->sourceNeeded(fn, Client::IncludeLocal); + client->sourceNeeded(fn, Client::IncludeLocal, firstToken->lineno); } } } diff --git a/src/libs/cplusplus/pp-environment.cpp b/src/libs/cplusplus/pp-environment.cpp index 20491727a4c..dd839087a40 100644 --- a/src/libs/cplusplus/pp-environment.cpp +++ b/src/libs/cplusplus/pp-environment.cpp @@ -53,8 +53,6 @@ #include "pp-environment.h" #include "pp.h" -#include - #include using namespace CPlusPlus; @@ -93,7 +91,7 @@ Macro *Environment::macroAt(unsigned index) const Macro *Environment::bind(const Macro &__macro) { - QTC_ASSERT(! __macro.name.isEmpty(), return 0); + Q_ASSERT(! __macro.name.isEmpty()); Macro *m = new Macro (__macro); m->hashcode = hash_code(m->name); diff --git a/src/libs/extensionsystem/optionsparser.cpp b/src/libs/extensionsystem/optionsparser.cpp index 8884cb378ce..09dbaa59b72 100644 --- a/src/libs/extensionsystem/optionsparser.cpp +++ b/src/libs/extensionsystem/optionsparser.cpp @@ -129,7 +129,7 @@ bool OptionsParser::checkForNoLoadOption() "The plugin '%1' does not exist.").arg(m_currentArg); m_hasError = true; } else { - m_pmPrivate->pluginSpecs.remove(spec); + m_pmPrivate->pluginSpecs.removeAll(spec); delete spec; m_isDependencyRefreshNeeded = true; } diff --git a/src/libs/extensionsystem/pluginmanager.cpp b/src/libs/extensionsystem/pluginmanager.cpp index 3f7ba386e4e..90e6e4bb004 100644 --- a/src/libs/extensionsystem/pluginmanager.cpp +++ b/src/libs/extensionsystem/pluginmanager.cpp @@ -48,7 +48,7 @@ #include #endif -typedef QSet PluginSpecSet; +typedef QList PluginSpecSet; enum { debugLeaks = 0 }; @@ -162,6 +162,11 @@ enum { debugLeaks = 0 }; using namespace ExtensionSystem; using namespace ExtensionSystem::Internal; +static bool lessThanByPluginName(const PluginSpec *one, const PluginSpec *two) +{ + return one->name() < two->name(); +} + PluginManager *PluginManager::m_instance = 0; /*! @@ -306,7 +311,7 @@ QStringList PluginManager::arguments() const } /*! - \fn QSet PluginManager::plugins() const + \fn QList PluginManager::plugins() const List of all plugin specifications that have been found in the plugin search paths. This list is valid directly after the setPluginPaths() call. The plugin specifications contain the information from the plugins' xml description files @@ -315,7 +320,7 @@ QStringList PluginManager::arguments() const \sa setPluginPaths() */ -QSet PluginManager::plugins() const +QList PluginManager::plugins() const { return d->pluginSpecs; } @@ -703,9 +708,11 @@ void PluginManagerPrivate::readPluginPaths() foreach (const QString &specFile, specFiles) { PluginSpec *spec = new PluginSpec; spec->d->read(specFile); - pluginSpecs.insert(spec); + pluginSpecs.append(spec); } resolveDependencies(); + // ensure deterministic plugin load order by sorting + qSort(pluginSpecs.begin(), pluginSpecs.end(), lessThanByPluginName); emit q->pluginsChanged(); } diff --git a/src/libs/extensionsystem/pluginmanager.h b/src/libs/extensionsystem/pluginmanager.h index e46451901e9..e621fbea17f 100644 --- a/src/libs/extensionsystem/pluginmanager.h +++ b/src/libs/extensionsystem/pluginmanager.h @@ -101,7 +101,7 @@ public: void loadPlugins(); QStringList pluginPaths() const; void setPluginPaths(const QStringList &paths); - QSet plugins() const; + QList plugins() const; void setFileExtension(const QString &extension); QString fileExtension() const; diff --git a/src/libs/extensionsystem/pluginmanager_p.h b/src/libs/extensionsystem/pluginmanager_p.h index 74cb84c8678..b286fdf2b1d 100644 --- a/src/libs/extensionsystem/pluginmanager_p.h +++ b/src/libs/extensionsystem/pluginmanager_p.h @@ -66,7 +66,7 @@ public: void loadPlugin(PluginSpec *spec, PluginSpec::State destState); void resolveDependencies(); - QSet pluginSpecs; + QList pluginSpecs; QList testSpecs; QStringList pluginPaths; QString extension; diff --git a/src/libs/extensionsystem/pluginspec.cpp b/src/libs/extensionsystem/pluginspec.cpp index 170cd72ba0b..a8694e29677 100644 --- a/src/libs/extensionsystem/pluginspec.cpp +++ b/src/libs/extensionsystem/pluginspec.cpp @@ -693,10 +693,10 @@ int PluginSpecPrivate::versionCompare(const QString &version1, const QString &ve } /*! - \fn bool PluginSpecPrivate::resolveDependencies(const QSet &specs) + \fn bool PluginSpecPrivate::resolveDependencies(const QList &specs) \internal */ -bool PluginSpecPrivate::resolveDependencies(const QSet &specs) +bool PluginSpecPrivate::resolveDependencies(const QList &specs) { if (hasError) return false; diff --git a/src/libs/extensionsystem/pluginspec_p.h b/src/libs/extensionsystem/pluginspec_p.h index 922fe36d05d..b4fefc59b32 100644 --- a/src/libs/extensionsystem/pluginspec_p.h +++ b/src/libs/extensionsystem/pluginspec_p.h @@ -56,7 +56,7 @@ public: bool read(const QString &fileName); bool provides(const QString &pluginName, const QString &version) const; - bool resolveDependencies(const QSet &specs); + bool resolveDependencies(const QList &specs); bool loadLibrary(); bool initializePlugin(); bool initializeExtensions(); diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 81a2228e669..100fdbe717f 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -46,11 +46,12 @@ #include #include #include +#include namespace Core { namespace Utils { -#ifdef Q_OS_OSX +#ifdef Q_OS_MAC /*static*/ const char * const PathChooser::browseButtonLabel = "Choose..."; #else /*static*/ const char * const PathChooser::browseButtonLabel = "Browse..."; @@ -112,7 +113,11 @@ PathChooser::PathChooser(QWidget *parent) : hLayout->addWidget(m_d->m_lineEdit); hLayout->setSizeConstraint(QLayout::SetMinimumSize); +#ifdef Q_OS_MAC + QPushButton *browseButton = new QPushButton; +#else QToolButton *browseButton = new QToolButton; +#endif browseButton->setText(tr(browseButtonLabel)); connect(browseButton, SIGNAL(clicked()), this, SLOT(slotBrowse())); diff --git a/src/plugins/bookmarks/bookmarksplugin.cpp b/src/plugins/bookmarks/bookmarksplugin.cpp index 83c8ec397ee..615ba5ec2ac 100644 --- a/src/plugins/bookmarks/bookmarksplugin.cpp +++ b/src/plugins/bookmarks/bookmarksplugin.cpp @@ -201,14 +201,18 @@ void BookmarksPlugin::updateActions(int state) void BookmarksPlugin::editorOpened(Core::IEditor *editor) { - connect(editor, SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)), - this, SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*))); + if (qobject_cast(editor)) { + connect(editor, SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)), + this, SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*))); + } } void BookmarksPlugin::editorAboutToClose(Core::IEditor *editor) { - disconnect(editor, SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)), - this, SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*))); + if (qobject_cast(editor)) { + disconnect(editor, SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)), + this, SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*))); + } } void BookmarksPlugin::requestContextMenu(TextEditor::ITextEditor *editor, diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 4eab3fb5571..228c58a94ac 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -186,6 +186,15 @@ MainWindow::MainWindow() : QCoreApplication::setOrganizationName(QLatin1String("Nokia")); QSettings::setDefaultFormat(QSettings::IniFormat); QString baseName = qApp->style()->objectName(); + if (baseName == "windows") { + // Sometimes we get the standard windows 95 style as a fallback + // e.g. if we are running on a KDE4 desktop + QByteArray desktopEnvironment = qgetenv("DESKTOP_SESSION"); + if (desktopEnvironment == "kde") + baseName = "plastique"; + else + baseName = "cleanlooks"; + } qApp->setStyle(new ManhattanStyle(baseName)); statusBar()->setProperty("p_styled", true); } diff --git a/src/plugins/coreplugin/navigationwidget.cpp b/src/plugins/coreplugin/navigationwidget.cpp index 82ed13a29e8..8e84df39321 100644 --- a/src/plugins/coreplugin/navigationwidget.cpp +++ b/src/plugins/coreplugin/navigationwidget.cpp @@ -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_navigationComboBox->setMaximumWidth(130); +#endif m_toolbar = new QToolBar(this); m_toolbar->setContentsMargins(0, 0, 0, 0); diff --git a/src/plugins/coreplugin/versiondialog.cpp b/src/plugins/coreplugin/versiondialog.cpp index 0decae6cf18..e534a0d1eae 100644 --- a/src/plugins/coreplugin/versiondialog.cpp +++ b/src/plugins/coreplugin/versiondialog.cpp @@ -72,7 +72,7 @@ VersionDialog::VersionDialog(QWidget *parent) "
" "Built on " __DATE__ " at " __TIME__ "
" #ifdef IDE_REVISION - "Using revision %5
" + "From revision %5
" #endif "
" "
" diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 8d4a36178ce..49b130ebc1c 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -427,7 +427,9 @@ void CPPEditor::switchDeclarationDefinition() if (!m_modelManager) return; - Document::Ptr doc = m_modelManager->document(file()->fileName()); + const Snapshot snapshot = m_modelManager->snapshot(); + + Document::Ptr doc = snapshot.value(file()->fileName()); if (!doc) return; Symbol *lastSymbol = doc->findSymbolAt(line, column); @@ -445,7 +447,7 @@ void CPPEditor::switchDeclarationDefinition() if (f) { TypeOfExpression typeOfExpression; - typeOfExpression.setDocuments(m_modelManager->documents()); + typeOfExpression.setSnapshot(m_modelManager->snapshot()); QList resolvedSymbols = typeOfExpression(QString(), doc, lastSymbol); const LookupContext &context = typeOfExpression.lookupContext(); @@ -474,26 +476,38 @@ void CPPEditor::jumpToDefinition() if (!m_modelManager) return; + const Snapshot snapshot = m_modelManager->snapshot(); + // Find the last symbol up to the cursor position int line = 0, column = 0; convertPosition(position(), &line, &column); - Document::Ptr doc = m_modelManager->document(file()->fileName()); + Document::Ptr doc = snapshot.value(file()->fileName()); if (!doc) return; + + QTextCursor tc = textCursor(); + unsigned lineno = tc.blockNumber() + 1; + foreach (const Document::Include &incl, doc->includes()) { + if (incl.line() == lineno) { + if (openCppEditorAt(incl.fileName(), 0, 0)) + return; // done + break; + } + } + Symbol *lastSymbol = doc->findSymbolAt(line, column); if (!lastSymbol) return; // Get the expression under the cursor const int endOfName = endOfNameUnderCursor(); - QTextCursor tc = textCursor(); tc.setPosition(endOfName); ExpressionUnderCursor expressionUnderCursor; const QString expression = expressionUnderCursor(tc); // Evaluate the type of the expression TypeOfExpression typeOfExpression; - typeOfExpression.setDocuments(m_modelManager->documents()); + typeOfExpression.setSnapshot(m_modelManager->snapshot()); QList resolvedSymbols = typeOfExpression(expression, doc, lastSymbol); @@ -515,7 +529,7 @@ void CPPEditor::jumpToDefinition() QList candidates = context.resolve(namedType->name()); if (!candidates.isEmpty()) { Symbol *s = candidates.takeFirst(); - openEditorAt(s->fileName(), s->line(), s->column()); + openCppEditorAt(s->fileName(), s->line(), s->column()); } #endif } @@ -524,7 +538,7 @@ void CPPEditor::jumpToDefinition() if (use.contains(endOfName - 1)) { const Macro ¯o = use.macro(); const QString fileName = QString::fromUtf8(macro.fileName); - if (TextEditor::BaseTextEditor::openEditorAt(fileName, macro.line, 0)) + if (openCppEditorAt(fileName, macro.line, 0)) return; // done } } @@ -562,7 +576,7 @@ Symbol *CPPEditor::findDefinition(Symbol *lastSymbol) QualifiedNameId *q = control.qualifiedNameId(&qualifiedName[0], qualifiedName.size()); LookupContext context(&control); - const QMap documents = m_modelManager->documents(); + const Snapshot documents = m_modelManager->snapshot(); foreach (Document::Ptr doc, documents) { QList visibleScopes; visibleScopes.append(doc->globalSymbols()); @@ -734,7 +748,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 && endText.at(endPos) == QLatin1Char('*') && endText.at(endPos+1) == QLatin1Char('/'))) { @@ -826,8 +841,15 @@ int CPPEditor::endOfNameUnderCursor() return pos; } +TextEditor::ITextEditor *CPPEditor::openCppEditorAt(const QString &fileName, + int line, int column) +{ + return TextEditor::BaseTextEditor::openEditorAt(fileName, line, column, + Constants::C_CPPEDITOR); +} + bool CPPEditor::openEditorAt(Symbol *s) { const QString fileName = QString::fromUtf8(s->fileName(), s->fileNameLength()); - return TextEditor::BaseTextEditor::openEditorAt(fileName, s->line(), s->column()); + return openCppEditorAt(fileName, s->line(), s->column()); } diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index 05f2c5d9c74..2dd88d34993 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -123,6 +123,9 @@ private: CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol); virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar); + TextEditor::ITextEditor *openCppEditorAt(const QString &fileName, int line, + int column = 0); + int previousBlockState(QTextBlock block) const; QTextCursor moveToPreviousToken(QTextCursor::MoveMode mode) const; QTextCursor moveToNextToken(QTextCursor::MoveMode mode) const; diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index 35206c2633b..addf5301f79 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -434,12 +434,15 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) //if (! expression.isEmpty()) //qDebug() << "***** expression:" << expression; - if (Document::Ptr thisDocument = m_manager->document(fileName)) { + const Snapshot snapshot = m_manager->snapshot(); + + if (Document::Ptr thisDocument = snapshot.value(fileName)) { Symbol *symbol = thisDocument->findSymbolAt(line, column); - typeOfExpression.setDocuments(m_manager->documents()); + typeOfExpression.setSnapshot(m_manager->snapshot()); - QList resolvedTypes = typeOfExpression(expression, thisDocument, symbol); + QList resolvedTypes = typeOfExpression(expression, thisDocument, symbol, + TypeOfExpression::Preprocess); LookupContext context = typeOfExpression.lookupContext(); if (!typeOfExpression.expressionAST() && (! m_completionOperator || @@ -963,8 +966,10 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item) if (Function *function = symbol->type()->asFunction()) { // If the member is a function, automatically place the opening parenthesis, // except when it might take template parameters. - if (!function->returnType().isValid() - && (function->identity() && !function->identity()->isDestructorNameId())) { + const bool hasReturnType = function->returnType().isValid() || + function->returnType().isSigned() || + function->returnType().isUnsigned(); + if (! hasReturnType && (function->identity() && !function->identity()->isDestructorNameId())) { // Don't insert any magic, since the user might have just wanted to select the class } else if (function->templateParameterCount() != 0) { @@ -1033,7 +1038,7 @@ void CppCodeCompletion::cleanup() // Set empty map in order to avoid referencing old versions of the documents // until the next completion - typeOfExpression.setDocuments(QMap()); + typeOfExpression.setSnapshot(Snapshot()); } int CppCodeCompletion::findStartOfName(const TextEditor::ITextEditor *editor) diff --git a/src/plugins/cpptools/cpphoverhandler.cpp b/src/plugins/cpptools/cpphoverhandler.cpp index 338123bc5e6..fab0d83b31f 100644 --- a/src/plugins/cpptools/cpphoverhandler.cpp +++ b/src/plugins/cpptools/cpphoverhandler.cpp @@ -165,9 +165,11 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in QTextCursor tc(edit->document()); tc.setPosition(pos); + const Snapshot documents = m_manager->snapshot(); + const int lineNumber = tc.block().blockNumber() + 1; const QString fileName = editor->file()->fileName(); - Document::Ptr doc = m_manager->document(fileName); + Document::Ptr doc = documents.value(fileName); if (doc) { foreach (Document::DiagnosticMessage m, doc->diagnosticMessages()) { if (m.line() == lineNumber) { @@ -177,6 +179,16 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in } } + if (m_toolTip.isEmpty()) { + unsigned lineno = tc.blockNumber() + 1; + foreach (const Document::Include &incl, doc->includes()) { + if (lineno == incl.line()) { + m_toolTip = incl.fileName(); + break; + } + } + } + if (m_toolTip.isEmpty()) { // Move to the end of a qualified name bool stop = false; @@ -202,7 +214,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in Symbol *lastSymbol = doc->findSymbolAt(line, column); TypeOfExpression typeOfExpression; - typeOfExpression.setDocuments(m_manager->documents()); + typeOfExpression.setSnapshot(documents); QList types = typeOfExpression(expression, doc, lastSymbol); if (!types.isEmpty()) { diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 40888d99f3f..a02656ee8c9 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -138,11 +138,12 @@ protected: virtual void stopExpandingMacro(unsigned offset, const Macro ¯o); virtual void startSkippingBlocks(unsigned offset); virtual void stopSkippingBlocks(unsigned offset); - virtual void sourceNeeded(QString &fileName, IncludeType type); + virtual void sourceNeeded(QString &fileName, IncludeType type, + unsigned line); private: QPointer m_modelManager; - CppModelManager::DocumentTable m_documents; + Snapshot m_snapshot; Environment env; pp m_proc; QStringList m_includePaths; @@ -159,7 +160,7 @@ private: CppPreprocessor::CppPreprocessor(QPointer modelManager) : m_modelManager(modelManager), - m_documents(modelManager->documents()), + m_snapshot(modelManager->snapshot()), m_proc(this, env) { } @@ -176,7 +177,7 @@ void CppPreprocessor::setProjectFiles(const QStringList &files) { m_projectFiles = files; } void CppPreprocessor::run(QString &fileName) -{ sourceNeeded(fileName, IncludeGlobal); } +{ sourceNeeded(fileName, IncludeGlobal, /*line = */ 0); } void CppPreprocessor::operator()(QString &fileName) { run(fileName); } @@ -339,7 +340,7 @@ void CppPreprocessor::mergeEnvironment(Document::Ptr doc, QSet *process processed->insert(fn); foreach (QString includedFile, doc->includedFiles()) { - mergeEnvironment(m_documents.value(includedFile), processed); + mergeEnvironment(m_snapshot.value(includedFile), processed); } foreach (const Macro macro, doc->definedMacros()) { @@ -361,7 +362,8 @@ void CppPreprocessor::stopSkippingBlocks(unsigned offset) m_currentDoc->stopSkippingBlocks(offset); } -void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type) +void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type, + unsigned line) { if (fileName.isEmpty()) return; @@ -369,7 +371,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type) QByteArray contents = tryIncludeFile(fileName, type); if (m_currentDoc) { - m_currentDoc->addIncludeFile(fileName); + m_currentDoc->addIncludeFile(fileName, line); if (contents.isEmpty() && ! QFileInfo(fileName).isAbsolute()) { QString msg; msg += fileName; @@ -384,7 +386,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type) } if (! contents.isEmpty()) { - Document::Ptr cachedDoc = m_documents.value(fileName); + Document::Ptr cachedDoc = m_snapshot.value(fileName); if (cachedDoc && m_currentDoc) { mergeEnvironment(cachedDoc); } else { @@ -475,11 +477,8 @@ CppModelManager::CppModelManager(QObject *parent) : CppModelManager::~CppModelManager() { } -Document::Ptr CppModelManager::document(const QString &fileName) const -{ return m_documents.value(fileName); } - -CppModelManager::DocumentTable CppModelManager::documents() const -{ return m_documents; } +Snapshot CppModelManager::snapshot() const +{ return m_snapshot; } void CppModelManager::ensureUpdated() { @@ -670,7 +669,7 @@ void CppModelManager::emitDocumentUpdated(Document::Ptr doc) void CppModelManager::onDocumentUpdated(Document::Ptr doc) { const QString fileName = doc->fileName(); - m_documents[fileName] = doc; + m_snapshot[fileName] = doc; QList openedEditors = m_core->editorManager()->openedEditors(); foreach (Core::IEditor *editor, openedEditors) { if (editor->file()->fileName() == fileName) { @@ -835,7 +834,7 @@ void CppModelManager::parse(QFutureInterface &future, void CppModelManager::GC() { - DocumentTable documents = m_documents; + Snapshot documents = m_snapshot; QSet processed; QStringList todo = projectFiles(); @@ -866,7 +865,7 @@ void CppModelManager::GC() } emit aboutToRemoveFiles(removedFiles); - m_documents = documents; + m_snapshot = documents; } diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index 3b2f4e19993..25947056203 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -76,8 +76,7 @@ public: virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const; virtual void updateProjectInfo(const ProjectInfo &pinfo); - virtual CPlusPlus::Document::Ptr document(const QString &fileName) const; - virtual DocumentTable documents() const; + virtual CPlusPlus::Snapshot snapshot() const; virtual void GC(); QFuture refreshSourceFiles(const QStringList &sourceFiles); @@ -146,7 +145,7 @@ private: Core::ICore *m_core; ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer; CppHoverHandler *m_hoverHandler; - DocumentTable m_documents; + CPlusPlus::Snapshot m_snapshot; // cache bool m_dirty; diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h index e3ad4fe961b..6dc0da67ca0 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.h +++ b/src/plugins/cpptools/cppmodelmanagerinterface.h @@ -46,14 +46,11 @@ namespace ProjectExplorer { namespace CppTools { -class CPPTOOLS_EXPORT CppModelManagerInterface - : public QObject +class CPPTOOLS_EXPORT CppModelManagerInterface: public QObject { Q_OBJECT public: - typedef QMap DocumentTable; // ### remove me - class ProjectInfo { public: @@ -89,8 +86,7 @@ public: virtual void GC() = 0; virtual void updateSourceFiles(const QStringList &sourceFiles) = 0; - virtual CPlusPlus::Document::Ptr document(const QString &fileName) const = 0; - virtual DocumentTable documents() const = 0; + virtual CPlusPlus::Snapshot snapshot() const = 0; virtual QList projectInfos() const = 0; virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const = 0; diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 74112379e39..170f62b5bf1 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -6,7 +6,6 @@ include(cpptools_dependencies.pri) # DEFINES += QT_NO_CAST_FROM_ASCII DEFINES += QT_NO_CAST_TO_ASCII -unix:QMAKE_CXXFLAGS_DEBUG += -O3 INCLUDEPATH += . DEFINES += CPPTOOLS_LIBRARY CONFIG += help diff --git a/src/plugins/cpptools/searchsymbols.h b/src/plugins/cpptools/searchsymbols.h index 4997e5cf049..494455f6d85 100644 --- a/src/plugins/cpptools/searchsymbols.h +++ b/src/plugins/cpptools/searchsymbols.h @@ -43,6 +43,7 @@ #include #include #include +#include #include diff --git a/src/plugins/debugger/debugger.pro b/src/plugins/debugger/debugger.pro index 3d67e19c6aa..7308fb441c2 100644 --- a/src/plugins/debugger/debugger.pro +++ b/src/plugins/debugger/debugger.pro @@ -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 diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index a01a3ddc57e..4981f199790 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -1033,7 +1033,6 @@ void DebuggerManager::addToWatchWindow() void DebuggerManager::watchExpression(const QString &expression) { watchHandler()->watchExpression(expression); - //engine()->updateWatchModel(); } void DebuggerManager::setBreakpoint(const QString &fileName, int lineNumber) diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 37406f70cc1..d9217069c68 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -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"; removeObject(m_debugMode); removeObject(m_generalOptionPage); - removeObject(m_typeMacroPage); // 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 mdebug->addAction(cmd); m_generalOptionPage = 0; - m_typeMacroPage = 0; // FIXME: m_generalOptionPage = new GdbOptionPage(&theGdbSettings()); addObject(m_generalOptionPage); - m_typeMacroPage = new TypeMacroPage(&theGdbSettings()); - addObject(m_typeMacroPage); m_locationMark = 0; diff --git a/src/plugins/debugger/debuggerplugin.h b/src/plugins/debugger/debuggerplugin.h index 91ffe4dbf77..ebf12b5e123 100644 --- a/src/plugins/debugger/debuggerplugin.h +++ b/src/plugins/debugger/debuggerplugin.h @@ -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; diff --git a/src/plugins/debugger/gdbengine.cpp b/src/plugins/debugger/gdbengine.cpp index d7ac5b1aaa1..83473674782 100644 --- a/src/plugins/debugger/gdbengine.cpp +++ b/src/plugins/debugger/gdbengine.cpp @@ -2939,6 +2939,8 @@ bool GdbEngine::isCustomValueDumperAvailable(const QString &type) const if (tmplate == "QSet") return true; } + if (tmplate == "std::list") + return true; if (tmplate == "std::vector" && inner != "bool") return true; if (tmplate == "std::basic_string") { diff --git a/src/plugins/debugger/gdbengine.h b/src/plugins/debugger/gdbengine.h index 56106a75244..6b3cbb15fee 100644 --- a/src/plugins/debugger/gdbengine.h +++ b/src/plugins/debugger/gdbengine.h @@ -80,7 +80,7 @@ enum DataDumperState DataDumperUnavailable, }; -// FIXME: Move to extra file? + class GdbSettings { public: diff --git a/src/plugins/debugger/gdboptionpage.cpp b/src/plugins/debugger/gdboptionpage.cpp index e05b811889a..7d6742e9582 100644 --- a/src/plugins/debugger/gdboptionpage.cpp +++ b/src/plugins/debugger/gdboptionpage.cpp @@ -58,7 +58,11 @@ GdbOptionPage::GdbOptionPage(GdbSettings *settings) #if defined(Q_OS_WIN32) defaultCommand.append(".exe"); #endif + QString defaultScript = coreIFace->resourcePath() + + QLatin1String("/gdb/qt4macros"); + 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.setupUi(w); - m_ui.gdbEdit->setText(m_settings->m_gdbCmd); - m_ui.envEdit->setText(m_settings->m_gdbEnv); + m_ui.gdbLocationChooser->setExpectedKind(Core::Utils::PathChooser::Command); + m_ui.gdbLocationChooser->setPromptDialogTitle(tr("Choose Gdb Location")); + m_ui.gdbLocationChooser->setPath(m_settings->m_gdbCmd); + m_ui.scriptFileChooser->setExpectedKind(Core::Utils::PathChooser::File); + m_ui.scriptFileChooser->setPromptDialogTitle(tr("Choose Location of Startup Script File")); + m_ui.scriptFileChooser->setPath(m_settings->m_scriptFile); + m_ui.environmentEdit->setText(m_settings->m_gdbEnv); m_ui.autoStartBox->setChecked(m_settings->m_autoRun); m_ui.autoQuitBox->setChecked(m_settings->m_autoQuit); - connect(m_ui.pushButtonBrowse, SIGNAL(clicked()), - this, SLOT(browse())); + + // FIXME + m_ui.autoStartBox->hide(); + m_ui.autoQuitBox->hide(); + m_ui.environmentEdit->hide(); + m_ui.labelEnvironment->hide(); + + 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()) - return; - m_settings->m_gdbCmd = fileName; - m_ui.gdbEdit->setText(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) return; - 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(); if (!coreIFace || !coreIFace->settings()) diff --git a/src/plugins/debugger/gdboptionpage.h b/src/plugins/debugger/gdboptionpage.h index 1d71024bac1..d306e03e20f 100644 --- a/src/plugins/debugger/gdboptionpage.h +++ b/src/plugins/debugger/gdboptionpage.h @@ -35,7 +35,6 @@ #define GDBOPTIONPAGE_H #include "ui_gdboptionpage.h" -#include "ui_gdbtypemacros.h" #include @@ -63,7 +62,8 @@ public: void finished(bool accepted); public slots: - void browse(); + void onGdbLocationChanged(); + void onScriptFileChanged(); private: ExtensionSystem::PluginManager *m_pm; @@ -72,6 +72,7 @@ private: GdbSettings *m_settings; }; +#if 0 class TypeMacroPage : public Core::IOptionsPage { Q_OBJECT @@ -87,7 +88,6 @@ public: void finished(bool accepted); private slots: - void onScriptButton(); void onAddButton(); void onDelButton(); void currentItemChanged(QTreeWidgetItem *item); @@ -100,6 +100,7 @@ private: GdbSettings *m_settings; QWidget *m_widget; }; +#endif } // namespace Internal } // namespace Debugger diff --git a/src/plugins/debugger/gdboptionpage.ui b/src/plugins/debugger/gdboptionpage.ui index 4b58d5d7140..580f13c0d66 100644 --- a/src/plugins/debugger/gdboptionpage.ui +++ b/src/plugins/debugger/gdboptionpage.ui @@ -7,7 +7,7 @@ 0 0 433 - 216 + 233 @@ -23,7 +23,7 @@ - Gdb Debug Options + Locations @@ -32,46 +32,45 @@ 6 - - - - - + + - + + + 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. + Gdb Location: - - gdbEdit - - + Environment: - envEdit + environmentEdit - - + + + + This is either empty or points to a file containing gdb commands that will be executed immediately after gdb starts up. + - - - - - :/qworkbench/images/fileopen.png:/qworkbench/images/fileopen.png - - - false + Gdb Startup Script: + + + + + + @@ -104,6 +103,14 @@ + + + Core::Utils::PathChooser + QWidget +
utils/pathchooser.h
+ 1 +
+
diff --git a/src/plugins/debugger/gdbtypemacros.cpp b/src/plugins/debugger/gdbtypemacros.cpp index 8610d01e39d..89178af268f 100644 --- a/src/plugins/debugger/gdbtypemacros.cpp +++ b/src/plugins/debugger/gdbtypemacros.cpp @@ -109,6 +109,8 @@ QWidget *TypeMacroPage::createPage(QWidget *parent) m_widget = new QWidget(parent); m_ui.setupUi(m_widget); + m_ui.scriptFile->setPromptDialogTitle(tr("Select Gdb Script")); + m_ui.scriptFile->setExpectedKind(Core::Utils::PathChooser::File); connect(m_ui.addButton, SIGNAL(clicked()), this, SLOT(onAddButton())); @@ -116,8 +118,8 @@ QWidget *TypeMacroPage::createPage(QWidget *parent) connect(m_ui.delButton, SIGNAL(clicked()), this, SLOT(onDelButton())); - connect(m_ui.scriptButton, SIGNAL(clicked()), - this, SLOT(onScriptButton())); + connect(m_ui.scriptFile, SIGNAL(validChanged()), + this, SLOT(updateButtonState())); connect(m_ui.treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(currentItemChanged(QTreeWidgetItem *))); @@ -139,7 +141,7 @@ QWidget *TypeMacroPage::createPage(QWidget *parent) ++i; } - m_ui.scriptEdit->setText(m_settings->m_scriptFile); + m_ui.scriptFile->setPath(m_settings->m_scriptFile); updateButtonState(); @@ -152,7 +154,7 @@ void TypeMacroPage::finished(bool accepted) return; m_settings->m_typeMacros.clear(); - m_settings->m_scriptFile = m_ui.scriptEdit->text(); + m_settings->m_scriptFile = m_ui.scriptFile->path(); for (int i = 0; i < m_ui.treeWidget->topLevelItemCount(); ++i) { QTreeWidgetItem *item = m_ui.treeWidget->topLevelItem(i); @@ -172,13 +174,6 @@ void TypeMacroPage::finished(bool accepted) } } -void TypeMacroPage::onScriptButton() -{ - QString fileName = QFileDialog::getOpenFileName(m_widget, tr("Select Gdb Script")); - m_ui.scriptEdit->setText(fileName); - updateButtonState(); -} - void TypeMacroPage::onAddButton() { if (m_ui.typeEdit->text().isEmpty() || m_ui.macroEdit->text().isEmpty()) diff --git a/src/plugins/debugger/gdbtypemacros.ui b/src/plugins/debugger/gdbtypemacros.ui index aa7215577b4..f42514e4e49 100644 --- a/src/plugins/debugger/gdbtypemacros.ui +++ b/src/plugins/debugger/gdbtypemacros.ui @@ -1,146 +1,115 @@ - - - - + + TypeMacroPage - - + + 0 0 519 - 238 + 263 - + Form - - - 9 - - + + 6 + + 9 + - - - Script File - - - - 9 - - - 6 - - - - - - - - - 21 - 23 - - - - ... - - - - - - - - - + + 0 - + 6 - - - + + + false - + Type - + Macro - - - + + + 21 23 - + + - - :/gdbdebugger/images/newitem.png + + + :/gdbdebugger/images/newitem.png:/gdbdebugger/images/newitem.png - - - + + + Macro Name: - - - + + + Parse as: - - + + - - - + + + 0 - + 0 - - + + 21 23 - + - - - :/gdbdebugger/images/delete.png + + + :/gdbdebugger/images/delete.png:/gdbdebugger/images/delete.png - + Qt::Vertical - + 20 40 @@ -150,25 +119,25 @@ - - + + - - - + + + Type: - - + + - + ASCII (char *) - + Unicode (short) @@ -178,9 +147,8 @@ - - + diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 053fcadcd19..5328a171aea 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -402,18 +402,41 @@ bool WatchHandler::setData(const QModelIndex &idx, static QString niceType(QString type) { if (type.contains("std::")) { - static QRegExp re("std::vector<(.*)\\s*,std::allocator<(.*)>\\s*>"); - re.setMinimal(true); - + // std::string type.replace("std::basic_string, " "std::allocator >", "std::string"); + + // std::wstring type.replace("std::basic_string, " "std::allocator >", "std::wstring"); + // std::vector + static QRegExp re1("std::vector<(.*), std::allocator<(.*)>\\s*>"); + re1.setMinimal(true); for (int i = 0; i != 10; ++i) { - if (re.indexIn(type) == -1 || re.cap(1) != re.cap(2)) + if (re1.indexIn(type) == -1 || re1.cap(1) != re1.cap(2)) break; - type.replace(re.cap(0), "std::vector<" + re.cap(1) + ">"); + type.replace(re1.cap(0), "std::vector<" + re1.cap(1) + ">"); + } + + // std::list + static QRegExp re2("std::list<(.*), std::allocator<(.*)>\\s*>"); + re2.setMinimal(true); + for (int i = 0; i != 10; ++i) { + if (re2.indexIn(type) == -1 || re2.cap(1) != re2.cap(2)) + break; + type.replace(re2.cap(0), "std::list<" + re2.cap(1) + ">"); + } + + // std::map + static QRegExp re3("std::map<(.*), (.*), std::less<(.*)\\s*>, " + "std::allocator > >"); + re3.setMinimal(true); + for (int i = 0; i != 10; ++i) { + if (re3.indexIn(type) == -1 || re3.cap(1) != re3.cap(3) + || re3.cap(1) != re3.cap(4) || re3.cap(2) != re3.cap(5)) + break; + type.replace(re3.cap(0), "std::map<" + re3.cap(1) + ", " + re3.cap(2) + ">"); } type.replace(" >", ">"); @@ -865,9 +888,9 @@ void WatchHandler::watchExpression(const QString &exp) data.name = exp; data.iname = "watch." + exp; insertData(data); + emit watchModelUpdateRequested(); } - void WatchHandler::setDisplayedIName(const QString &iname, bool on) { WatchData *d = findData(iname); diff --git a/src/plugins/designer/workbenchintegration.cpp b/src/plugins/designer/workbenchintegration.cpp index cc6f5afb7d6..590ff14cf6e 100644 --- a/src/plugins/designer/workbenchintegration.cpp +++ b/src/plugins/designer/workbenchintegration.cpp @@ -95,7 +95,7 @@ static QList findDocumentsIncluding(const QString &fileName, bool QList docList; // take all docs - CppTools::CppModelManagerInterface::DocumentTable docTable = cppModelManager->documents(); + CPlusPlus::Snapshot docTable = cppModelManager->snapshot(); foreach (Document::Ptr doc, docTable) { // we go through all documents QStringList includes = doc->includedFiles(); foreach (QString include, includes) { @@ -286,7 +286,7 @@ static Document::Ptr findDefinition(Function *functionDeclaration, int *line) QualifiedNameId *q = control.qualifiedNameId(&qualifiedName[0], qualifiedName.size()); LookupContext context(&control); - const QMap documents = cppModelManager->documents(); + const Snapshot documents = cppModelManager->snapshot(); foreach (Document::Ptr doc, documents) { QList visibleScopes; visibleScopes.append(doc->globalSymbols()); diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index ff0cdbde5e4..466307b4de3 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -197,7 +197,7 @@ void GitClient::diff(const QString &workingDirectory, const QStringList &fileNam const QString title = tr("Git Diff"); VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, workingDirectory, true, "originalFileName", workingDirectory); - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), editor); + executeGit(workingDirectory, arguments, editor); } @@ -215,14 +215,14 @@ void GitClient::diff(const QString &workingDirectory, const QString &fileName) const QString sourceFile = source(workingDirectory, fileName); VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, sourceFile, true, "originalFileName", sourceFile); - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), editor); + executeGit(workingDirectory, arguments, editor); } void GitClient::status(const QString &workingDirectory) { QStringList statusArgs(QLatin1String("status")); statusArgs << QLatin1String("-u"); - executeGit(workingDirectory, statusArgs, m_plugin->outputWindow(), 0,true); + executeGit(workingDirectory, statusArgs, 0, true); } void GitClient::log(const QString &workingDirectory, const QString &fileName) @@ -242,7 +242,7 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName) const QString kind = QLatin1String(Git::Constants::GIT_LOG_EDITOR_KIND); const QString sourceFile = source(workingDirectory, fileName); VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, sourceFile, false, "logFileName", sourceFile); - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), editor); + executeGit(workingDirectory, arguments, editor); } void GitClient::show(const QString &source, const QString &id) @@ -258,7 +258,7 @@ void GitClient::show(const QString &source, const QString &id) const QFileInfo sourceFi(source); const QString workDir = sourceFi.isDir() ? sourceFi.absoluteFilePath() : sourceFi.absolutePath(); - executeGit(workDir, arguments, m_plugin->outputWindow(), editor); + executeGit(workDir, arguments, editor); } void GitClient::blame(const QString &workingDirectory, const QString &fileName) @@ -273,7 +273,7 @@ void GitClient::blame(const QString &workingDirectory, const QString &fileName) const QString sourceFile = source(workingDirectory, fileName); VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, sourceFile, true, "blameFileName", sourceFile); - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), editor); + executeGit(workingDirectory, arguments, editor); } void GitClient::checkout(const QString &workingDirectory, const QString &fileName) @@ -287,7 +287,7 @@ void GitClient::checkout(const QString &workingDirectory, const QString &fileNam arguments << QLatin1String("checkout") << QLatin1String("HEAD") << QLatin1String("--") << fileName; - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), 0,true); + executeGit(workingDirectory, arguments, 0, true); } void GitClient::hardReset(const QString &workingDirectory, const QString &commit) @@ -297,7 +297,7 @@ void GitClient::hardReset(const QString &workingDirectory, const QString &commit if (!commit.isEmpty()) arguments << commit; - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), 0,true); + executeGit(workingDirectory, arguments, 0, true); } void GitClient::addFile(const QString &workingDirectory, const QString &fileName) @@ -305,7 +305,7 @@ void GitClient::addFile(const QString &workingDirectory, const QString &fileName QStringList arguments; arguments << QLatin1String("add") << fileName; - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), 0,true); + executeGit(workingDirectory, arguments, 0, true); } bool GitClient::synchronousAdd(const QString &workingDirectory, const QStringList &files) @@ -380,13 +380,14 @@ bool GitClient::synchronousCheckout(const QString &workingDirectory, } void GitClient::executeGit(const QString &workingDirectory, const QStringList &arguments, - GitOutputWindow *outputWindow, VCSBase::VCSBaseEditor* editor, + VCSBase::VCSBaseEditor* editor, bool outputToWindow) { if (Git::Constants::debug) qDebug() << "executeGit" << workingDirectory << arguments << editor; - m_plugin->outputWindow()->append(formatCommand(QLatin1String(kGitCommand), arguments)); + GitOutputWindow *outputWindow = m_plugin->outputWindow(); + outputWindow->append(formatCommand(QLatin1String(kGitCommand), arguments)); QProcess process; ProjectExplorer::Environment environment = ProjectExplorer::Environment::systemEnvironment(); @@ -396,8 +397,13 @@ void GitClient::executeGit(const QString &workingDirectory, const QStringList &a GitCommand* command = new GitCommand(); if (outputToWindow) { - connect(command, SIGNAL(outputText(QString)), outputWindow, SLOT(append(QString))); - connect(command, SIGNAL(outputData(QByteArray)), outputWindow, SLOT(appendData(QByteArray))); + if (!editor) { // assume that the commands output is the important thing + connect(command, SIGNAL(outputText(QString)), this, SLOT(appendAndPopup(QString))); + connect(command, SIGNAL(outputData(QByteArray)), this, SLOT(appendDataAndPopup(QByteArray))); + } else { + connect(command, SIGNAL(outputText(QString)), outputWindow, SLOT(append(QString))); + connect(command, SIGNAL(outputData(QByteArray)), outputWindow, SLOT(appendData(QByteArray))); + } } else { QTC_ASSERT(editor, /**/); connect(command, SIGNAL(outputText(QString)), editor, SLOT(setPlainText(QString))); @@ -405,11 +411,23 @@ void GitClient::executeGit(const QString &workingDirectory, const QStringList &a } if (outputWindow) - connect(command, SIGNAL(errorText(QString)), outputWindow, SLOT(append(QString))); + connect(command, SIGNAL(errorText(QString)), this, SLOT(appendAndPopup(QString))); command->execute(arguments, workingDirectory, environment); } +void GitClient::appendDataAndPopup(const QByteArray &data) +{ + m_plugin->outputWindow()->appendData(data); + m_plugin->outputWindow()->popup(false); +} + +void GitClient::appendAndPopup(const QString &text) +{ + m_plugin->outputWindow()->append(text); + m_plugin->outputWindow()->popup(false); +} + bool GitClient::synchronousGit(const QString &workingDirectory, const QStringList &arguments, QByteArray* outputText, @@ -810,12 +828,12 @@ void GitClient::revert(const QStringList &files) void GitClient::pull(const QString &workingDirectory) { - executeGit(workingDirectory, QStringList(QLatin1String("pull")), m_plugin->outputWindow(), 0, true); + executeGit(workingDirectory, QStringList(QLatin1String("pull")), 0, true); } void GitClient::push(const QString &workingDirectory) { - executeGit(workingDirectory, QStringList(QLatin1String("push")), m_plugin->outputWindow(), 0, true); + executeGit(workingDirectory, QStringList(QLatin1String("push")), 0, true); } QString GitClient::msgNoChangedFiles() @@ -829,7 +847,7 @@ void GitClient::stash(const QString &workingDirectory) QString errorMessage; switch (gitStatus(workingDirectory, false, 0, &errorMessage)) { case StatusChanged: - executeGit(workingDirectory, QStringList(QLatin1String("stash")), m_plugin->outputWindow(), 0, true); + executeGit(workingDirectory, QStringList(QLatin1String("stash")), 0, true); break; case StatusUnchanged: m_plugin->outputWindow()->append(msgNoChangedFiles()); @@ -846,21 +864,21 @@ void GitClient::stashPop(const QString &workingDirectory) { QStringList arguments(QLatin1String("stash")); arguments << QLatin1String("pop"); - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), 0, true); + executeGit(workingDirectory, arguments, 0, true); } void GitClient::branchList(const QString &workingDirectory) { QStringList arguments(QLatin1String("branch")); arguments << QLatin1String("-r"); - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), 0, true); + executeGit(workingDirectory, arguments, 0, true); } void GitClient::stashList(const QString &workingDirectory) { QStringList arguments(QLatin1String("stash")); arguments << QLatin1String("list"); - executeGit(workingDirectory, arguments, m_plugin->outputWindow(), 0, true); + executeGit(workingDirectory, arguments, 0, true); } QString GitClient::readConfig(const QString &workingDirectory, const QStringList &configVar) diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index efc767e5409..eb42b27efcb 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -130,6 +130,10 @@ public: public slots: void show(const QString &source, const QString &id); +private slots: + void appendAndPopup(const QString &text); + void appendDataAndPopup(const QByteArray &data); + private: VCSBase::VCSBaseEditor *createVCSEditor(const QString &kind, QString title, @@ -141,7 +145,6 @@ private: void executeGit(const QString &workingDirectory, const QStringList &arguments, - GitOutputWindow *outputWindow, VCSBase::VCSBaseEditor* editor = 0, bool outputToWindow = false); diff --git a/src/plugins/git/gitoutputwindow.cpp b/src/plugins/git/gitoutputwindow.cpp index 375be909597..fbaed2c8413 100644 --- a/src/plugins/git/gitoutputwindow.cpp +++ b/src/plugins/git/gitoutputwindow.cpp @@ -105,7 +105,6 @@ void GitOutputWindow::append(const QString &text) foreach (const QString &s, lines) m_outputListWidget->addItem(s); m_outputListWidget->scrollToBottom(); - popup(); } void GitOutputWindow::setData(const QByteArray &data) diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index d9187f542a9..f7647fb2d1a 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -496,7 +496,7 @@ QString GitPlugin::getWorkingDirectory() if (workingDirectory.isEmpty()) { m_outputWindow->clearContents(); m_outputWindow->append(tr("Could not find working directory")); - m_outputWindow->popup(); + m_outputWindow->popup(false); return QString(); } return workingDirectory; @@ -612,6 +612,7 @@ void GitPlugin::startCommit() changeTmpFile->setAutoRemove(true); if (!changeTmpFile->open()) { m_outputWindow->append(tr("Cannot create temporary file: %1").arg(changeTmpFile->errorString())); + m_outputWindow->popup(false); delete changeTmpFile; return; } diff --git a/src/plugins/git/settingspage.cpp b/src/plugins/git/settingspage.cpp index e1b14cb9ccc..7f0581fc3c3 100644 --- a/src/plugins/git/settingspage.cpp +++ b/src/plugins/git/settingspage.cpp @@ -77,7 +77,7 @@ QString SettingsPage::name() const return tr("General"); } - QString SettingsPage::category() const +QString SettingsPage::category() const { return QLatin1String("Git"); } diff --git a/src/plugins/git/settingspage.ui b/src/plugins/git/settingspage.ui index aa2337605b8..151608d03b0 100644 --- a/src/plugins/git/settingspage.ui +++ b/src/plugins/git/settingspage.ui @@ -6,114 +6,97 @@ 0 0 - 436 - 186 + 389 + 183
Form - + - - - - - true - - - Environment variables - - - true - - - - - - PATH: - - + + + true + + + Environment variables + + + true + + + + + + PATH: + + + + + + + - - - - - - - - - From system - - - - - - - + + - <b>Note:</b> - - - - - - - Git needs to find Perl in the environment as well. + From system + + + + + <b>Note:</b> + + + + + + + Git needs to find Perl in the environment as well. + + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Note that huge amount of commits might take some time. + + + 1000 + - - - - QFormLayout::ExpandingFieldsGrow + + + + Log commit display count: - - - - Note that huge amount of commits might take some time. - - - 1000 - - - - - - - Log commit display count: - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - + - + - Qt::Horizontal + Qt::Vertical - 40 - 20 + 20 + 40 diff --git a/src/plugins/projectexplorer/projectmodels.cpp b/src/plugins/projectexplorer/projectmodels.cpp index e5a2e702650..de4f851e5ce 100644 --- a/src/plugins/projectexplorer/projectmodels.cpp +++ b/src/plugins/projectexplorer/projectmodels.cpp @@ -626,7 +626,7 @@ QList DetailedModel::recursiveSubFolders(FolderNode *parentFolder) FlatModel::FlatModel(SessionNode *rootNode, QObject *parent) : QAbstractItemModel(parent), - m_filterProjects(true), + m_filterProjects(false), m_filterGeneratedFiles(true), m_rootNode(rootNode), m_startupProject(0), @@ -914,6 +914,8 @@ QModelIndex FlatModel::indexForNode(const Node *node_) void FlatModel::setProjectFilterEnabled(bool filter) { + if (filter == m_filterProjects) + return; m_filterProjects = filter; reset(); } diff --git a/src/plugins/projectexplorer/projecttreewidget.cpp b/src/plugins/projectexplorer/projecttreewidget.cpp index 6285bb81dee..c2197a2dc7c 100644 --- a/src/plugins/projectexplorer/projecttreewidget.cpp +++ b/src/plugins/projectexplorer/projecttreewidget.cpp @@ -90,6 +90,20 @@ protected: if (event->reason() != Qt::PopupFocusReason) QTreeView::focusOutEvent(event); } + +#ifdef Q_OS_MAC + void keyPressEvent(QKeyEvent *event) + { + if ((event->key() == Qt::Key_Return + || event->key() == Qt::Key_Enter) + && event->modifiers() == 0 + && currentIndex().isValid()) { + emit activated(currentIndex()); + return; + } + QTreeView::keyPressEvent(event); + } +#endif }; /*! diff --git a/src/plugins/projectexplorer/projectwindow.cpp b/src/plugins/projectexplorer/projectwindow.cpp index c725c915c9e..e6732387424 100644 --- a/src/plugins/projectexplorer/projectwindow.cpp +++ b/src/plugins/projectexplorer/projectwindow.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -190,7 +191,14 @@ void ProjectWindow::updateTreeWidget() // That one runs fully thorough and deletes all widgets, even that one that we are currently removing // from m_panelsTabWidget. // To prevent that, we simply prevent the focus switching.... - m_treeWidget->setFocus(); + QWidget *focusWidget = qApp->focusWidget(); + while (focusWidget) { + if (focusWidget == this) { + m_treeWidget->setFocus(); + break; + } + focusWidget = focusWidget->parentWidget(); + } m_treeWidget->clear(); foreach(Project *project, m_session->projects()) { diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index a9bded02c61..89716ce3f68 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -628,8 +628,10 @@ bool SessionManager::loadImpl(const QString &fileName) if (success) { // restore the active mode const QString &modeIdentifier = value(QLatin1String("ActiveMode")).toString(); - if (!modeIdentifier.isEmpty()) + if (!modeIdentifier.isEmpty()) { m_core->modeManager()->activateMode(modeIdentifier); + m_core->modeManager()->setFocusToCurrentMode(); + } } if (debug) diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp index c9263201937..9e47ac404d2 100644 --- a/src/plugins/qt4projectmanager/qt4project.cpp +++ b/src/plugins/qt4projectmanager/qt4project.cpp @@ -498,12 +498,8 @@ void Qt4Project::updateCodeModel() pinfo.sourceFiles = files; modelmanager->updateProjectInfo(pinfo); - - modelmanager->GC(); modelmanager->updateSourceFiles(pinfo.sourceFiles); } - - // update info } diff --git a/src/plugins/quickopen/filesystemfilter.cpp b/src/plugins/quickopen/filesystemfilter.cpp index 8265f6a07ef..386523ebc43 100644 --- a/src/plugins/quickopen/filesystemfilter.cpp +++ b/src/plugins/quickopen/filesystemfilter.cpp @@ -54,14 +54,7 @@ QList FileSystemFilter::matchesFor(const QString &entry) QString name = entryInfo.fileName(); QString directory = entryInfo.path(); QString filePath = entryInfo.filePath(); - bool isDrive = false; - foreach (const QFileInfo &drive, QDir::drives()) { - if (filePath.startsWith(drive.path())) { - isDrive = true; - break; - } - } - if (!isDrive) { + if (entryInfo.isRelative()) { if (filePath.startsWith("~/")) { directory.replace(0, 1, QDir::homePath()); } else { diff --git a/src/plugins/quickopen/opendocumentsfilter.h b/src/plugins/quickopen/opendocumentsfilter.h index 7b24aeeca02..6957119727e 100644 --- a/src/plugins/quickopen/opendocumentsfilter.h +++ b/src/plugins/quickopen/opendocumentsfilter.h @@ -54,8 +54,8 @@ class OpenDocumentsFilter : public QuickOpen::IQuickOpenFilter public: OpenDocumentsFilter(Core::EditorManager *editorManager); - QString trName() const { return tr("Open document"); } - QString name() const { return "Open document"; } + QString trName() const { return tr("Open documents"); } + QString name() const { return "Open documents"; } QuickOpen::IQuickOpenFilter::Priority priority() const { return QuickOpen::IQuickOpenFilter::Medium; } QList matchesFor(const QString &entry); void accept(QuickOpen::FilterEntry selection) const; diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index db5413c3446..1cff254452c 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -128,12 +128,13 @@ protected: ITextEditor *BaseTextEditor::openEditorAt(const QString &fileName, int line, - int column) + int column, + const QString &editorKind) { Core::EditorManager *editorManager = ExtensionSystem::PluginManager::instance()->getObject()->editorManager(); editorManager->addCurrentPositionToNavigationHistory(true); - Core::IEditor *editor = editorManager->openEditor(fileName, QString(), true); + Core::IEditor *editor = editorManager->openEditor(fileName, editorKind, true); TextEditor::ITextEditor *texteditor = qobject_cast(editor); if (texteditor) { texteditor->gotoLine(line, column); @@ -684,6 +685,67 @@ void BaseTextEditor::selectBlockDown() _q_matchParentheses(); } +void BaseTextEditor::moveLineUp() +{ + moveLineUpDown(true); +} + +void BaseTextEditor::moveLineDown() +{ + moveLineUpDown(false); +} + +void BaseTextEditor::moveLineUpDown(bool up) +{ + QTextCursor cursor = textCursor(); + QTextCursor move = cursor; + move.beginEditBlock(); + + bool hasSelection = cursor.hasSelection(); + + if (cursor.hasSelection()) { + move.setPosition(cursor.selectionStart()); + move.movePosition(QTextCursor::StartOfBlock); + move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor); + move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + } else { + move.movePosition(QTextCursor::StartOfBlock); + move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + } + QString text = move.selectedText(); + move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); + move.removeSelectedText(); + + if (up) { + move.movePosition(QTextCursor::PreviousBlock); + move.insertBlock(); + move.movePosition(QTextCursor::Left); + } else { + move.movePosition(QTextCursor::EndOfBlock); + if (move.atBlockStart()) { // empty block + move.movePosition(QTextCursor::NextBlock); + move.insertBlock(); + move.movePosition(QTextCursor::Left); + } else { + move.insertBlock(); + } + } + + int start = move.position(); + move.clearSelection(); + move.insertText(text); + int end = move.position(); + + if (hasSelection) { + move.setPosition(start); + move.setPosition(end, QTextCursor::KeepAnchor); + } + + indent(document(), move, QChar::Null); + move.endEditBlock(); + + setTextCursor(move); +} void BaseTextEditor::cleanWhitespace() { @@ -740,9 +802,13 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) QTextCursor cursor = textCursor(); if (d->m_inBlockSelectionMode) cursor.clearSelection(); - cursor.insertBlock(); if (d->m_document->tabSettings().m_autoIndent) { + cursor.beginEditBlock(); + cursor.insertBlock(); indent(document(), cursor, QChar::Null); + cursor.endEditBlock(); + } else { + cursor.insertBlock(); } e->accept(); setTextCursor(cursor); @@ -2451,7 +2517,7 @@ void BaseTextEditor::extraAreaMouseEvent(QMouseEvent *e) } } else if (e->button() == Qt::RightButton) { QMenu * contextMenu = new QMenu(this); - emit d->m_editable->markContextMenuRequested(editableInterface(), cursor.blockNumber(), contextMenu); + emit d->m_editable->markContextMenuRequested(editableInterface(), cursor.blockNumber() + 1, contextMenu); if (!contextMenu->isEmpty()) contextMenu->exec(e->globalPos()); delete contextMenu; @@ -2702,6 +2768,8 @@ void BaseTextEditor::handleHomeKey(bool anchor) while (character == tab || character.category() == QChar::Separator_Space) { ++pos; + if (pos == initpos) + break; character = characterAt(pos); } @@ -2889,12 +2957,13 @@ void BaseTextEditor::markBlocksAsChanged(QList blockNumbers) { TextBlockUserData::MatchType TextBlockUserData::checkOpenParenthesis(QTextCursor *cursor, QChar c) { - if (!TextEditDocumentLayout::hasParentheses(cursor->block())) + QTextBlock block = cursor->block(); + if (!TextEditDocumentLayout::hasParentheses(block) || TextEditDocumentLayout::ifdefedOut(block)) return NoMatch; - Parentheses parenList = TextEditDocumentLayout::parentheses(cursor->block()); + Parentheses parenList = TextEditDocumentLayout::parentheses(block); Parenthesis openParen, closedParen; - QTextBlock closedParenParag = cursor->block(); + QTextBlock closedParenParag = block; const int cursorPos = cursor->position() - closedParenParag.position(); int i = 0; @@ -2919,7 +2988,8 @@ TextBlockUserData::MatchType TextBlockUserData::checkOpenParenthesis(QTextCursor closedParenParag = closedParenParag.next(); if (!closedParenParag.isValid()) return NoMatch; - if (TextEditDocumentLayout::hasParentheses(closedParenParag)) { + if (TextEditDocumentLayout::hasParentheses(closedParenParag) + && !TextEditDocumentLayout::ifdefedOut(closedParenParag)) { parenList = TextEditDocumentLayout::parentheses(closedParenParag); break; } @@ -2956,12 +3026,13 @@ TextBlockUserData::MatchType TextBlockUserData::checkOpenParenthesis(QTextCursor TextBlockUserData::MatchType TextBlockUserData::checkClosedParenthesis(QTextCursor *cursor, QChar c) { - if (!TextEditDocumentLayout::hasParentheses(cursor->block())) + QTextBlock block = cursor->block(); + if (!TextEditDocumentLayout::hasParentheses(block) || TextEditDocumentLayout::ifdefedOut(block)) return NoMatch; - Parentheses parenList = TextEditDocumentLayout::parentheses(cursor->block()); + Parentheses parenList = TextEditDocumentLayout::parentheses(block); Parenthesis openParen, closedParen; - QTextBlock openParenParag = cursor->block(); + QTextBlock openParenParag = block; const int cursorPos = cursor->position() - openParenParag.position(); int i = parenList.count() - 1; @@ -2987,7 +3058,8 @@ TextBlockUserData::MatchType TextBlockUserData::checkClosedParenthesis(QTextCurs if (!openParenParag.isValid()) return NoMatch; - if (TextEditDocumentLayout::hasParentheses(openParenParag)) { + if (TextEditDocumentLayout::hasParentheses(openParenParag) + && !TextEditDocumentLayout::ifdefedOut(openParenParag)) { parenList = TextEditDocumentLayout::parentheses(openParenParag); break; } @@ -3029,7 +3101,7 @@ bool TextBlockUserData::findPreviousOpenParenthesis(QTextCursor *cursor, bool se int ignore = 0; while (block.isValid()) { Parentheses parenList = TextEditDocumentLayout::parentheses(block); - if (!parenList.isEmpty()) { + if (!parenList.isEmpty() && !TextEditDocumentLayout::ifdefedOut(block)) { for (int i = parenList.count()-1; i >= 0; --i) { Parenthesis paren = parenList.at(i); if (block == cursor->block() && position - block.position() <= paren.pos + 1) @@ -3056,7 +3128,7 @@ bool TextBlockUserData::findNextClosingParenthesis(QTextCursor *cursor, bool sel int ignore = 0; while (block.isValid()) { Parentheses parenList = TextEditDocumentLayout::parentheses(block); - if (!parenList.isEmpty()) { + if (!parenList.isEmpty() && !TextEditDocumentLayout::ifdefedOut(block)) { for (int i = 0; i < parenList.count(); ++i) { Parenthesis paren = parenList.at(i); if (block == cursor->block() && position - block.position() >= paren.pos) @@ -3081,7 +3153,7 @@ TextBlockUserData::MatchType TextBlockUserData::matchCursorBackward(QTextCursor cursor->clearSelection(); const QTextBlock block = cursor->block(); - if (!TextEditDocumentLayout::hasParentheses(block)) + if (!TextEditDocumentLayout::hasParentheses(block) || TextEditDocumentLayout::ifdefedOut(block)) return NoMatch; const int relPos = cursor->position() - block.position(); @@ -3103,7 +3175,7 @@ TextBlockUserData::MatchType TextBlockUserData::matchCursorForward(QTextCursor * cursor->clearSelection(); const QTextBlock block = cursor->block(); - if (!TextEditDocumentLayout::hasParentheses(block)) + if (!TextEditDocumentLayout::hasParentheses(block) || TextEditDocumentLayout::ifdefedOut(block)) return NoMatch; const int relPos = cursor->position() - block.position(); @@ -3314,7 +3386,7 @@ void BaseTextEditorPrivate::moveCursorVisible() if (!cursor.block().isVisible()) { cursor.setVisualNavigation(true); cursor.movePosition(QTextCursor::PreviousBlock); - q->setTextCursor(cursor); + q->setTextCursor(cursor); } q->ensureCursorVisible(); } diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 1219439fc98..d75e174fea2 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -230,7 +230,8 @@ public: BaseTextEditor(QWidget *parent); ~BaseTextEditor(); - static ITextEditor *openEditorAt(const QString &fileName, int line, int column = 0); + static ITextEditor *openEditorAt(const QString &fileName, int line, int column = 0, + const QString &editorKind = QString()); // EditorInterface Core::IFile * file(); @@ -329,6 +330,9 @@ public slots: void selectBlockUp(); void selectBlockDown(); + void moveLineUp(); + void moveLineDown(); + void cleanWhitespace(); signals: @@ -447,6 +451,7 @@ private: void indentOrUnindent(bool doIndent); void handleHomeKey(bool anchor); void handleBackspaceKey(); + void moveLineUpDown(bool up); void toggleBlockVisible(const QTextBlock &block); QRect collapseBox(const QTextBlock &block); diff --git a/src/plugins/texteditor/generalsettingspage.ui b/src/plugins/texteditor/generalsettingspage.ui index 11f6b8b997e..140f94628d6 100644 --- a/src/plugins/texteditor/generalsettingspage.ui +++ b/src/plugins/texteditor/generalsettingspage.ui @@ -66,6 +66,9 @@ 0 + + 1 + 20 @@ -132,6 +135,9 @@ 0 + + 1 + 20 diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index 12fc7d1fac5..39a12ee93fd 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -71,6 +71,7 @@ TextEditorActionHandler::TextEditorActionHandler(Core::ICore *core, = m_gotoBlockStartAction = m_gotoBlockStartWithSelectionAction = m_gotoBlockEndAction = m_gotoBlockEndWithSelectionAction = m_selectBlockUpAction = m_selectBlockDownAction + = m_moveLineUpAction = m_moveLineDownAction = 0; m_contextId << m_core->uniqueIDManager()->uniqueIdentifier(context); @@ -223,6 +224,16 @@ void TextEditorActionHandler::createActions() command = am->registerAction(m_selectBlockDownAction, Constants::SELECT_BLOCK_DOWN, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U"))); connect(m_selectBlockDownAction, SIGNAL(triggered()), this, SLOT(selectBlockDown())); + + m_moveLineUpAction= new QAction(tr("Move Line Up"), this); + command = am->registerAction(m_moveLineUpAction, Constants::MOVE_LINE_UP, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Up"))); + connect(m_moveLineUpAction, SIGNAL(triggered()), this, SLOT(moveLineUp())); + + m_moveLineDownAction= new QAction(tr("Move Line Down"), this); + command = am->registerAction(m_moveLineDownAction, Constants::MOVE_LINE_DOWN, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Down"))); + connect(m_moveLineDownAction, SIGNAL(triggered()), this, SLOT(moveLineDown())); } bool TextEditorActionHandler::supportsAction(const QString & /*id */) const @@ -287,6 +298,8 @@ void TextEditorActionHandler::updateActions(UpdateMode um) m_gotoBlockEndWithSelectionAction->setEnabled(um != NoEditor); m_selectBlockUpAction->setEnabled(um != NoEditor); m_selectBlockDownAction->setEnabled(um != NoEditor); + m_moveLineUpAction->setEnabled(um != NoEditor); + m_moveLineDownAction->setEnabled(um != NoEditor); m_visualizeWhitespaceAction->setEnabled(um != NoEditor); if (m_currentEditor) @@ -390,6 +403,8 @@ FUNCTION(gotoBlockStartWithSelection) FUNCTION(gotoBlockEndWithSelection) FUNCTION(selectBlockUp) FUNCTION(selectBlockDown) +FUNCTION(moveLineUp) +FUNCTION(moveLineDown) void TextEditorActionHandler::updateCurrentEditor(Core::IContext *object) { diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h index 520ae26ddf6..98e8c9198a9 100644 --- a/src/plugins/texteditor/texteditoractionhandler.h +++ b/src/plugins/texteditor/texteditoractionhandler.h @@ -116,6 +116,8 @@ private slots: void gotoBlockEndWithSelection(); void selectBlockUp(); void selectBlockDown(); + void moveLineUp(); + void moveLineDown(); void updateCurrentEditor(Core::IContext *object); private: @@ -145,6 +147,8 @@ private: QAction *m_gotoBlockEndWithSelectionAction; QAction *m_selectBlockUpAction; QAction *m_selectBlockDownAction; + QAction *m_moveLineUpAction; + QAction *m_moveLineDownAction; uint m_optionalActions; QPointer m_currentEditor; diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 192a07c257e..d9147a9a9e9 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -55,6 +55,8 @@ const char * const GOTO_BLOCK_END = "TextEditor.GotoBlockEnd"; const char * const GOTO_BLOCK_END_WITH_SELECTION = "TextEditor.GotoBlockEndWithSelection"; const char * const SELECT_BLOCK_UP = "TextEditor.SelectBlockUp"; const char * const SELECT_BLOCK_DOWN = "TextEditor.SelectBlockDown"; +const char * const MOVE_LINE_UP = "TextEditor.MoveLineUp"; +const char * const MOVE_LINE_DOWN = "TextEditor.MoveLineDown"; const char * const DELETE_LINE = "TextEditor.DeleteLine"; const char * const DELETE_WORD = "TextEditor.DeleteWord"; const char * const SELECT_ENCODING = "TextEditor.SelectEncoding"; diff --git a/tests/manual/gdbdebugger/simple/app.cpp b/tests/manual/gdbdebugger/simple/app.cpp index 958c8985b05..ab5ee635b5a 100644 --- a/tests/manual/gdbdebugger/simple/app.cpp +++ b/tests/manual/gdbdebugger/simple/app.cpp @@ -53,6 +53,9 @@ #include #include +#include +#include +#include #include #include @@ -71,6 +74,9 @@ uint qHash(const double & f) return int(f); } +#define X myns +X::QString str; + class Foo { public: @@ -126,8 +132,7 @@ void testArray() } } - -void testByteArray() +void testQByteArray() { QByteArray ba = "Hello"; ba += '"'; @@ -137,8 +142,7 @@ void testByteArray() ba += 2; } - -void testHash() +void testQHash() { QHash hgg0; hgg0[11] = 11.0; @@ -162,7 +166,7 @@ void testHash() hash.insert(".", QPointer(&ob)); } -void testImage() +void testQImage() { QImage im(QSize(200, 200), QImage::Format_RGB32); im.fill(QColor(200, 100, 130).rgba()); @@ -190,7 +194,7 @@ void testIO() } -void testList() +void testQList() { #if 1 QList li; @@ -252,7 +256,7 @@ void testList() v.push_back("dd"); } -void testMap() +void testQMap() { QMap ggl; ggl[11] = QStringList() << "11"; @@ -287,7 +291,7 @@ void testMap() #endif } -void testObject(int &argc, char *argv[]) +void testQObject(int &argc, char *argv[]) { QApplication app(argc, argv); QAction act("xxx", &app); @@ -315,7 +319,7 @@ void testObject(int &argc, char *argv[]) app.exec(); } -void testPixmap() +void testQPixmap() { QImage im(QSize(200, 200), QImage::Format_RGB32); im.fill(QColor(200, 100, 130).rgba()); @@ -351,7 +355,7 @@ void testPlugin() } } -void testSet() +void testQSet() { QSet hgg0; hgg0.insert(11); @@ -373,65 +377,98 @@ void stringRefTest(const QString &refstring) Q_UNUSED(refstring); } - -int F(int a, int b) +void testStdList() { - return a + b; -} - -int add(int i) { return i + 2; } - -int mul(int i) { return i * 2; } - - -void testStdVector() -{ - int x = F(add(1), mul(2)); - Q_UNUSED(x); - std::vector plist1; + std::list plist1; plist1.push_back(new int(1)); plist1.push_back(0); plist1.push_back(new int(2)); - std::vector flist2; + std::list flist2; flist2.push_back(1); flist2.push_back(2); flist2.push_back(3); flist2.push_back(4); - int a = 1; - int b = 0; - - while (0) { - a += 1; - if (b) - break; - } - flist2.push_back(1); flist2.push_back(2); flist2.push_back(3); flist2.push_back(4); - std::vector plist; + std::list plist; plist.push_back(new Foo(1)); plist.push_back(0); plist.push_back(new Foo(2)); - std::vector flist; + std::list flist; flist.push_back(1); - flist.push_back(2); flist.push_back(3); flist.push_back(4); - //flist.takeFirst(); - //flist.takeFirst(); - std::vector vec; + std::list vec; vec.push_back(true); vec.push_back(false); } +void testStdMap() +{ + std::map ggl; + ggl[11] = QStringList() << "11"; + ggl[22] = QStringList() << "22"; + + typedef std::map T; + T ggt; + ggt[11] = QStringList() << "11"; + ggt[22] = QStringList() << "22"; + +#if 0 + std::map gg0; + gg0[11] = 11.0; + gg0[22] = 22.0; + + + std::map gg1; + gg1["22.0"] = 22.0; + + std::map gg2; + gg2[22] = "22.0"; + + std::map gg3; + gg3["22.0"] = Foo(22); + gg3["33.0"] = Foo(33); + + QObject ob; + std::map > map; + map.insert("Hallo", QPointer(&ob)); + map.insert("Welt", QPointer(&ob)); + map.insert(".", QPointer(&ob)); +#endif +} + +void testStdStack() +{ + std::stack plist1; + plist1.push(new int(1)); + plist1.push(0); + plist1.push(new int(2)); + plist1.pop(); + plist1.pop(); + plist1.pop(); + + std::stack flist2; + flist2.push(1); + flist2.push(2); + + std::stack plist; + plist.push(new Foo(1)); + plist.push(new Foo(2)); + + std::stack flist; + flist.push(1); + flist.push(2); +} + void testStdString() { QString foo; @@ -470,7 +507,43 @@ void testStdString() v.push_back(str); } -void testString() +void testStdVector() +{ + std::vector plist1; + plist1.push_back(new int(1)); + plist1.push_back(0); + plist1.push_back(new int(2)); + + std::vector flist2; + flist2.push_back(1); + flist2.push_back(2); + flist2.push_back(3); + flist2.push_back(4); + + flist2.push_back(1); + flist2.push_back(2); + flist2.push_back(3); + flist2.push_back(4); + + std::vector plist; + plist.push_back(new Foo(1)); + plist.push_back(0); + plist.push_back(new Foo(2)); + + std::vector flist; + flist.push_back(1); + flist.push_back(2); + flist.push_back(3); + flist.push_back(4); + //flist.takeFirst(); + //flist.takeFirst(); + + std::vector vec; + vec.push_back(true); + vec.push_back(false); +} + +void testQString() { QString str = "Hello "; str += " big, "; @@ -480,19 +553,9 @@ void testString() str += " World "; str += " World "; str += " World "; - str += " World "; - str += " World "; - str += " World "; - str += " World "; - str += " World "; - str += " World "; - str += " World "; - str += " World "; - str += " World "; - str += " World "; } -void testString3() +void testQString3() { QString str = "Hello "; str += " big, "; @@ -508,7 +571,7 @@ void testString3() delete pstring; } -void testStringList() +void testQStringList() { QStringList l; l << "Hello "; @@ -542,7 +605,7 @@ private: int m_id; }; -void testThreads() +void testQThread() { Thread thread1(1); Thread thread2(2); @@ -552,7 +615,7 @@ void testThreads() thread2.wait(); } -void testVariant1() +void testQVariant1() { QVariant v; v = 1; @@ -561,7 +624,7 @@ void testVariant1() v = 1; } -void testVariant2() +void testQVariant2() { QVariant var; #if 0 @@ -586,7 +649,7 @@ void testVariant2() var.setValue(my); } -void testVariant3() +void testQVariant3() { QList list; list << 1 << 2 << 3; @@ -595,8 +658,10 @@ void testVariant3() list = qVariantValue >(variant); } -void testVector() +void testQVector() { + QVector big(10000); + QVector plist; plist.append(new Foo(1)); plist.append(0); @@ -616,7 +681,7 @@ void testVector() vec.append(false); } -void testVectorOfList() +void testQVectorOfQList() { QVector > v; QVector > *pv = &v; @@ -729,16 +794,9 @@ void testNamespace() bar.doit(1); } -int main(int argc, char *argv[]) + +void testHidden() { - testIO(); - //QString s; - //s = "hallo"; - //QList *> vi; - //QList *> vd; - //int n = A::barz(); - - int n = 1; n = 2; n = 3; @@ -762,34 +820,43 @@ int main(int argc, char *argv[]) } ++n; ++n; +} +int main(int argc, char *argv[]) +{ + //testIO(); + testHidden(); testArray(); - testStdVector(); + + testStdList(); + testStdMap(); + testStdStack(); testStdString(); + testStdVector(); testPlugin(); - testList(); + testQList(); testNamespace(); //return 0; - testByteArray(); - testHash(); - testImage(); - testMap(); - testString(); - testSet(); - testStringList(); + testQByteArray(); + testQHash(); + testQImage(); + testQMap(); + testQString(); + testQSet(); + testQStringList(); testStruct(); //testThreads(); - testVariant1(); - testVariant2(); - testVariant3(); - testVector(); - testVectorOfList(); + testQVariant1(); + testQVariant2(); + testQVariant3(); + testQVector(); + testQVectorOfQList(); *(int *)0 = 0; - testObject(argc, argv); + testQObject(argc, argv); //QColor color(255,128,10);