| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
// IMPORTANT!!!! If you want to add testdata to this file, |
| 30 |
// always add it to the end in order to not change the linenumbers of translations!!! |
| 31 |
#include <QtCore> |
| 32 |
#include <QtGui> |
| 33 |
#include <QtWidgets/QMainWindow> |
| 34 |
// |
| 35 |
// Test namespace scoping |
| 36 |
// |
| 37 |
|
| 38 |
class D : public QObject { |
| 39 |
Q_OBJECT |
| 40 |
public: |
| 41 |
QString foo() { |
| 42 |
return tr("test", "D"); |
| 43 |
} |
| 44 |
|
| 45 |
}; |
| 46 |
|
| 47 |
namespace A { |
| 48 |
|
| 49 |
class C : public QObject { |
| 50 |
Q_OBJECT |
| 51 |
public: |
| 52 |
void foo(); |
| 53 |
}; |
| 54 |
|
| 55 |
void C::foo() { |
| 56 |
tr("Bla", "A::C"); |
| 57 |
} |
| 58 |
|
| 59 |
void goo() { |
| 60 |
C::tr("Bla", "A::C"); // Is identical to the previous tr(), (same context, sourcetext and comment, |
| 61 |
// so it should not add another entry to the list of messages) |
| 62 |
} |
| 63 |
|
| 64 |
void goo2() { |
| 65 |
C::tr("Bla 2", "A::C"); //Should be in the same namespace as the previous tr() |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
namespace X { |
| 72 |
|
| 73 |
class D : public QObject { |
| 74 |
Q_OBJECT |
| 75 |
public: |
| 76 |
|
| 77 |
}; |
| 78 |
|
| 79 |
class E : public QObject { |
| 80 |
Q_OBJECT |
| 81 |
public: |
| 82 |
void foo() { D::tr("foo", "D"); } // Note that this is X::D from 440 on |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
namespace Y { |
| 87 |
class E : public QObject { |
| 88 |
Q_OBJECT |
| 89 |
|
| 90 |
}; |
| 91 |
|
| 92 |
class C : public QObject { |
| 93 |
Q_OBJECT |
| 94 |
void foo(); |
| 95 |
}; |
| 96 |
|
| 97 |
void C::foo() { |
| 98 |
tr("Bla", "X::Y::C"); |
| 99 |
} |
| 100 |
|
| 101 |
void goo() { |
| 102 |
D::tr("Bla", "X::D"); //This should be assigned to the X::D context |
| 103 |
} |
| 104 |
|
| 105 |
void goo2() { |
| 106 |
E::tr("Bla", "X::Y::E"); //This should be assigned to the X::Y::E context |
| 107 |
Y::E::tr("Bla", "X::Y::E"); //This should be assigned to the X::Y::E context |
| 108 |
} |
| 109 |
|
| 110 |
}; // namespace Y |
| 111 |
|
| 112 |
class F : public QObject { |
| 113 |
Q_OBJECT |
| 114 |
inline void inlinefunc() { |
| 115 |
tr("inline function", "X::F"); |
| 116 |
} |
| 117 |
}; |
| 118 |
} // namespace X |
| 119 |
|
| 120 |
namespace ico { |
| 121 |
namespace foo { |
| 122 |
class A : public QObject { |
| 123 |
A(); |
| 124 |
}; |
| 125 |
|
| 126 |
A::A() { |
| 127 |
tr("myfoo", "ico::foo::A"); |
| 128 |
QObject::tr("task 161186", "QObject"); |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
namespace AA { |
| 134 |
class C {}; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* the context of a message should not be affected by any inherited classes |
| 139 |
* |
| 140 |
* Keep this disabled for now, but at a long-term range it should work. |
| 141 |
*/ |
| 142 |
namespace Gui { |
| 143 |
class MainWindow : public QMainWindow, |
| 144 |
public AA::C |
| 145 |
{ |
| 146 |
Q_OBJECT |
| 147 |
public: |
| 148 |
MainWindow() |
| 149 |
{ |
| 150 |
tr("More bla", "Gui::MainWindow"); |
| 151 |
} |
| 152 |
|
| 153 |
}; |
| 154 |
} //namespace Gui |
| 155 |
|
| 156 |
|
| 157 |
namespace A1 { |
| 158 |
class AB : public QObject { |
| 159 |
Q_OBJECT |
| 160 |
public: |
| 161 |
|
| 162 |
friend class OtherClass; |
| 163 |
|
| 164 |
QString inlineFuncAfterFriendDeclaration() const { |
| 165 |
return tr("inlineFuncAfterFriendDeclaration", "A1::AB"); |
| 166 |
} |
| 167 |
}; |
| 168 |
class B : AB { |
| 169 |
Q_OBJECT |
| 170 |
public: |
| 171 |
QString foo() const { return tr("foo", "A1::B"); } |
| 172 |
}; |
| 173 |
|
| 174 |
// This is valid C++ too.... |
| 175 |
class V : virtual AB { |
| 176 |
Q_OBJECT |
| 177 |
public: |
| 178 |
QString bar() const { return tr("bar", "A1::V"); } |
| 179 |
}; |
| 180 |
|
| 181 |
class W : virtual public AB { |
| 182 |
Q_OBJECT |
| 183 |
public: |
| 184 |
QString baz() const { return tr("baz", "A1::W"); } |
| 185 |
}; |
| 186 |
} |
| 187 |
|
| 188 |
class ForwardDecl; |
| 189 |
|
| 190 |
|
| 191 |
class B1 : public QObject { |
| 192 |
}; |
| 193 |
|
| 194 |
class C1 : public QObject { |
| 195 |
}; |
| 196 |
|
| 197 |
namespace A1 { |
| 198 |
|
| 199 |
class B2 : public QObject { |
| 200 |
}; |
| 201 |
|
| 202 |
} |
| 203 |
|
| 204 |
void func1() |
| 205 |
{ |
| 206 |
B1::tr("test TRANSLATOR comment (1)", "B1"); |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
using namespace A1; |
| 211 |
/* |
| 212 |
TRANSLATOR A1::B2 |
| 213 |
*/ |
| 214 |
void func2() |
| 215 |
{ |
| 216 |
B2::tr("test TRANSLATOR comment (2)", "A1::B2"); |
| 217 |
C1::tr("test TRANSLATOR comment (3)", "C1"); |
| 218 |
} |
| 219 |
|
| 220 |
void func3() |
| 221 |
{ |
| 222 |
B2::tr("test TRANSLATOR comment (4)", "A1::B2"); |
| 223 |
} |
| 224 |
|
| 225 |
/* |
| 226 |
TRANSLATOR B2 |
| 227 |
This is a comment to the translator. |
| 228 |
*/ |
| 229 |
void func4() |
| 230 |
{ |
| 231 |
B2::tr("test TRANSLATOR comment (5)", "A1::B2"); |
| 232 |
} |
| 233 |
|
| 234 |
namespace A1 { |
| 235 |
namespace B3 { |
| 236 |
class C2 : public QObject { |
| 237 |
QString foo(); |
| 238 |
}; |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
namespace D1 = A1::B3; |
| 243 |
using namespace D1; |
| 244 |
|
| 245 |
// TRANSLATOR A1::B3::C2 |
| 246 |
QString C2::foo() |
| 247 |
{ |
| 248 |
return tr("test TRANSLATOR comment (6)", "A1::B3::C2"); // 4.4 screws up |
| 249 |
} |
| 250 |
namespace Fooish { |
| 251 |
struct toto { |
| 252 |
Q_DECLARE_TR_FUNCTIONS(Bears::And::Spiders) |
| 253 |
QString bar(); }; |
| 254 |
} |
| 255 |
|
| 256 |
QString Fooish::toto::bar() |
| 257 |
{ |
| 258 |
return tr("whatever the context", "Bears::And::Spiders"); |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
int main(int /*argc*/, char ** /*argv*/) { |
| 263 |
return 0; |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
// QTBUG-140636: Return type vs method qualification disambiguation |
| 268 |
// Types from <external_types.h> use angle brackets, so lupdate looks for them in the |
| 269 |
// configured paths (and not the relative locations), and if not found, they are not qualified. |
| 270 |
// Without the fix, these produce: "Qualifying with unknown namespace/class ::Namespace" |
| 271 |
#include <external_types.h> |
| 272 |
|
| 273 |
// Basic namespaced return type |
| 274 |
class TestClass1_Widget : public QObject { |
| 275 |
Q_OBJECT |
| 276 |
}; |
| 277 |
|
| 278 |
Tasking::GroupItem testFunction1() |
| 279 |
{ |
| 280 |
TestClass1_Widget::tr("test1: basic return type"); |
| 281 |
} |
| 282 |
|
| 283 |
// Deeply nested return type |
| 284 |
namespace MyNS { |
| 285 |
class TestClass2 : public QObject { |
| 286 |
Q_OBJECT |
| 287 |
public: |
| 288 |
External::Deeply::Nested::Type method(); |
| 289 |
}; |
| 290 |
} |
| 291 |
|
| 292 |
External::Deeply::Nested::Type MyNS::TestClass2::method() |
| 293 |
{ |
| 294 |
tr("test2: nested return type"); |
| 295 |
return {}; |
| 296 |
} |
| 297 |
|
| 298 |
// Trailing return type syntax |
| 299 |
class TestClass3 : public QObject { |
| 300 |
Q_OBJECT |
| 301 |
public: |
| 302 |
auto method() -> UndefinedNS::RetType; |
| 303 |
}; |
| 304 |
|
| 305 |
auto TestClass3::method() -> UndefinedNS::RetType |
| 306 |
{ |
| 307 |
tr("test3: trailing return type"); |
| 308 |
return {}; |
| 309 |
} |
| 310 |
|
| 311 |
// Template return type |
| 312 |
#include <vector> |
| 313 |
class TestClass4 : public QObject { |
| 314 |
Q_OBJECT |
| 315 |
public: |
| 316 |
std::vector<ThirdParty::Item> getItems(); |
| 317 |
}; |
| 318 |
|
| 319 |
std::vector<ThirdParty::Item> TestClass4::getItems() |
| 320 |
{ |
| 321 |
tr("test4: template return type"); |
| 322 |
return {}; |
| 323 |
} |
| 324 |
|
| 325 |
// Const reference return |
| 326 |
class TestClass5 : public QObject { |
| 327 |
Q_OBJECT |
| 328 |
public: |
| 329 |
const LibraryNS::Data& getData() const noexcept; |
| 330 |
}; |
| 331 |
|
| 332 |
const LibraryNS::Data& TestClass5::getData() const noexcept |
| 333 |
{ |
| 334 |
tr("test5: const reference return"); |
| 335 |
static LibraryNS::Data d; |
| 336 |
return d; |
| 337 |
} |
| 338 |
|
| 339 |
// Operator overload return type |
| 340 |
class TestClass6 : public QObject { |
| 341 |
Q_OBJECT |
| 342 |
public: |
| 343 |
OperatorNS::Type operator<<(const OperatorNS::Type& t); |
| 344 |
}; |
| 345 |
|
| 346 |
OperatorNS::Type TestClass6::operator<<(const OperatorNS::Type& t) |
| 347 |
{ |
| 348 |
tr("test6: operator overload"); |
| 349 |
return t; |
| 350 |
} |
| 351 |
|
| 352 |
//#include "main.moc" |