ctkPathLineEditTest1.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QApplication>
  16. #include <QSignalSpy>
  17. #include <QStyle>
  18. #include <QTimer>
  19. #include <QVBoxLayout>
  20. // CTK includes
  21. #include "ctkPathLineEdit.h"
  22. // STD includes
  23. #include <cstdlib>
  24. #include <iostream>
  25. //-----------------------------------------------------------------------------
  26. int ctkPathLineEditTest1(int argc, char * argv [] )
  27. {
  28. QApplication app(argc, argv);
  29. QWidget topLevel;
  30. ctkPathLineEdit button;
  31. ctkPathLineEdit button2("Files",
  32. QStringList() << "Images (*.png *.jpg)" << "Text (*.txt)",
  33. ctkPathLineEdit::Files);
  34. ctkPathLineEdit button3("Dirs", QStringList("CTK*"));
  35. QVBoxLayout* layout = new QVBoxLayout;
  36. layout->addWidget(&button);
  37. layout->addWidget(&button2);
  38. layout->addWidget(&button3);
  39. topLevel.setLayout(layout);
  40. button.setCurrentPath(QDir::tempPath());
  41. if (button.currentPath() != QDir::tempPath())
  42. {
  43. std::cerr << "ctkPathLineEdit::setCurrentPath() failed"
  44. << qPrintable(button.currentPath()) << std::endl;
  45. return EXIT_FAILURE;
  46. }
  47. button.setLabel("Default");
  48. if (button.label() != "Default")
  49. {
  50. std::cerr << "ctkPathLineEdit::setLabel() failed"
  51. << qPrintable(button.label()) << std::endl;
  52. return EXIT_FAILURE;
  53. }
  54. QStringList nameFilters= button2.nameFilters();
  55. nameFilters << "*.conf";
  56. button2.setNameFilters(nameFilters);
  57. if (button2.nameFilters() != nameFilters)
  58. {
  59. std::cerr << "ctkPathLineEdit::setNameFilters() failed" << std::endl;
  60. return EXIT_FAILURE;
  61. }
  62. button2.setFilters(button2.filters() | ctkPathLineEdit::Readable);
  63. if (!(button2.filters() & ctkPathLineEdit::Readable))
  64. {
  65. std::cerr << "ctkPathLineEdit::setFilters() failed"
  66. << button2.filters() << std::endl;
  67. return EXIT_FAILURE;
  68. }
  69. button2.setCurrentFileExtension("jpg");
  70. if (!button2.currentPath().endsWith(".jpg"))
  71. {
  72. std::cerr << "ctkPathLineEdit::setCurrentFileExtension() failed"
  73. << qPrintable(button2.currentPath()) << std::endl;
  74. return EXIT_FAILURE;
  75. }
  76. topLevel.show();
  77. if (argc < 2 || QString(argv[1]) != "-I" )
  78. {
  79. QTimer::singleShot(500, &app, SLOT(quit()));
  80. }
  81. QTimer::singleShot(100, &button, SLOT(retrieveHistory()));
  82. QTimer::singleShot(115, &button2, SLOT(addCurrentPathToHistory()));
  83. // The open dialog blocks QTimers (to quit the app).
  84. button3.setOptions(button3.options() | ctkPathLineEdit::DontUseNativeDialog);
  85. QTimer::singleShot(120, &button3, SLOT(browse()));
  86. return app.exec();
  87. }