| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2002 Jürgen Riegel <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#include <QApplication> |
| 24 |
#include <QEventLoop> |
| 25 |
#include <QFileDialog> |
| 26 |
#include <QMutex> |
| 27 |
#include <QMutexLocker> |
| 28 |
#include <QMdiArea> |
| 29 |
#include <QMdiSubWindow> |
| 30 |
#include <QRunnable> |
| 31 |
#include <QThread> |
| 32 |
#include <QThreadPool> |
| 33 |
#include <QTimer> |
| 34 |
#include <QTranslator> |
| 35 |
#include <QWaitCondition> |
| 36 |
|
| 37 |
#include <Base/Console.h> |
| 38 |
#include <Base/Sequencer.h> |
| 39 |
|
| 40 |
#include "CommandT.h" |
| 41 |
#include "Application.h" |
| 42 |
#include "Command.h" |
| 43 |
#include "MainWindow.h" |
| 44 |
#include "MDIView.h" |
| 45 |
#include "Language/Translator.h" |
| 46 |
|
| 47 |
|
| 48 |
using namespace Gui; |
| 49 |
|
| 50 |
//=========================================================================== |
| 51 |
// Std_TestQM |
| 52 |
//=========================================================================== |
| 53 |
DEF_STD_CMD(Std_TestQM) |
| 54 |
|
| 55 |
Std_TestQM::Std_TestQM() |
| 56 |
: Command("Std_TestQM") |
| 57 |
{ |
| 58 |
sGroup = "Standard-Test"; |
| 59 |
sMenuText = "Test Translation Files"; |
| 60 |
|
| 61 |
sToolTipText = "Runs a test to verify .qm translation files"; |
| 62 |
sWhatsThis = "Std_TestQM"; |
| 63 |
sStatusTip = sToolTipText; |
| 64 |
} |
| 65 |
|
| 66 |
void Std_TestQM::activated(int iMsg) |
| 67 |
{ |
| 68 |
Q_UNUSED(iMsg); |
| 69 |
QStringList files = QFileDialog::getOpenFileNames( |
| 70 |
getMainWindow(), |
| 71 |
QStringLiteral("Test translation"), |
| 72 |
QString(), |
| 73 |
QStringLiteral("Translation (*.qm)") |
| 74 |
); |
| 75 |
if (!files.empty()) { |
| 76 |
Translator::instance()->activateLanguage("English"); |
| 77 |
QList<QTranslator*> i18n = qApp->findChildren<QTranslator*>(); |
| 78 |
for (QTranslator* it : i18n) { |
| 79 |
qApp->removeTranslator(it); |
| 80 |
} |
| 81 |
for (const QString& it : files) { |
| 82 |
auto translator = new QTranslator(qApp); |
| 83 |
if (translator->load(it)) { |
| 84 |
qApp->installTranslator(translator); |
| 85 |
} |
| 86 |
else { |
| 87 |
delete translator; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
//=========================================================================== |
| 94 |
// Std_TestReloadQM |
| 95 |
//=========================================================================== |
| 96 |
DEF_STD_CMD(Std_TestReloadQM) |
| 97 |
|
| 98 |
Std_TestReloadQM::Std_TestReloadQM() |
| 99 |
: Command("Std_TestReloadQM") |
| 100 |
{ |
| 101 |
sGroup = "Standard-Test"; |
| 102 |
sMenuText = "Reload Translation Files"; |
| 103 |
sToolTipText = "Reloads the translation files"; |
| 104 |
sWhatsThis = "Std_TestReloadQM"; |
| 105 |
sStatusTip = sToolTipText; |
| 106 |
} |
| 107 |
|
| 108 |
void Std_TestReloadQM::activated(int iMsg) |
| 109 |
{ |
| 110 |
Q_UNUSED(iMsg); |
| 111 |
Translator::instance()->activateLanguage(Translator::instance()->activeLanguage().c_str()); |
| 112 |
} |
| 113 |
|
| 114 |
//=========================================================================== |
| 115 |
// Std_Test1 |
| 116 |
//=========================================================================== |
| 117 |
DEF_STD_CMD_A(FCCmdTest1) |
| 118 |
|
| 119 |
FCCmdTest1::FCCmdTest1() |
| 120 |
: Command("Std_Test1") |
| 121 |
{ |
| 122 |
sGroup = "Standard-Test"; |
| 123 |
sMenuText = "Test1"; |
| 124 |
sToolTipText = "Test function 1"; |
| 125 |
sWhatsThis = "Std_Test1"; |
| 126 |
sStatusTip = sToolTipText; |
| 127 |
sPixmap = "Std_Tool1"; |
| 128 |
sAccel = "Ctrl+T"; |
| 129 |
} |
| 130 |
|
| 131 |
void FCCmdTest1::activated(int iMsg) |
| 132 |
{ |
| 133 |
Q_UNUSED(iMsg); |
| 134 |
} |
| 135 |
|
| 136 |
bool FCCmdTest1::isActive() |
| 137 |
{ |
| 138 |
// return (GetActiveOCCDocument()!=NULL); |
| 139 |
return true; |
| 140 |
} |
| 141 |
|
| 142 |
//=========================================================================== |
| 143 |
// Std_Test2 |
| 144 |
//=========================================================================== |
| 145 |
DEF_STD_CMD_A(FCCmdTest2) |
| 146 |
|
| 147 |
FCCmdTest2::FCCmdTest2() |
| 148 |
: Command("Std_Test2") |
| 149 |
{ |
| 150 |
sGroup = "Standard-Test"; |
| 151 |
sMenuText = "Test2"; |
| 152 |
sToolTipText = "Test function 2"; |
| 153 |
sWhatsThis = "Std_Test2"; |
| 154 |
sStatusTip = sToolTipText; |
| 155 |
sPixmap = "Std_Tool2"; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
void FCCmdTest2::activated(int iMsg) |
| 160 |
{ |
| 161 |
Q_UNUSED(iMsg); |
| 162 |
} |
| 163 |
|
| 164 |
bool FCCmdTest2::isActive() |
| 165 |
{ |
| 166 |
return (getDocument() != nullptr); |
| 167 |
} |
| 168 |
|
| 169 |
//=========================================================================== |
| 170 |
// Std_Test3 |
| 171 |
//=========================================================================== |
| 172 |
DEF_STD_CMD_A(FCCmdTest3) |
| 173 |
|
| 174 |
FCCmdTest3::FCCmdTest3() |
| 175 |
: Command("Std_Test3") |
| 176 |
{ |
| 177 |
sGroup = "Standard-Test"; |
| 178 |
sMenuText = "Test3"; |
| 179 |
sToolTipText = "Test function 3"; |
| 180 |
sWhatsThis = "Std_Test3"; |
| 181 |
sStatusTip = sToolTipText; |
| 182 |
sPixmap = "Std_Tool3"; |
| 183 |
} |
| 184 |
|
| 185 |
void FCCmdTest3::activated(int iMsg) |
| 186 |
{ |
| 187 |
Q_UNUSED(iMsg); |
| 188 |
App::Document* pcDoc = getDocument(); |
| 189 |
if (!pcDoc) { |
| 190 |
return; |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
bool FCCmdTest3::isActive() |
| 196 |
{ |
| 197 |
return (getDocument() != nullptr); |
| 198 |
} |
| 199 |
|
| 200 |
//=========================================================================== |
| 201 |
// Std_Test4 |
| 202 |
//=========================================================================== |
| 203 |
|
| 204 |
DEF_STD_CMD_A(FCCmdTest4) |
| 205 |
|
| 206 |
FCCmdTest4::FCCmdTest4() |
| 207 |
: Command("Std_Test4") |
| 208 |
{ |
| 209 |
sGroup = "Standard-Test"; |
| 210 |
sMenuText = "Test4"; |
| 211 |
sToolTipText = "Test function 4"; |
| 212 |
sWhatsThis = "Std_Test4"; |
| 213 |
sStatusTip = sToolTipText; |
| 214 |
sPixmap = "Std_Tool4"; |
| 215 |
} |
| 216 |
|
| 217 |
void FCCmdTest4::activated(int iMsg) |
| 218 |
{ |
| 219 |
Q_UNUSED(iMsg); |
| 220 |
App::Document* pcDoc = getDocument(); |
| 221 |
if (!pcDoc) { |
| 222 |
return; |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
bool FCCmdTest4::isActive() |
| 228 |
{ |
| 229 |
return (getDocument() != nullptr); |
| 230 |
} |
| 231 |
|
| 232 |
//=========================================================================== |
| 233 |
// Std_Test5 |
| 234 |
//=========================================================================== |
| 235 |
DEF_STD_CMD_A(FCCmdTest5) |
| 236 |
|
| 237 |
FCCmdTest5::FCCmdTest5() |
| 238 |
: Command("Std_Test5") |
| 239 |
{ |
| 240 |
sGroup = "Standard-Test"; |
| 241 |
sMenuText = "Test5"; |
| 242 |
sToolTipText = "Test function 5"; |
| 243 |
sWhatsThis = "Std_Test5"; |
| 244 |
sStatusTip = sToolTipText; |
| 245 |
sPixmap = "Std_Tool5"; |
| 246 |
} |
| 247 |
|
| 248 |
void FCCmdTest5::activated(int iMsg) |
| 249 |
{ |
| 250 |
Q_UNUSED(iMsg); |
| 251 |
App::Document* pcDoc = getDocument(); |
| 252 |
if (!pcDoc) { |
| 253 |
return; |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
bool FCCmdTest5::isActive() |
| 258 |
{ |
| 259 |
return (getDocument() != nullptr); |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
//=========================================================================== |
| 264 |
// Std_Test6 |
| 265 |
//=========================================================================== |
| 266 |
DEF_STD_CMD_A(FCCmdTest6) |
| 267 |
|
| 268 |
FCCmdTest6::FCCmdTest6() |
| 269 |
: Command("Std_Test6") |
| 270 |
{ |
| 271 |
sGroup = "Standard-Test"; |
| 272 |
sMenuText = "Test6"; |
| 273 |
sToolTipText = "Test function 6"; |
| 274 |
sWhatsThis = "Std_Test6"; |
| 275 |
sStatusTip = sToolTipText; |
| 276 |
sPixmap = "Std_Tool6"; |
| 277 |
} |
| 278 |
|
| 279 |
void FCCmdTest6::activated(int iMsg) |
| 280 |
{ |
| 281 |
Q_UNUSED(iMsg); |
| 282 |
App::Document* pcDoc = getDocument(); |
| 283 |
if (!pcDoc) { |
| 284 |
return; |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
bool FCCmdTest6::isActive() |
| 289 |
{ |
| 290 |
return (getDocument() != nullptr); |
| 291 |
} |
| 292 |
|
| 293 |
//=========================================================================== |
| 294 |
// Std_TestCmdFuncs |
| 295 |
//=========================================================================== |
| 296 |
DEF_STD_CMD_A(CmdTestCmdFuncs) |
| 297 |
|
| 298 |
CmdTestCmdFuncs::CmdTestCmdFuncs() |
| 299 |
: Command("Std_TestCmdFuncs") |
| 300 |
{ |
| 301 |
sGroup = "Standard-Test"; |
| 302 |
sMenuText = "Test Functions"; |
| 303 |
sToolTipText = "Test functions"; |
| 304 |
sWhatsThis = "Std_TestCmdFuncs"; |
| 305 |
sStatusTip = sToolTipText; |
| 306 |
} |
| 307 |
|
| 308 |
void CmdTestCmdFuncs::activated(int iMsg) |
| 309 |
{ |
| 310 |
Q_UNUSED(iMsg); |
| 311 |
App::Document* doc = getDocument(); |
| 312 |
auto obj = doc->addObject("App::Annotation", "obj"); |
| 313 |
if (!obj) { |
| 314 |
return; |
| 315 |
} |
| 316 |
|
| 317 |
std::string objName = obj->getNameInDocument(); |
| 318 |
|
| 319 |
Gui::cmdAppDocument(doc, std::ostringstream() << "getObject('" << objName << "')"); |
| 320 |
std::string cmd = "getObject('"; |
| 321 |
cmd += objName; |
| 322 |
cmd += "')"; |
| 323 |
Gui::cmdAppDocument(doc, cmd); |
| 324 |
|
| 325 |
Gui::cmdAppDocument(doc, std::ostringstream() << "getObject('" << objName << "')"); |
| 326 |
Gui::cmdAppDocument(obj, std::ostringstream() << "getObject('" << objName << "')"); |
| 327 |
Gui::cmdGuiDocument(obj, std::ostringstream() << "getObject('" << objName << "')"); |
| 328 |
Gui::cmdAppObject(obj, "Visibility = False"); |
| 329 |
Gui::cmdGuiObject(obj, "Visibility = False"); |
| 330 |
Gui::cmdAppObject(obj, std::ostringstream() << "Visibility =" << "False"); |
| 331 |
Gui::cmdGuiObject(obj, std::ostringstream() << "Visibility =" << "False"); |
| 332 |
Gui::cmdAppObjectHide(obj); |
| 333 |
Gui::cmdAppObjectShow(obj); |
| 334 |
Gui::cmdAppObjectArgs(obj, "%s = %s", "Visibility", "True"); |
| 335 |
Gui::cmdGuiObjectArgs(obj, "%s = %s", "Visibility", "True"); |
| 336 |
Gui::cmdSetEdit(obj); |
| 337 |
Gui::doCommandT(Gui::Command::Gui, "print('%s %s')", "Hello,", "World"); |
| 338 |
Gui::copyVisualT(objName.c_str(), "DisplayMode", objName.c_str()); |
| 339 |
} |
| 340 |
|
| 341 |
bool CmdTestCmdFuncs::isActive() |
| 342 |
{ |
| 343 |
return (getDocument() != nullptr); |
| 344 |
} |
| 345 |
|
| 346 |
//=========================================================================== |
| 347 |
// Std_TestProgress1 |
| 348 |
//=========================================================================== |
| 349 |
DEF_STD_CMD_A(CmdTestProgress1) |
| 350 |
|
| 351 |
CmdTestProgress1::CmdTestProgress1() |
| 352 |
: Command("Std_TestProgress1") |
| 353 |
{ |
| 354 |
sGroup = "Standard-Test"; |
| 355 |
sMenuText = "Breakable Bar"; |
| 356 |
sToolTipText = "Test a breakable progress bar"; |
| 357 |
sWhatsThis = "Std_TestProgress1"; |
| 358 |
sStatusTip = sToolTipText; |
| 359 |
sPixmap = "Std_Tool7"; |
| 360 |
} |
| 361 |
|
| 362 |
void CmdTestProgress1::activated(int iMsg) |
| 363 |
{ |
| 364 |
Q_UNUSED(iMsg); |
| 365 |
QMutex mutex; |
| 366 |
QMutexLocker ml(&mutex); |
| 367 |
try { |
| 368 |
unsigned long steps = 1000; |
| 369 |
Base::SequencerLauncher seq("Starting progress bar", steps); |
| 370 |
|
| 371 |
for (unsigned long i = 0; i < steps; i++) { |
| 372 |
seq.next(true); |
| 373 |
QWaitCondition().wait(&mutex, 30); |
| 374 |
} |
| 375 |
} |
| 376 |
catch (...) { |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
bool CmdTestProgress1::isActive() |
| 381 |
{ |
| 382 |
return (!Base::Sequencer().isRunning()); |
| 383 |
} |
| 384 |
|
| 385 |
//=========================================================================== |
| 386 |
// Std_TestProgress2 |
| 387 |
//=========================================================================== |
| 388 |
DEF_STD_CMD_A(CmdTestProgress2) |
| 389 |
|
| 390 |
CmdTestProgress2::CmdTestProgress2() |
| 391 |
: Command("Std_TestProgress2") |
| 392 |
{ |
| 393 |
sGroup = "Standard-Test"; |
| 394 |
sMenuText = "Unbreakable Bar"; |
| 395 |
sToolTipText = "Test a unbreakable progress bar"; |
| 396 |
sWhatsThis = "Std_TestProgress2"; |
| 397 |
sStatusTip = sToolTipText; |
| 398 |
sPixmap = "Std_Tool7"; |
| 399 |
} |
| 400 |
|
| 401 |
void CmdTestProgress2::activated(int iMsg) |
| 402 |
{ |
| 403 |
Q_UNUSED(iMsg); |
| 404 |
QMutex mutex; |
| 405 |
QMutexLocker ml(&mutex); |
| 406 |
|
| 407 |
try { |
| 408 |
unsigned long steps = 1000; |
| 409 |
Base::SequencerLauncher seq("Starting progress bar", steps); |
| 410 |
|
| 411 |
for (unsigned long i = 0; i < steps; i++) { |
| 412 |
seq.next(false); |
| 413 |
QWaitCondition().wait(&mutex, 10); |
| 414 |
} |
| 415 |
} |
| 416 |
catch (...) { |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
bool CmdTestProgress2::isActive() |
| 421 |
{ |
| 422 |
return (!Base::Sequencer().isRunning()); |
| 423 |
} |
| 424 |
|
| 425 |
//=========================================================================== |
| 426 |
// Std_TestProgress3 |
| 427 |
//=========================================================================== |
| 428 |
DEF_STD_CMD_A(CmdTestProgress3) |
| 429 |
|
| 430 |
CmdTestProgress3::CmdTestProgress3() |
| 431 |
: Command("Std_TestProgress3") |
| 432 |
{ |
| 433 |
sGroup = "Standard-Test"; |
| 434 |
sMenuText = "Nested Progress Bar"; |
| 435 |
sToolTipText = "Test nested progress bar"; |
| 436 |
sWhatsThis = "Std_TestProgress3"; |
| 437 |
sStatusTip = sToolTipText; |
| 438 |
sPixmap = "Std_Tool8"; |
| 439 |
} |
| 440 |
|
| 441 |
void CmdTestProgress3::activated(int iMsg) |
| 442 |
{ |
| 443 |
Q_UNUSED(iMsg); |
| 444 |
QMutex mutex; |
| 445 |
QMutexLocker ml(&mutex); |
| 446 |
|
| 447 |
try { |
| 448 |
// level 1 |
| 449 |
unsigned long level1 = 5; |
| 450 |
Base::SequencerLauncher seq1("Starting progress bar", level1); |
| 451 |
for (unsigned long i = 0; i < level1; i++) { |
| 452 |
QWaitCondition().wait(&mutex, 200); |
| 453 |
seq1.next(true); |
| 454 |
|
| 455 |
// level 2 |
| 456 |
unsigned long level2 = 6; |
| 457 |
Base::SequencerLauncher seq2("Starting progress bar", level2); |
| 458 |
for (unsigned long j = 0; j < level2; j++) { |
| 459 |
QWaitCondition().wait(&mutex, 150); |
| 460 |
seq2.next(true); |
| 461 |
|
| 462 |
// level 3 |
| 463 |
unsigned long level3 = 7; |
| 464 |
Base::SequencerLauncher seq3("Starting progress bar", level3); |
| 465 |
for (unsigned long k = 0; k < level3; k++) { |
| 466 |
QWaitCondition().wait(&mutex, 100); |
| 467 |
seq3.next(true); |
| 468 |
|
| 469 |
// level 4 |
| 470 |
unsigned long level4 = 8; |
| 471 |
Base::SequencerLauncher seq4("Starting progress bar", level4); |
| 472 |
for (unsigned long l = 0; l < level4; l++) { |
| 473 |
QWaitCondition().wait(&mutex, 5); |
| 474 |
seq4.next(true); |
| 475 |
} |
| 476 |
} |
| 477 |
} |
| 478 |
} |
| 479 |
} |
| 480 |
catch (...) { |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
bool CmdTestProgress3::isActive() |
| 485 |
{ |
| 486 |
return (!Base::Sequencer().isRunning()); |
| 487 |
} |
| 488 |
|
| 489 |
//=========================================================================== |
| 490 |
// Std_TestProgress4 |
| 491 |
//=========================================================================== |
| 492 |
DEF_STD_CMD_A(CmdTestProgress4) |
| 493 |
|
| 494 |
CmdTestProgress4::CmdTestProgress4() |
| 495 |
: Command("Std_TestProgress4") |
| 496 |
{ |
| 497 |
sGroup = "Standard-Test"; |
| 498 |
sMenuText = "Mixed Nested Bar"; |
| 499 |
sToolTipText = "Test a mixed up nested progress bar"; |
| 500 |
sWhatsThis = "Std_TestProgress4"; |
| 501 |
sStatusTip = sToolTipText; |
| 502 |
sPixmap = "Std_Tool7"; |
| 503 |
} |
| 504 |
|
| 505 |
void CmdTestProgress4::activated(int iMsg) |
| 506 |
{ |
| 507 |
Q_UNUSED(iMsg); |
| 508 |
QMutex mutex; |
| 509 |
QMutexLocker ml(&mutex); |
| 510 |
|
| 511 |
try { |
| 512 |
unsigned long steps = 50; |
| 513 |
auto seq = new Base::SequencerLauncher("Starting progress bar", steps); |
| 514 |
|
| 515 |
for (unsigned long i = 0; i < steps; i++) { |
| 516 |
QWaitCondition().wait(&mutex, 5); |
| 517 |
if (i == 45) { |
| 518 |
delete seq; |
| 519 |
seq = nullptr; |
| 520 |
} |
| 521 |
if (seq) { |
| 522 |
seq->next(false); |
| 523 |
} |
| 524 |
Base::SequencerLauncher seq2("Starting second progress bar", steps); |
| 525 |
for (unsigned long j = 0; j < steps; j++) { |
| 526 |
QWaitCondition().wait(&mutex, (seq ? 5 : 50)); |
| 527 |
seq2.next(true); |
| 528 |
} |
| 529 |
} |
| 530 |
} |
| 531 |
catch (...) { |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
bool CmdTestProgress4::isActive() |
| 536 |
{ |
| 537 |
return (!Base::Sequencer().isRunning()); |
| 538 |
} |
| 539 |
|
| 540 |
//=========================================================================== |
| 541 |
// Std_TestProgress5 |
| 542 |
//=========================================================================== |
| 543 |
DEF_STD_CMD_A(CmdTestProgress5) |
| 544 |
|
| 545 |
CmdTestProgress5::CmdTestProgress5() |
| 546 |
: Command("Std_TestProgress5") |
| 547 |
{ |
| 548 |
sGroup = "Standard-Test"; |
| 549 |
sMenuText = "From Thread"; |
| 550 |
sToolTipText = "Test a progress bar from a thread"; |
| 551 |
sWhatsThis = "Std_TestProgress5"; |
| 552 |
sStatusTip = sToolTipText; |
| 553 |
sPixmap = "Std_Tool7"; |
| 554 |
} |
| 555 |
|
| 556 |
class BarThread: public QThread |
| 557 |
{ |
| 558 |
public: |
| 559 |
explicit BarThread(unsigned long s) |
| 560 |
: steps(s) |
| 561 |
{} |
| 562 |
~BarThread() override = default; |
| 563 |
void run() override |
| 564 |
{ |
| 565 |
QMutex mutex; |
| 566 |
QMutexLocker ml(&mutex); |
| 567 |
|
| 568 |
try { |
| 569 |
Base::SequencerLauncher seq("Starting progress bar in thread", steps); |
| 570 |
|
| 571 |
for (unsigned long i = 0; i < this->steps; i++) { |
| 572 |
seq.next(true); |
| 573 |
QWaitCondition().wait(&mutex, 5); |
| 574 |
} |
| 575 |
} |
| 576 |
catch (...) { |
| 577 |
} |
| 578 |
|
| 579 |
this->deleteLater(); |
| 580 |
Base::Console().message("Thread with %d steps finished\n", this->steps); |
| 581 |
} |
| 582 |
|
| 583 |
private: |
| 584 |
unsigned long steps; |
| 585 |
}; |
| 586 |
|
| 587 |
void CmdTestProgress5::activated(int iMsg) |
| 588 |
{ |
| 589 |
Q_UNUSED(iMsg); |
| 590 |
QEventLoop loop; |
| 591 |
|
| 592 |
auto thr1 = new BarThread(2000); |
| 593 |
QObject::connect(thr1, &QThread::finished, &loop, &QEventLoop::quit); |
| 594 |
thr1->start(); |
| 595 |
loop.exec(); |
| 596 |
|
| 597 |
auto thr2 = new BarThread(1500); |
| 598 |
|
| 599 |
QTimer timer; |
| 600 |
timer.setSingleShot(true); |
| 601 |
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); |
| 602 |
thr2->start(); |
| 603 |
timer.start(2000); // 2s timeout |
| 604 |
loop.exec(); |
| 605 |
|
| 606 |
auto thr3 = new BarThread(1000); |
| 607 |
thr3->start(); |
| 608 |
} |
| 609 |
|
| 610 |
bool CmdTestProgress5::isActive() |
| 611 |
{ |
| 612 |
return (!Base::Sequencer().isRunning()); |
| 613 |
} |
| 614 |
|
| 615 |
//=========================================================================== |
| 616 |
// Std_MDITest |
| 617 |
//=========================================================================== |
| 618 |
DEF_STD_CMD_A(CmdTestMDI1) |
| 619 |
|
| 620 |
CmdTestMDI1::CmdTestMDI1() |
| 621 |
: Command("Std_MDITest1") |
| 622 |
{ |
| 623 |
sGroup = "Standard-Test"; |
| 624 |
sMenuText = "Remove MDI 1"; |
| 625 |
sToolTipText = "Remove MDI from main window"; |
| 626 |
sWhatsThis = "Std_MDITest1"; |
| 627 |
sStatusTip = sToolTipText; |
| 628 |
} |
| 629 |
|
| 630 |
void CmdTestMDI1::activated(int iMsg) |
| 631 |
{ |
| 632 |
Q_UNUSED(iMsg); |
| 633 |
MDIView* mdi = getMainWindow()->activeWindow(); |
| 634 |
getMainWindow()->removeWindow(mdi); |
| 635 |
} |
| 636 |
|
| 637 |
bool CmdTestMDI1::isActive() |
| 638 |
{ |
| 639 |
return getMainWindow()->activeWindow(); |
| 640 |
} |
| 641 |
|
| 642 |
DEF_STD_CMD_A(CmdTestMDI2) |
| 643 |
|
| 644 |
CmdTestMDI2::CmdTestMDI2() |
| 645 |
: Command("Std_MDITest2") |
| 646 |
{ |
| 647 |
sGroup = "Standard-Test"; |
| 648 |
sMenuText = "Remove MDI 2"; |
| 649 |
sToolTipText = "Remove view from MDI area"; |
| 650 |
sWhatsThis = "Std_MDITest2"; |
| 651 |
sStatusTip = sToolTipText; |
| 652 |
} |
| 653 |
|
| 654 |
void CmdTestMDI2::activated(int iMsg) |
| 655 |
{ |
| 656 |
Q_UNUSED(iMsg); |
| 657 |
QMdiArea* area = getMainWindow()->findChild<QMdiArea*>(); |
| 658 |
if (area) { |
| 659 |
MDIView* mdi = getMainWindow()->activeWindow(); |
| 660 |
area->removeSubWindow(mdi->parentWidget()); |
| 661 |
mdi->parentWidget()->showNormal(); |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
bool CmdTestMDI2::isActive() |
| 666 |
{ |
| 667 |
return getMainWindow()->activeWindow(); |
| 668 |
} |
| 669 |
|
| 670 |
DEF_STD_CMD_A(CmdTestMDI3) |
| 671 |
|
| 672 |
CmdTestMDI3::CmdTestMDI3() |
| 673 |
: Command("Std_MDITest3") |
| 674 |
{ |
| 675 |
sGroup = "Standard-Test"; |
| 676 |
sMenuText = "Remove MDI 3"; |
| 677 |
sToolTipText = "Unset parent and remove from main window"; |
| 678 |
sWhatsThis = "Std_MDITest3"; |
| 679 |
sStatusTip = sToolTipText; |
| 680 |
} |
| 681 |
|
| 682 |
void CmdTestMDI3::activated(int iMsg) |
| 683 |
{ |
| 684 |
Q_UNUSED(iMsg); |
| 685 |
MDIView* mdi = getMainWindow()->activeWindow(); |
| 686 |
getMainWindow()->removeWindow(mdi); |
| 687 |
mdi->setParent( |
| 688 |
nullptr, |
| 689 |
Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint |
| 690 |
); |
| 691 |
mdi->show(); |
| 692 |
} |
| 693 |
|
| 694 |
bool CmdTestMDI3::isActive() |
| 695 |
{ |
| 696 |
return getMainWindow()->activeWindow(); |
| 697 |
} |
| 698 |
|
| 699 |
DEF_STD_CMD(CmdTestConsoleOutput) |
| 700 |
|
| 701 |
CmdTestConsoleOutput::CmdTestConsoleOutput() |
| 702 |
: Command("Std_TestConsoleOutput") |
| 703 |
{ |
| 704 |
sGroup = "Standard-Test"; |
| 705 |
sMenuText = QT_TR_NOOP("Test Console Output"); |
| 706 |
sToolTipText = QT_TR_NOOP("Run test cases to verify console messages"); |
| 707 |
sStatusTip = sToolTipText; |
| 708 |
} |
| 709 |
|
| 710 |
namespace Gui |
| 711 |
{ |
| 712 |
class TestConsoleObserver: public Base::ILogger |
| 713 |
{ |
| 714 |
QMutex mutex; |
| 715 |
|
| 716 |
public: |
| 717 |
int matchMsg {0}; |
| 718 |
int matchWrn {0}; |
| 719 |
int matchErr {0}; |
| 720 |
int matchLog {0}; |
| 721 |
int matchCritical {0}; |
| 722 |
TestConsoleObserver() = default; |
| 723 |
void sendLog( |
| 724 |
const std::string& notifiername, |
| 725 |
const std::string& msg, |
| 726 |
Base::LogStyle level, |
| 727 |
Base::IntendedRecipient recipient, |
| 728 |
Base::ContentType content |
| 729 |
) override |
| 730 |
{ |
| 731 |
|
| 732 |
(void)notifiername; |
| 733 |
(void)recipient; |
| 734 |
(void)content; |
| 735 |
|
| 736 |
QMutexLocker ml(&mutex); |
| 737 |
|
| 738 |
switch (level) { |
| 739 |
case Base::LogStyle::Warning: |
| 740 |
matchWrn += strcmp(msg.c_str(), "Write a warning to the console output.\n"); |
| 741 |
break; |
| 742 |
case Base::LogStyle::Message: |
| 743 |
matchMsg += strcmp(msg.c_str(), "Write a message to the console output.\n"); |
| 744 |
break; |
| 745 |
case Base::LogStyle::Error: |
| 746 |
matchErr += strcmp(msg.c_str(), "Write an error to the console output.\n"); |
| 747 |
break; |
| 748 |
case Base::LogStyle::Log: |
| 749 |
matchLog += strcmp(msg.c_str(), "Write a log to the console output.\n"); |
| 750 |
break; |
| 751 |
case Base::LogStyle::Critical: |
| 752 |
matchMsg += strcmp(msg.c_str(), "Write a critical message to the console output.\n"); |
| 753 |
break; |
| 754 |
default: |
| 755 |
break; |
| 756 |
} |
| 757 |
} |
| 758 |
}; |
| 759 |
|
| 760 |
class ConsoleMessageTask: public QRunnable |
| 761 |
{ |
| 762 |
public: |
| 763 |
void run() override |
| 764 |
{ |
| 765 |
for (int i = 0; i < 10; i++) { |
| 766 |
Base::Console().message("Write a message to the console output.\n"); |
| 767 |
} |
| 768 |
} |
| 769 |
}; |
| 770 |
|
| 771 |
class ConsoleWarningTask: public QRunnable |
| 772 |
{ |
| 773 |
public: |
| 774 |
void run() override |
| 775 |
{ |
| 776 |
for (int i = 0; i < 10; i++) { |
| 777 |
Base::Console().warning("Write a warning to the console output.\n"); |
| 778 |
} |
| 779 |
} |
| 780 |
}; |
| 781 |
|
| 782 |
class ConsoleErrorTask: public QRunnable |
| 783 |
{ |
| 784 |
public: |
| 785 |
void run() override |
| 786 |
{ |
| 787 |
for (int i = 0; i < 10; i++) { |
| 788 |
Base::Console().error("Write an error to the console output.\n"); |
| 789 |
} |
| 790 |
} |
| 791 |
}; |
| 792 |
|
| 793 |
class ConsoleLogTask: public QRunnable |
| 794 |
{ |
| 795 |
public: |
| 796 |
void run() override |
| 797 |
{ |
| 798 |
for (int i = 0; i < 10; i++) { |
| 799 |
Base::Console().log("Write a log to the console output.\n"); |
| 800 |
} |
| 801 |
} |
| 802 |
}; |
| 803 |
|
| 804 |
class ConsoleCriticalTask: public QRunnable |
| 805 |
{ |
| 806 |
public: |
| 807 |
void run() override |
| 808 |
{ |
| 809 |
for (int i = 0; i < 10; i++) { |
| 810 |
Base::Console().critical("Write a critical message to the console output.\n"); |
| 811 |
} |
| 812 |
} |
| 813 |
}; |
| 814 |
|
| 815 |
} // namespace Gui |
| 816 |
|
| 817 |
void CmdTestConsoleOutput::activated(int iMsg) |
| 818 |
{ |
| 819 |
Q_UNUSED(iMsg); |
| 820 |
TestConsoleObserver obs; |
| 821 |
Base::Console().attachObserver(&obs); |
| 822 |
QThreadPool::globalInstance()->start(new ConsoleMessageTask); |
| 823 |
QThreadPool::globalInstance()->start(new ConsoleWarningTask); |
| 824 |
QThreadPool::globalInstance()->start(new ConsoleErrorTask); |
| 825 |
QThreadPool::globalInstance()->start(new ConsoleLogTask); |
| 826 |
QThreadPool::globalInstance()->start(new ConsoleCriticalTask); |
| 827 |
QThreadPool::globalInstance()->waitForDone(); |
| 828 |
Base::Console().detachObserver(&obs); |
| 829 |
|
| 830 |
if (obs.matchMsg > 0 || obs.matchWrn > 0 || obs.matchErr > 0 || obs.matchLog > 0 |
| 831 |
|| obs.matchCritical > 0) { |
| 832 |
Base::Console().error("Race condition in Console class\n"); |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
namespace Gui |
| 838 |
{ |
| 839 |
|
| 840 |
void CreateTestCommands() |
| 841 |
{ |
| 842 |
CommandManager& rcCmdMgr = Application::Instance->commandManager(); |
| 843 |
|
| 844 |
rcCmdMgr.addCommand(new Std_TestQM()); |
| 845 |
rcCmdMgr.addCommand(new Std_TestReloadQM()); |
| 846 |
rcCmdMgr.addCommand(new FCCmdTest1()); |
| 847 |
rcCmdMgr.addCommand(new FCCmdTest2()); |
| 848 |
rcCmdMgr.addCommand(new FCCmdTest3()); |
| 849 |
rcCmdMgr.addCommand(new FCCmdTest4()); |
| 850 |
rcCmdMgr.addCommand(new FCCmdTest5()); |
| 851 |
rcCmdMgr.addCommand(new FCCmdTest6()); |
| 852 |
rcCmdMgr.addCommand(new CmdTestCmdFuncs); |
| 853 |
rcCmdMgr.addCommand(new CmdTestProgress1()); |
| 854 |
rcCmdMgr.addCommand(new CmdTestProgress2()); |
| 855 |
rcCmdMgr.addCommand(new CmdTestProgress3()); |
| 856 |
rcCmdMgr.addCommand(new CmdTestProgress4()); |
| 857 |
rcCmdMgr.addCommand(new CmdTestProgress5()); |
| 858 |
rcCmdMgr.addCommand(new CmdTestMDI1()); |
| 859 |
rcCmdMgr.addCommand(new CmdTestMDI2()); |
| 860 |
rcCmdMgr.addCommand(new CmdTestMDI3()); |
| 861 |
rcCmdMgr.addCommand(new CmdTestConsoleOutput()); |
| 862 |
} |
| 863 |
|
| 864 |
} // namespace Gui |