Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / QtDialog / AddCacheEntry.cxx
blob1226d24a862cfac23befd6e6427825680dca3bcc
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: AddCacheEntry.cxx,v $
5 Language: C++
6 Date: $Date: 2007/11/17 02:18:48 $
7 Version: $Revision: 1.3 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #include "AddCacheEntry.h"
19 #include <QMetaProperty>
21 static const int NumTypes = 4;
22 static const QString TypeStrings[NumTypes] =
23 { "BOOL", "PATH", "FILEPATH", "STRING" };
24 static const QCMakeCacheProperty::PropertyType Types[NumTypes] =
25 { QCMakeCacheProperty::BOOL, QCMakeCacheProperty::PATH,
26 QCMakeCacheProperty::FILEPATH, QCMakeCacheProperty::STRING};
28 AddCacheEntry::AddCacheEntry(QWidget* p)
29 : QWidget(p)
31 this->setupUi(this);
32 for(int i=0; i<NumTypes; i++)
34 this->Type->addItem(TypeStrings[i]);
36 QWidget* cb = new QCheckBox();
37 QWidget* path = new QCMakeCachePathEditor();
38 QWidget* filepath = new QCMakeCacheFilePathEditor();
39 QWidget* string = new QLineEdit();
40 this->StackedWidget->addWidget(cb);
41 this->StackedWidget->addWidget(path);
42 this->StackedWidget->addWidget(filepath);
43 this->StackedWidget->addWidget(string);
44 this->setTabOrder(this->Name, this->Type);
45 this->setTabOrder(this->Type, cb);
46 this->setTabOrder(cb, path);
47 this->setTabOrder(path, filepath);
48 this->setTabOrder(filepath, string);
49 this->setTabOrder(string, this->Description);
52 QString AddCacheEntry::name() const
54 return this->Name->text();
57 QVariant AddCacheEntry::value() const
59 QWidget* w = this->StackedWidget->currentWidget();
60 if(qobject_cast<QLineEdit*>(w))
62 return static_cast<QLineEdit*>(w)->text();
64 else if(qobject_cast<QCheckBox*>(w))
66 return static_cast<QCheckBox*>(w)->isChecked();
68 return QVariant();
71 QString AddCacheEntry::description() const
73 return this->Description->text();
76 QCMakeCacheProperty::PropertyType AddCacheEntry::type() const
78 int idx = this->Type->currentIndex();
79 if(idx >= 0 && idx < NumTypes)
81 return Types[idx];
83 return QCMakeCacheProperty::BOOL;