From a81896eaedc17f11e3fb412a296309abd9e34b63 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Mon, 12 Nov 2007 23:54:49 -0500 Subject: ENH: Add ability to add cache entries (even before first configure). --- Source/QtDialog/AddCacheEntry.cxx | 71 +++++++++++++++++++++++++ Source/QtDialog/AddCacheEntry.h | 24 +++++++++ Source/QtDialog/AddCacheEntry.ui | 97 +++++++++++++++++++++++++++++++++++ Source/QtDialog/CMakeLists.txt | 4 ++ Source/QtDialog/CMakeSetup.qrc | 1 + Source/QtDialog/CMakeSetupDialog.cxx | 40 ++++++++++++++- Source/QtDialog/CMakeSetupDialog.h | 1 + Source/QtDialog/CMakeSetupDialog.ui | 16 ++++++ Source/QtDialog/Plus16.png | Bin 0 -> 358 bytes Source/QtDialog/QCMake.cxx | 41 ++++++++++++++- Source/QtDialog/QCMakeCacheView.cxx | 90 ++++++++++++++++++++++++-------- Source/QtDialog/QCMakeCacheView.h | 40 ++++++++++----- 12 files changed, 391 insertions(+), 34 deletions(-) create mode 100644 Source/QtDialog/AddCacheEntry.cxx create mode 100644 Source/QtDialog/AddCacheEntry.h create mode 100644 Source/QtDialog/AddCacheEntry.ui create mode 100644 Source/QtDialog/Plus16.png diff --git a/Source/QtDialog/AddCacheEntry.cxx b/Source/QtDialog/AddCacheEntry.cxx new file mode 100644 index 0000000..46cc6ab --- /dev/null +++ b/Source/QtDialog/AddCacheEntry.cxx @@ -0,0 +1,71 @@ + +#include "AddCacheEntry.h" +#include + +static const int NumTypes = 4; +static const QString TypeStrings[NumTypes] = + { "BOOL", "PATH", "FILEPATH", "STRING" }; +static const QCMakeCacheProperty::PropertyType Types[NumTypes] = + { QCMakeCacheProperty::BOOL, QCMakeCacheProperty::PATH, + QCMakeCacheProperty::FILEPATH, QCMakeCacheProperty::STRING}; + +AddCacheEntry::AddCacheEntry(QWidget* p) + : QWidget(p) +{ + this->setupUi(this); + for(int i=0; iType->addItem(TypeStrings[i]); + } + QWidget* cb = new QCheckBox(); + QWidget* path = new QCMakeCachePathEditor(); + QWidget* filepath = new QCMakeCacheFilePathEditor(); + QWidget* string = new QLineEdit(); + this->StackedWidget->addWidget(cb); + this->StackedWidget->addWidget(path); + this->StackedWidget->addWidget(filepath); + this->StackedWidget->addWidget(string); + this->setTabOrder(this->Name, this->Type); + this->setTabOrder(this->Type, cb); + this->setTabOrder(cb, path); + this->setTabOrder(path, filepath); + this->setTabOrder(filepath, string); + this->setTabOrder(string, this->Description); +} + +QString AddCacheEntry::name() const +{ + return this->Name->text(); +} + +QVariant AddCacheEntry::value() const +{ + QWidget* w = this->StackedWidget->currentWidget(); + if(qobject_cast(w)) + { + return static_cast(w)->text(); + } + else if(qobject_cast(w)) + { + return static_cast(w)->isChecked(); + } + printf("didn't get anything %s\n", w->metaObject()->className()); + return QVariant(); +} + +QString AddCacheEntry::description() const +{ + return this->Description->text(); +} + +QCMakeCacheProperty::PropertyType AddCacheEntry::type() const +{ + int idx = this->Type->currentIndex(); + if(idx >= 0 && idx < NumTypes) + { + return Types[idx]; + } + return QCMakeCacheProperty::BOOL; +} + + diff --git a/Source/QtDialog/AddCacheEntry.h b/Source/QtDialog/AddCacheEntry.h new file mode 100644 index 0000000..74e4705 --- /dev/null +++ b/Source/QtDialog/AddCacheEntry.h @@ -0,0 +1,24 @@ + +#ifndef AddCacheEntry_h +#define AddCacheEntry_h + +#include +#include + +#include "QCMake.h" +#include "ui_AddCacheEntry.h" + +class AddCacheEntry : public QWidget, public Ui::AddCacheEntry +{ + Q_OBJECT +public: + AddCacheEntry(QWidget* p); + + QString name() const; + QVariant value() const; + QString description() const; + QCMakeCacheProperty::PropertyType type() const; +}; + +#endif + diff --git a/Source/QtDialog/AddCacheEntry.ui b/Source/QtDialog/AddCacheEntry.ui new file mode 100644 index 0000000..3ed9b49 --- /dev/null +++ b/Source/QtDialog/AddCacheEntry.ui @@ -0,0 +1,97 @@ + + AddCacheEntry + + + + 0 + 0 + 380 + 158 + + + + Form + + + + 0 + + + + + Name: + + + + + + + + + + Type: + + + + + + + + + + + Value: + + + + + + + 0 + + + + + + + Description: + + + + + + + + + + + QCMakeCachePathEditor + QLineEdit +
QCMakeCacheView.h
+
+ + QCMakeCacheFilePathEditor + QLineEdit +
QCMakeCacheView.h
+
+
+ + + + Type + currentIndexChanged(int) + StackedWidget + setCurrentIndex(int) + + + 229 + 34 + + + 287 + 65 + + + + +
diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index 5ce6d24..f36d405 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -9,6 +9,8 @@ ELSE(NOT QT4_FOUND) INCLUDE(${QT_USE_FILE}) SET(SRCS + AddCacheEntry.cxx + AddCacheEntry.h CMakeSetup.cxx CMakeSetupDialog.cxx CMakeSetupDialog.h @@ -19,8 +21,10 @@ ELSE(NOT QT4_FOUND) ) QT4_WRAP_UI(UI_SRCS CMakeSetupDialog.ui + AddCacheEntry.ui ) QT4_WRAP_CPP(MOC_SRCS + AddCacheEntry.h CMakeSetupDialog.h QCMake.h QCMakeCacheView.h diff --git a/Source/QtDialog/CMakeSetup.qrc b/Source/QtDialog/CMakeSetup.qrc index a4031d3..5ceb1df 100644 --- a/Source/QtDialog/CMakeSetup.qrc +++ b/Source/QtDialog/CMakeSetup.qrc @@ -2,5 +2,6 @@ CMakeSetup.png Delete16.png + Plus16.png diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 4f2884c..fe30896 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -34,6 +34,7 @@ #include "QCMake.h" #include "QCMakeCacheView.h" +#include "AddCacheEntry.h" QCMakeThread::QCMakeThread(QObject* p) : QThread(p), CMakeInstance(NULL) @@ -82,6 +83,7 @@ CMakeSetupDialog::CMakeSetupDialog() this->setCentralWidget(cont); this->ProgressBar->reset(); this->RemoveEntry->setEnabled(false); + this->AddEntry->setEnabled(false); QMenu* FileMenu = this->menuBar()->addMenu(tr("&File")); this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache")); @@ -186,6 +188,8 @@ void CMakeSetupDialog::initialize() this, SLOT(selectionChanged())); QObject::connect(this->RemoveEntry, SIGNAL(clicked(bool)), this, SLOT(removeSelectedCacheEntries())); + QObject::connect(this->AddEntry, SIGNAL(clicked(bool)), + this, SLOT(addCacheEntry())); // get the saved binary directories QStringList buildPaths = this->loadBuildPaths(); @@ -449,8 +453,8 @@ void CMakeSetupDialog::setEnabledState(bool enabled) this->DeleteCacheAction->setEnabled(enabled); this->ExitAction->setEnabled(enabled); this->ConfigureAction->setEnabled(enabled); + this->AddEntry->setEnabled(enabled); this->RemoveEntry->setEnabled(false); // let selection re-enable it - // generate button/action are handled separately } void CMakeSetupDialog::promptForGenerator() @@ -735,4 +739,38 @@ void CMakeSetupDialog::enterState(CMakeSetupDialog::State s) } } +void CMakeSetupDialog::addCacheEntry() +{ + QDialog dialog(this); + dialog.resize(400, 200); + dialog.setWindowTitle(tr("CMakeSetup Help")); + QVBoxLayout* l = new QVBoxLayout(&dialog); + AddCacheEntry* w = new AddCacheEntry(&dialog); + QDialogButtonBox* btns = new QDialogButtonBox( + QDialogButtonBox::Ok | QDialogButtonBox::Cancel, + Qt::Horizontal, &dialog); + QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept())); + QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(reject())); + l->addWidget(w); + l->addStretch(); + l->addWidget(btns); + if(QDialog::Accepted == dialog.exec()) + { + QCMakeCacheModel* m = this->CacheValues->cacheModel(); + m->insertRows(0, 1, QModelIndex()); + m->setData(m->index(0, 0), w->type(), QCMakeCacheModel::TypeRole); + m->setData(m->index(0, 0), w->name(), Qt::DisplayRole); + m->setData(m->index(0, 0), w->description(), QCMakeCacheModel::HelpRole); + m->setData(m->index(0, 0), 0, QCMakeCacheModel::AdvancedRole); + if(w->type() == QCMakeCacheProperty::BOOL) + { + m->setData(m->index(0, 1), w->value().toBool() ? + Qt::Checked : Qt::Unchecked, Qt::CheckStateRole); + } + else + { + m->setData(m->index(0, 1), w->value(), Qt::DisplayRole); + } + } +} diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h index d8bea36..1294594 100644 --- a/Source/QtDialog/CMakeSetupDialog.h +++ b/Source/QtDialog/CMakeSetupDialog.h @@ -69,6 +69,7 @@ protected slots: void setCacheModified(); void removeSelectedCacheEntries(); void selectionChanged(); + void addCacheEntry(); protected: diff --git a/Source/QtDialog/CMakeSetupDialog.ui b/Source/QtDialog/CMakeSetupDialog.ui index 6e13673..fb80cc0 100644 --- a/Source/QtDialog/CMakeSetupDialog.ui +++ b/Source/QtDialog/CMakeSetupDialog.ui @@ -150,6 +150,22 @@ + + + Add New Entry + + + Add Entry + + + :/Icons/Plus16.png + + + Qt::ToolButtonTextBesideIcon + + + + Remove Selected Entries diff --git a/Source/QtDialog/Plus16.png b/Source/QtDialog/Plus16.png new file mode 100644 index 0000000..552f6f0 Binary files /dev/null and b/Source/QtDialog/Plus16.png differ diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 48a9c57..92fca88 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -148,9 +148,13 @@ void QCMake::generate() emit this->generateDone(err); } -void QCMake::setProperties(const QCMakeCachePropertyList& props) +void QCMake::setProperties(const QCMakeCachePropertyList& newProps) { + QCMakeCachePropertyList props = newProps; + QStringList toremove; + + // set the value of properties cmCacheManager *cachem = this->CMakeInstance->GetCacheManager(); for(cmCacheManager::CacheIterator i = cachem->NewIterator(); !i.IsAtEnd(); i.Next()) @@ -180,15 +184,50 @@ void QCMake::setProperties(const QCMakeCachePropertyList& props) { i.SetValue(prop.Value.toString().toAscii().data()); } + props.removeAt(idx); } } + // remove some properites foreach(QString s, toremove) { cachem->RemoveCacheEntry(s.toAscii().data()); } + // add some new properites + foreach(QCMakeCacheProperty s, props) + { + if(s.Type == QCMakeCacheProperty::BOOL) + { + this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(), + s.Value.toBool() ? "ON" : "OFF", + s.Help.toAscii().data(), + cmCacheManager::BOOL); + } + else if(s.Type == QCMakeCacheProperty::STRING) + { + this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(), + s.Value.toString().toAscii().data(), + s.Help.toAscii().data(), + cmCacheManager::STRING); + } + else if(s.Type == QCMakeCacheProperty::PATH) + { + this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(), + s.Value.toString().toAscii().data(), + s.Help.toAscii().data(), + cmCacheManager::PATH); + } + else if(s.Type == QCMakeCacheProperty::FILEPATH) + { + this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(), + s.Value.toString().toAscii().data(), + s.Help.toAscii().data(), + cmCacheManager::FILEPATH); + } + } + cachem->SaveCache(this->BinaryDirectory.toAscii().data()); } diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index b1dbf6f..3ded470 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -40,10 +40,12 @@ QCMakeCacheView::QCMakeCacheView(QWidget* p) this->AdvancedFilter->setSourceModel(this->CacheModel); this->AdvancedFilter->setFilterRole(QCMakeCacheModel::AdvancedRole); this->AdvancedFilter->setFilterRegExp(AdvancedRegExp[0]); + this->AdvancedFilter->setDynamicSortFilter(true); this->SearchFilter = new QSortFilterProxyModel(this); this->SearchFilter->setSourceModel(this->AdvancedFilter); this->SearchFilter->setFilterCaseSensitivity(Qt::CaseInsensitive); this->SearchFilter->setFilterKeyColumn(-1); // all columns + this->SearchFilter->setDynamicSortFilter(true); this->setModel(this->SearchFilter); // our delegate for creating our editors @@ -296,6 +298,19 @@ bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, i this->Properties[idx.row()].Value = value.toInt() == Qt::Checked; emit this->dataChanged(idx, idx); } + else if(role == QCMakeCacheModel::HelpRole) + { + this->Properties[idx.row()].Help = value.toString(); + emit this->dataChanged(idx, idx); + } + else if(role == QCMakeCacheModel::TypeRole) + { + this->Properties[idx.row()].Type = static_cast(value.toInt()); + } + else if(role == QCMakeCacheModel::AdvancedRole) + { + this->Properties[idx.row()].Advanced = value.toBool(); + } return false; } @@ -327,6 +342,26 @@ bool QCMakeCacheModel::removeRows(int row, int num, const QModelIndex&) return true; } +bool QCMakeCacheModel::insertRows(int row, int num, const QModelIndex&) +{ + if(row < 0) + row = 0; + if(row > this->rowCount()) + row = this->rowCount(); + + this->beginInsertRows(QModelIndex(), row, row+num-1); + for(int i=0; iProperties.insert(row+i, QCMakeCacheProperty()); + if(this->NewCount >= row) + { + this->NewCount++; + } + } + this->endInsertRows(); + return true; +} + QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p) : QItemDelegate(p) { @@ -342,18 +377,18 @@ QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p, } else if(type == QCMakeCacheProperty::PATH) { - return new QCMakeCachePathEditor(false, p); + return new QCMakeCachePathEditor(p); } else if(type == QCMakeCacheProperty::FILEPATH) { - return new QCMakeCachePathEditor(true, p); + return new QCMakeCacheFilePathEditor(p); } return new QLineEdit(p); } -QCMakeCachePathEditor::QCMakeCachePathEditor(bool fp, QWidget* p) - : QLineEdit(p), IsFilePath(fp) +QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p) + : QLineEdit(p) { // this *is* instead of has a line edit so QAbstractItemView // doesn't get confused with what the editor really is @@ -363,18 +398,28 @@ QCMakeCachePathEditor::QCMakeCachePathEditor(bool fp, QWidget* p) this->ToolButton->setCursor(QCursor(Qt::ArrowCursor)); QObject::connect(this->ToolButton, SIGNAL(clicked(bool)), this, SLOT(chooseFile())); +} + +QCMakeCacheFilePathEditor::QCMakeCacheFilePathEditor(QWidget* p) + : QCMakeCacheFileEditor(p) +{ QCompleter* comp = new QCompleter(this); QDirModel* model = new QDirModel(comp); - if(!fp) - { - // only dirs - model->setFilter(QDir::AllDirs | QDir::Drives); - } comp->setModel(model); this->setCompleter(comp); } -void QCMakeCachePathEditor::resizeEvent(QResizeEvent* e) +QCMakeCachePathEditor::QCMakeCachePathEditor(QWidget* p) + : QCMakeCacheFileEditor(p) +{ + QCompleter* comp = new QCompleter(this); + QDirModel* model = new QDirModel(comp); + model->setFilter(QDir::AllDirs | QDir::Drives); + comp->setModel(model); + this->setCompleter(comp); +} + +void QCMakeCacheFileEditor::resizeEvent(QResizeEvent* e) { // make the tool button fit on the right side int h = e->size().height(); @@ -383,21 +428,26 @@ void QCMakeCachePathEditor::resizeEvent(QResizeEvent* e) this->setContentsMargins(0, 0, h, 0); } -void QCMakeCachePathEditor::chooseFile() +void QCMakeCacheFilePathEditor::chooseFile() { // choose a file and set it QString path; - if(this->IsFilePath) - { - QFileInfo info(this->text()); - path = QFileDialog::getOpenFileName(this, tr("Select File"), - info.absolutePath()); - } - else + QFileInfo info(this->text()); + path = QFileDialog::getOpenFileName(this, tr("Select File"), + info.absolutePath()); + + if(!path.isEmpty()) { - path = QFileDialog::getExistingDirectory(this, tr("Select Path"), - this->text()); + this->setText(path); } +} + +void QCMakeCachePathEditor::chooseFile() +{ + // choose a file and set it + QString path; + path = QFileDialog::getExistingDirectory(this, tr("Select Path"), + this->text()); if(!path.isEmpty()) { this->setText(path); diff --git a/Source/QtDialog/QCMakeCacheView.h b/Source/QtDialog/QCMakeCacheView.h index a6ddbf2..b427af5 100644 --- a/Source/QtDialog/QCMakeCacheView.h +++ b/Source/QtDialog/QCMakeCacheView.h @@ -68,17 +68,18 @@ public slots: void clear(); void setEditEnabled(bool); bool removeRows(int row, int count, const QModelIndex& idx = QModelIndex()); + bool insertRows(int row, int num, const QModelIndex&); public: // satisfy [pure] virtuals - int columnCount ( const QModelIndex & parent ) const; - QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole) const; - QModelIndex parent ( const QModelIndex & index ) const; - int rowCount ( const QModelIndex & parent ) const; - QVariant headerData ( int section, Qt::Orientation orient, int role ) const; - Qt::ItemFlags flags ( const QModelIndex& index ) const; - bool setData ( const QModelIndex& index, const QVariant& value, int role ); - QModelIndex buddy ( const QModelIndex& index ) const; + int columnCount (const QModelIndex& parent) const; + QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; + QModelIndex parent (const QModelIndex& index) const; + int rowCount (const QModelIndex& parent = QModelIndex()) const; + QVariant headerData (int section, Qt::Orientation orient, int role) const; + Qt::ItemFlags flags (const QModelIndex& index) const; + bool setData (const QModelIndex& index, const QVariant& value, int role); + QModelIndex buddy (const QModelIndex& index) const; // get the properties QCMakeCachePropertyList properties() const; @@ -107,18 +108,33 @@ public: }; /// Editor widget for editing paths or file paths -class QCMakeCachePathEditor : public QLineEdit +class QCMakeCacheFileEditor : public QLineEdit { Q_OBJECT public: - QCMakeCachePathEditor(bool isFilePath, QWidget* p); + QCMakeCacheFileEditor(QWidget* p); protected slots: - void chooseFile(); + virtual void chooseFile() = 0; protected: void resizeEvent(QResizeEvent* e); - bool IsFilePath; QToolButton* ToolButton; }; +class QCMakeCachePathEditor : public QCMakeCacheFileEditor +{ + Q_OBJECT +public: + QCMakeCachePathEditor(QWidget* p = NULL); + void chooseFile(); +}; + +class QCMakeCacheFilePathEditor : public QCMakeCacheFileEditor +{ + Q_OBJECT +public: + QCMakeCacheFilePathEditor(QWidget* p = NULL); + void chooseFile(); +}; + #endif -- cgit v0.12