diff options
author | Clinton Stimpson <clinton@elemtech.com> | 2007-11-08 15:17:37 (GMT) |
---|---|---|
committer | Clinton Stimpson <clinton@elemtech.com> | 2007-11-08 15:17:37 (GMT) |
commit | 9f676df3c6daddc0d6d2d8d2907b2ce707ceebaf (patch) | |
tree | 5409c6b3d32eca167ddfe312cb3a9c1df02b7215 /Source/QtDialog | |
parent | e3572607f4097fbc07bebbfbfe333adc16e43195 (diff) | |
download | CMake-9f676df3c6daddc0d6d2d8d2907b2ce707ceebaf.zip CMake-9f676df3c6daddc0d6d2d8d2907b2ce707ceebaf.tar.gz CMake-9f676df3c6daddc0d6d2d8d2907b2ce707ceebaf.tar.bz2 |
ENH: add context menu for deleting, ignoring, and getting help for cache entries.
ENH: add delete cache button
ENH: add information string above configure/generate buttons
ENH: change search to search both columns, and from regex to plain string search
ENH: add buddy info in cache entry view, so double clicking in the left column
starts editing the associated value.
BUG: fix file path editor so it goes away when focus is lost
Diffstat (limited to 'Source/QtDialog')
-rw-r--r-- | Source/QtDialog/CMakeSetupDialog.cxx | 6 | ||||
-rw-r--r-- | Source/QtDialog/CMakeSetupDialog.ui | 29 | ||||
-rw-r--r-- | Source/QtDialog/QCMake.cxx | 33 | ||||
-rw-r--r-- | Source/QtDialog/QCMakeCacheView.cxx | 151 | ||||
-rw-r--r-- | Source/QtDialog/QCMakeCacheView.h | 15 |
5 files changed, 197 insertions, 37 deletions
diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 650a7a6..2bb470d 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -77,7 +77,7 @@ CMakeSetupDialog::CMakeSetupDialog() QWidget* cont = new QWidget(this); this->setupUi(cont); - this->Splitter->setStretchFactor(0, 2); + this->Splitter->setStretchFactor(0, 3); this->Splitter->setStretchFactor(1, 1); this->setCentralWidget(cont); this->ProgressBar->reset(); @@ -196,6 +196,9 @@ void CMakeSetupDialog::initialize() this, SLOT(cacheModelDirty())); QObject::connect(this->CacheValues->cacheModel(), SIGNAL(modelReset()), this, SLOT(cacheModelDirty())); + + QObject::connect(this->DeleteCacheButton, SIGNAL(clicked(bool)), + this, SLOT(doDeleteCache())); // get the saved binary directories QStringList buildPaths = this->loadBuildPaths(); @@ -464,6 +467,7 @@ void CMakeSetupDialog::setEnabledState(bool enabled) this->ConfigureButton->setEnabled(enabled); this->ReloadCacheAction->setEnabled(enabled); this->DeleteCacheAction->setEnabled(enabled); + this->DeleteCacheButton->setEnabled(enabled); this->ExitAction->setEnabled(enabled); this->ConfigureAction->setEnabled(enabled); // generate button/action are handled separately diff --git a/Source/QtDialog/CMakeSetupDialog.ui b/Source/QtDialog/CMakeSetupDialog.ui index ba27cd8..ade3cbf 100644 --- a/Source/QtDialog/CMakeSetupDialog.ui +++ b/Source/QtDialog/CMakeSetupDialog.ui @@ -5,8 +5,8 @@ <rect> <x>0</x> <y>0</y> - <width>693</width> - <height>582</height> + <width>705</width> + <height>495</height> </rect> </property> <layout class="QGridLayout" > @@ -140,6 +140,9 @@ <property name="alternatingRowColors" > <bool>true</bool> </property> + <property name="selectionMode" > + <enum>QAbstractItemView::ExtendedSelection</enum> + </property> <property name="selectionBehavior" > <enum>QAbstractItemView::SelectRows</enum> </property> @@ -154,7 +157,7 @@ </widget> </widget> </item> - <item row="3" column="0" > + <item row="4" column="0" > <layout class="QHBoxLayout" > <item> <widget class="QPushButton" name="ConfigureButton" > @@ -171,6 +174,13 @@ </widget> </item> <item> + <widget class="QPushButton" name="DeleteCacheButton" > + <property name="text" > + <string>Delete Cache</string> + </property> + </widget> + </item> + <item> <spacer> <property name="orientation" > <enum>Qt::Horizontal</enum> @@ -205,6 +215,19 @@ </item> </layout> </item> + <item row="3" column="0" > + <widget class="QLabel" name="label_3" > + <property name="text" > + <string>Right click on a cache value for additional options (delete, ignore, and help).<br>Press Configure to update and display new values in red, then press Generate to generate selected build files.</string> + </property> + <property name="alignment" > + <set>Qt::AlignCenter</set> + </property> + <property name="wordWrap" > + <bool>true</bool> + </property> + </widget> + </item> </layout> </widget> <customwidgets> diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 0621aaf..bfa5af9 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -150,22 +150,45 @@ void QCMake::generate() void QCMake::setProperties(const QCMakeCachePropertyList& props) { + QStringList toremove; cmCacheManager *cachem = this->CMakeInstance->GetCacheManager(); - cmCacheManager::CacheIterator it = cachem->NewIterator(); - foreach(QCMakeCacheProperty prop, props) + for(cmCacheManager::CacheIterator i = cachem->NewIterator(); + !i.IsAtEnd(); i.Next()) { - if ( it.Find(prop.Key.toAscii().data()) ) + + if(i.GetType() == cmCacheManager::INTERNAL || + i.GetType() == cmCacheManager::STATIC) + { + continue; + } + + QCMakeCacheProperty prop; + prop.Key = i.GetName(); + int idx = props.indexOf(prop); + if(idx == -1) { + toremove.append(i.GetName()); + } + else + { + prop = props[idx]; if(prop.Value.type() == QVariant::Bool) { - it.SetValue(prop.Value.toBool() ? "ON" : "OFF"); + i.SetValue(prop.Value.toBool() ? "ON" : "OFF"); } else { - it.SetValue(prop.Value.toString().toAscii().data()); + i.SetValue(prop.Value.toString().toAscii().data()); } } + } + + foreach(QString s, toremove) + { + cachem->RemoveCacheEntry(s.toAscii().data()); + } + cachem->SaveCache(this->BinaryDirectory.toAscii().data()); } diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 1937f24..cfa875d 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -25,6 +25,10 @@ #include <QFileInfo> #include <QStyle> #include <QKeyEvent> +#include <QMenu> +#include <QDialog> +#include <QLabel> +#include <QDialogButtonBox> static QRegExp AdvancedRegExp[2] = { QRegExp("(false)"), QRegExp("(true|false)") }; @@ -40,6 +44,7 @@ QCMakeCacheView::QCMakeCacheView(QWidget* p) this->SearchFilter = new QSortFilterProxyModel(this); this->SearchFilter->setSourceModel(this->AdvancedFilter); this->SearchFilter->setFilterCaseSensitivity(Qt::CaseInsensitive); + this->SearchFilter->setFilterKeyColumn(-1); // all columns this->setModel(this->SearchFilter); // our delegate for creating our editors @@ -72,6 +77,81 @@ QCMakeCacheModel* QCMakeCacheView::cacheModel() const { return this->CacheModel; } + +void QCMakeCacheView::contextMenuEvent(QContextMenuEvent* /*e*/) +{ + QList<QModelIndex> idxs = this->selectionModel()->selectedRows(); + + if(idxs.count()) + { + QMenu* menu = new QMenu(this); + QAction* d = NULL; + QAction* i = NULL; + if(this->cacheModel()->editEnabled()) + { + QString t = idxs.count() > 1 ? tr("Delete Cache Entries") : + tr("Delete Cache Entry"); + d = menu->addAction(t); + t = idxs.count() > 1 ? tr("Ignore Cache Entries") : + tr("Ignore Cache Entry"); + i = menu->addAction(t); + } + QAction* h = menu->addAction(tr("Help For Cache Entry")); + QAction* which = menu->exec(QCursor::pos()); + if(!which) + { + return; + } + + if(which == h) + { + QModelIndex idx = this->selectionModel()->currentIndex(); + idx = this->SearchFilter->mapToSource(idx); + idx = this->AdvancedFilter->mapToSource(idx); + idx = this->cacheModel()->index(idx.row(), 0); + QString msg = this->cacheModel()->data(idx, Qt::DisplayRole).toString() + + "\n\n" + + this->cacheModel()->data(idx, QCMakeCacheModel::HelpRole).toString(); + QDialog dialog; + dialog.setWindowTitle(tr("CMakeSetup Help")); + QVBoxLayout* l = new QVBoxLayout(&dialog); + QLabel* lab = new QLabel(&dialog); + l->addWidget(lab); + lab->setText(msg); + lab->setWordWrap(true); + QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok, + Qt::Horizontal, &dialog); + QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept())); + l->addWidget(btns); + dialog.exec(); + } + else + { + QList<QPersistentModelIndex> pidxs; + foreach(QModelIndex i, idxs) + { + i = this->SearchFilter->mapToSource(i); + i = this->AdvancedFilter->mapToSource(i); + pidxs.append(i); + } + if(which == d) + { + foreach(QPersistentModelIndex j, pidxs) + { + this->cacheModel()->removeRows(j.row(), 1); + } + } + else if(which == i) + { + foreach(QPersistentModelIndex j, pidxs) + { + j = this->cacheModel()->index(j.row(), 1); + this->cacheModel()->setData(j, "IGNORE", Qt::DisplayRole); + } + } + } + } +} QModelIndex QCMakeCacheView::moveCursor(CursorAction act, Qt::KeyboardModifiers mod) @@ -120,7 +200,7 @@ bool QCMakeCacheView::showAdvanced() const void QCMakeCacheView::setSearchFilter(const QString& s) { - this->SearchFilter->setFilterRegExp(s); + this->SearchFilter->setFilterFixedString(s); } QCMakeCacheModel::QCMakeCacheModel(QObject* p) @@ -297,7 +377,30 @@ bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, i return false; } - +QModelIndex QCMakeCacheModel::buddy ( const QModelIndex& idx ) const +{ + if(idx.column() == 0) + { + return this->index(idx.row(), 1); + } + return idx; +} + +bool QCMakeCacheModel::removeRows(int row, int, const QModelIndex&) +{ + if(row < 0 || row >= this->Properties.count()) + { + return false; + } + this->beginRemoveRows(QModelIndex(), row, row); + this->Properties.removeAt(row); + if(this->NewCount >= row+1) + { + this->NewCount--; + } + this->endRemoveRows(); + return true; +} QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p) : QItemDelegate(p) @@ -314,52 +417,56 @@ QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p, } else if(type == QCMakeCacheProperty::PATH) { - return new QCMakeCachePathEditor(idx.data().toString(), false, p); + return new QCMakeCachePathEditor(false, p); } else if(type == QCMakeCacheProperty::FILEPATH) { - return new QCMakeCachePathEditor(idx.data().toString(), true, p); + return new QCMakeCachePathEditor(true, p); } return new QLineEdit(p); } -QCMakeCachePathEditor::QCMakeCachePathEditor(const QString& file, bool fp, - QWidget* p) - : QWidget(p), LineEdit(this), IsFilePath(fp) +QCMakeCachePathEditor::QCMakeCachePathEditor(bool fp, QWidget* p) + : QLineEdit(p), IsFilePath(fp) { - QHBoxLayout* l = new QHBoxLayout(this); - l->setMargin(0); - l->setSpacing(0); - l->addWidget(&this->LineEdit); - QToolButton* tb = new QToolButton(this); - tb->setText("..."); - l->addWidget(tb); - QObject::connect(tb, SIGNAL(clicked(bool)), + // this *is* instead of has a line edit so QAbstractItemView + // doesn't get confused with what the editor really is + this->setContentsMargins(0, 0, 0, 0); + this->ToolButton = new QToolButton(this); + this->ToolButton->setText("..."); + this->ToolButton->setCursor(QCursor(Qt::ArrowCursor)); + QObject::connect(this->ToolButton, SIGNAL(clicked(bool)), this, SLOT(chooseFile())); - this->LineEdit.setText(file); - this->LineEdit.selectAll(); - tb->setFocusProxy(&this->LineEdit); - this->setFocusProxy(&this->LineEdit); +} + +void QCMakeCachePathEditor::resizeEvent(QResizeEvent* e) +{ + // make the tool button fit on the right side + int h = e->size().height(); + this->ToolButton->resize(h, h); + this->ToolButton->move(this->width() - h, 0); + this->setContentsMargins(0, 0, h, 0); } void QCMakeCachePathEditor::chooseFile() { + // choose a file and set it QString path; if(this->IsFilePath) { - QFileInfo info(this->value()); + QFileInfo info(this->text()); path = QFileDialog::getOpenFileName(this, tr("Select File"), info.absolutePath()); } else { path = QFileDialog::getExistingDirectory(this, tr("Select Path"), - this->value()); + this->text()); } if(!path.isEmpty()) { - this->LineEdit.setText(path); + this->setText(path); } } diff --git a/Source/QtDialog/QCMakeCacheView.h b/Source/QtDialog/QCMakeCacheView.h index 52b154e..8e92b42 100644 --- a/Source/QtDialog/QCMakeCacheView.h +++ b/Source/QtDialog/QCMakeCacheView.h @@ -27,6 +27,7 @@ #include <QSortFilterProxyModel> class QCMakeCacheModel; +class QToolButton; /// Qt view class for cache properties @@ -44,6 +45,7 @@ public slots: void setSearchFilter(const QString&); protected: + void contextMenuEvent(QContextMenuEvent* e); QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers); void showEvent(QShowEvent* e); bool Init; @@ -66,16 +68,18 @@ public slots: void setProperties(const QCMakeCachePropertyList& props); void clear(); void setEditEnabled(bool); + bool removeRows(int row, int count, const QModelIndex& idx = QModelIndex()); public: // satisfy [pure] virtuals int columnCount ( const QModelIndex & parent ) const; - QVariant data ( const QModelIndex & index, int role ) 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; // flag if a cache property has been modified bool modifiedValues() const; @@ -105,18 +109,17 @@ public: }; /// Editor widget for editing paths or file paths -class QCMakeCachePathEditor : public QWidget +class QCMakeCachePathEditor : public QLineEdit { Q_OBJECT - Q_PROPERTY(QString value READ value USER true) public: - QCMakeCachePathEditor(const QString& file, bool isFilePath, QWidget* p); - QString value() const { return this->LineEdit.text(); } + QCMakeCachePathEditor(bool isFilePath, QWidget* p); protected slots: void chooseFile(); protected: - QLineEdit LineEdit; + void resizeEvent(QResizeEvent* e); bool IsFilePath; + QToolButton* ToolButton; }; #endif |