AddCacheEntry.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "AddCacheEntry.h"
  14. #include <QMetaProperty>
  15. static const int NumTypes = 4;
  16. static const QString TypeStrings[NumTypes] =
  17. { "BOOL", "PATH", "FILEPATH", "STRING" };
  18. static const QCMakeCacheProperty::PropertyType Types[NumTypes] =
  19. { QCMakeCacheProperty::BOOL, QCMakeCacheProperty::PATH,
  20. QCMakeCacheProperty::FILEPATH, QCMakeCacheProperty::STRING};
  21. AddCacheEntry::AddCacheEntry(QWidget* p)
  22. : QWidget(p)
  23. {
  24. this->setupUi(this);
  25. for(int i=0; i<NumTypes; i++)
  26. {
  27. this->Type->addItem(TypeStrings[i]);
  28. }
  29. QWidget* cb = new QCheckBox();
  30. QWidget* path = new QCMakeCachePathEditor();
  31. QWidget* filepath = new QCMakeCacheFilePathEditor();
  32. QWidget* string = new QLineEdit();
  33. this->StackedWidget->addWidget(cb);
  34. this->StackedWidget->addWidget(path);
  35. this->StackedWidget->addWidget(filepath);
  36. this->StackedWidget->addWidget(string);
  37. this->setTabOrder(this->Name, this->Type);
  38. this->setTabOrder(this->Type, cb);
  39. this->setTabOrder(cb, path);
  40. this->setTabOrder(path, filepath);
  41. this->setTabOrder(filepath, string);
  42. this->setTabOrder(string, this->Description);
  43. }
  44. QString AddCacheEntry::name() const
  45. {
  46. return this->Name->text();
  47. }
  48. QVariant AddCacheEntry::value() const
  49. {
  50. QWidget* w = this->StackedWidget->currentWidget();
  51. if(qobject_cast<QLineEdit*>(w))
  52. {
  53. return static_cast<QLineEdit*>(w)->text();
  54. }
  55. else if(qobject_cast<QCheckBox*>(w))
  56. {
  57. return static_cast<QCheckBox*>(w)->isChecked();
  58. }
  59. printf("didn't get anything %s\n", w->metaObject()->className());
  60. return QVariant();
  61. }
  62. QString AddCacheEntry::description() const
  63. {
  64. return this->Description->text();
  65. }
  66. QCMakeCacheProperty::PropertyType AddCacheEntry::type() const
  67. {
  68. int idx = this->Type->currentIndex();
  69. if(idx >= 0 && idx < NumTypes)
  70. {
  71. return Types[idx];
  72. }
  73. return QCMakeCacheProperty::BOOL;
  74. }