AddCacheEntry.cxx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "AddCacheEntry.h"
  2. #include <QMetaProperty>
  3. static const int NumTypes = 4;
  4. static const QString TypeStrings[NumTypes] =
  5. { "BOOL", "PATH", "FILEPATH", "STRING" };
  6. static const QCMakeCacheProperty::PropertyType Types[NumTypes] =
  7. { QCMakeCacheProperty::BOOL, QCMakeCacheProperty::PATH,
  8. QCMakeCacheProperty::FILEPATH, QCMakeCacheProperty::STRING};
  9. AddCacheEntry::AddCacheEntry(QWidget* p)
  10. : QWidget(p)
  11. {
  12. this->setupUi(this);
  13. for(int i=0; i<NumTypes; i++)
  14. {
  15. this->Type->addItem(TypeStrings[i]);
  16. }
  17. QWidget* cb = new QCheckBox();
  18. QWidget* path = new QCMakeCachePathEditor();
  19. QWidget* filepath = new QCMakeCacheFilePathEditor();
  20. QWidget* string = new QLineEdit();
  21. this->StackedWidget->addWidget(cb);
  22. this->StackedWidget->addWidget(path);
  23. this->StackedWidget->addWidget(filepath);
  24. this->StackedWidget->addWidget(string);
  25. this->setTabOrder(this->Name, this->Type);
  26. this->setTabOrder(this->Type, cb);
  27. this->setTabOrder(cb, path);
  28. this->setTabOrder(path, filepath);
  29. this->setTabOrder(filepath, string);
  30. this->setTabOrder(string, this->Description);
  31. }
  32. QString AddCacheEntry::name() const
  33. {
  34. return this->Name->text();
  35. }
  36. QVariant AddCacheEntry::value() const
  37. {
  38. QWidget* w = this->StackedWidget->currentWidget();
  39. if(qobject_cast<QLineEdit*>(w))
  40. {
  41. return static_cast<QLineEdit*>(w)->text();
  42. }
  43. else if(qobject_cast<QCheckBox*>(w))
  44. {
  45. return static_cast<QCheckBox*>(w)->isChecked();
  46. }
  47. printf("didn't get anything %s\n", w->metaObject()->className());
  48. return QVariant();
  49. }
  50. QString AddCacheEntry::description() const
  51. {
  52. return this->Description->text();
  53. }
  54. QCMakeCacheProperty::PropertyType AddCacheEntry::type() const
  55. {
  56. int idx = this->Type->currentIndex();
  57. if(idx >= 0 && idx < NumTypes)
  58. {
  59. return Types[idx];
  60. }
  61. return QCMakeCacheProperty::BOOL;
  62. }