AddCacheEntry.cxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "AddCacheEntry.h"
  11. #include <QMetaProperty>
  12. static const int NumTypes = 4;
  13. static const QString TypeStrings[NumTypes] =
  14. { "BOOL", "PATH", "FILEPATH", "STRING" };
  15. static const QCMakeProperty::PropertyType Types[NumTypes] =
  16. { QCMakeProperty::BOOL, QCMakeProperty::PATH,
  17. QCMakeProperty::FILEPATH, QCMakeProperty::STRING};
  18. AddCacheEntry::AddCacheEntry(QWidget* p)
  19. : QWidget(p)
  20. {
  21. this->setupUi(this);
  22. for(int i=0; i<NumTypes; i++)
  23. {
  24. this->Type->addItem(TypeStrings[i]);
  25. }
  26. QWidget* cb = new QCheckBox();
  27. QWidget* path = new QCMakePathEditor();
  28. QWidget* filepath = new QCMakeFilePathEditor();
  29. QWidget* string = new QLineEdit();
  30. this->StackedWidget->addWidget(cb);
  31. this->StackedWidget->addWidget(path);
  32. this->StackedWidget->addWidget(filepath);
  33. this->StackedWidget->addWidget(string);
  34. this->setTabOrder(this->Name, this->Type);
  35. this->setTabOrder(this->Type, cb);
  36. this->setTabOrder(cb, path);
  37. this->setTabOrder(path, filepath);
  38. this->setTabOrder(filepath, string);
  39. this->setTabOrder(string, this->Description);
  40. }
  41. QString AddCacheEntry::name() const
  42. {
  43. return this->Name->text();
  44. }
  45. QVariant AddCacheEntry::value() const
  46. {
  47. QWidget* w = this->StackedWidget->currentWidget();
  48. if(qobject_cast<QLineEdit*>(w))
  49. {
  50. return static_cast<QLineEdit*>(w)->text();
  51. }
  52. else if(qobject_cast<QCheckBox*>(w))
  53. {
  54. return static_cast<QCheckBox*>(w)->isChecked();
  55. }
  56. return QVariant();
  57. }
  58. QString AddCacheEntry::description() const
  59. {
  60. return this->Description->text();
  61. }
  62. QCMakeProperty::PropertyType AddCacheEntry::type() const
  63. {
  64. int idx = this->Type->currentIndex();
  65. if(idx >= 0 && idx < NumTypes)
  66. {
  67. return Types[idx];
  68. }
  69. return QCMakeProperty::BOOL;
  70. }