AddCacheEntry.cxx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include <QCompleter>
  13. static const int NumTypes = 4;
  14. static const QString TypeStrings[NumTypes] =
  15. { "BOOL", "PATH", "FILEPATH", "STRING" };
  16. static const QCMakeProperty::PropertyType Types[NumTypes] =
  17. { QCMakeProperty::BOOL, QCMakeProperty::PATH,
  18. QCMakeProperty::FILEPATH, QCMakeProperty::STRING};
  19. AddCacheEntry::AddCacheEntry(QWidget* p, const QStringList& completions)
  20. : QWidget(p)
  21. {
  22. this->setupUi(this);
  23. for(int i=0; i<NumTypes; i++)
  24. {
  25. this->Type->addItem(TypeStrings[i]);
  26. }
  27. QWidget* cb = new QCheckBox();
  28. QWidget* path = new QCMakePathEditor();
  29. QWidget* filepath = new QCMakeFilePathEditor();
  30. QWidget* string = new QLineEdit();
  31. this->StackedWidget->addWidget(cb);
  32. this->StackedWidget->addWidget(path);
  33. this->StackedWidget->addWidget(filepath);
  34. this->StackedWidget->addWidget(string);
  35. this->setTabOrder(this->Name, this->Type);
  36. this->setTabOrder(this->Type, cb);
  37. this->setTabOrder(cb, path);
  38. this->setTabOrder(path, filepath);
  39. this->setTabOrder(filepath, string);
  40. this->setTabOrder(string, this->Description);
  41. this->Name->setCompleter(new QCompleter(completions, this));
  42. }
  43. QString AddCacheEntry::name() const
  44. {
  45. return this->Name->text();
  46. }
  47. QVariant AddCacheEntry::value() const
  48. {
  49. QWidget* w = this->StackedWidget->currentWidget();
  50. if(qobject_cast<QLineEdit*>(w))
  51. {
  52. return static_cast<QLineEdit*>(w)->text();
  53. }
  54. else if(qobject_cast<QCheckBox*>(w))
  55. {
  56. return static_cast<QCheckBox*>(w)->isChecked();
  57. }
  58. return QVariant();
  59. }
  60. QString AddCacheEntry::description() const
  61. {
  62. return this->Description->text();
  63. }
  64. QCMakeProperty::PropertyType AddCacheEntry::type() const
  65. {
  66. int idx = this->Type->currentIndex();
  67. if(idx >= 0 && idx < NumTypes)
  68. {
  69. return Types[idx];
  70. }
  71. return QCMakeProperty::BOOL;
  72. }