ctkSettingsDialogTest1.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.commontk.org/LICENSE
  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 <QCheckBox>
  17. #include <QSettings>
  18. #include <QTimer>
  19. // CTK includes
  20. #include "ctkSettingsPanel.h"
  21. #include "ctkSettingsDialog.h"
  22. // STD includes
  23. #include <cstdlib>
  24. #include <iostream>
  25. //-----------------------------------------------------------------------------
  26. int ctkSettingsDialogTest1(int argc, char * argv [] )
  27. {
  28. QApplication app(argc, argv);
  29. QSettings settings(QSettings::IniFormat, QSettings::UserScope, "Common ToolKit", "CTK");
  30. settings.remove("key 1");
  31. ctkSettingsDialog settingsDialog;
  32. settingsDialog.setSettings(&settings);
  33. ctkSettingsPanel* panel1 = new ctkSettingsPanel;
  34. settingsDialog.addPanel("Panel 1", panel1);
  35. if (panel1->settings() != &settings)
  36. {
  37. std::cerr << "ctkSettingsDialog::addPanel settings failed" << panel1->settings() << std::endl;
  38. return EXIT_FAILURE;
  39. }
  40. settingsDialog.addPanel("Panel 2", new ctkSettingsPanel);
  41. settingsDialog.addPanel("Panel 3", new ctkSettingsPanel);
  42. ctkSettingsPanel* panel4 = new ctkSettingsPanel;
  43. settingsDialog.addPanel("Panel 4", panel4, panel1);
  44. QCheckBox* box = new QCheckBox(panel4);
  45. box->setChecked(false); // false by default but we just want to make sure
  46. panel4->registerProperty("key 1", box, "checked",
  47. SIGNAL(toggled(bool)));
  48. QVariant boxVal = settings.value("key 1");
  49. if (!boxVal.isValid() || boxVal.toBool() != false)
  50. {
  51. std::cerr << "Saving to settings failed" << std::endl;
  52. return EXIT_FAILURE;
  53. }
  54. box->setChecked(true);
  55. boxVal = settings.value("key 1");
  56. if (!boxVal.isValid() || boxVal.toBool() != true)
  57. {
  58. std::cerr << "Saving to settings failed" << std::endl;
  59. return EXIT_FAILURE;
  60. }
  61. settingsDialog.resetSettings();
  62. boxVal = settings.value("key 1");
  63. if (!boxVal.isValid() || boxVal.toBool() != false)
  64. {
  65. std::cerr << "Reset failed" << std::endl;
  66. return EXIT_FAILURE;
  67. }
  68. settingsDialog.setCurrentPanel("Panel 4");
  69. settingsDialog.show();
  70. if (argc < 2 || QString(argv[1]) != "-I" )
  71. {
  72. QTimer::singleShot(200, &app, SLOT(quit()));
  73. }
  74. return app.exec();
  75. }