diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index ce7c78607..cafff1da8 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -108,6 +108,9 @@ CMakeSetupDialog::CMakeSetupDialog() this->GenerateAction = ToolsMenu->addAction(tr("&Generate")); QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)), this, SLOT(doGenerate())); + QAction* showChangesAction = ToolsMenu->addAction(tr("&Show My Changes")); + QObject::connect(showChangesAction, SIGNAL(triggered(bool)), + this, SLOT(showUserChanges())); #if defined(Q_WS_MAC) this->InstallForCommandLineAction = ToolsMenu->addAction(tr("&Install For Command Line Use")); @@ -512,6 +515,7 @@ void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir) { this->CacheModified = false; this->CacheValues->cacheModel()->clear(); + qobject_cast(this->CacheValues->itemDelegate())->clearChanges(); this->Output->clear(); QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "setBinaryDirectory", Qt::QueuedConnection, Q_ARG(QString, dir)); @@ -962,3 +966,68 @@ void CMakeSetupDialog::setViewType(int v) } +void CMakeSetupDialog::showUserChanges() +{ + QSet changes = + qobject_cast(this->CacheValues->itemDelegate())->changes(); + + QDialog dialog(this); + dialog.setWindowTitle(tr("My Changes")); + dialog.resize(600, 400); + QVBoxLayout* l = new QVBoxLayout(&dialog); + QTextEdit* textedit = new QTextEdit(&dialog); + textedit->setReadOnly(true); + l->addWidget(textedit); + QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok, + Qt::Horizontal, &dialog); + QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept())); + l->addWidget(btns); + + QString command; + QString cache; + + foreach(QCMakeProperty prop, changes) + { + QString type; + switch(prop.Type) + { + case QCMakeProperty::BOOL: + type = "BOOL"; + break; + case QCMakeProperty::PATH: + type = "PATH"; + break; + case QCMakeProperty::FILEPATH: + type = "FILEPATH"; + break; + case QCMakeProperty::STRING: + type = "STRING"; + break; + } + QString value; + if(prop.Type == QCMakeProperty::BOOL) + { + value = prop.Value.toBool() ? "1" : "0"; + } + else + { + value = prop.Value.toString(); + } + + QString line("%1:%2="); + line = line.arg(prop.Key); + line = line.arg(type); + + command += QString("-D%1\"%2\" ").arg(line).arg(value); + cache += QString("%1%2\n").arg(line).arg(value); + } + + textedit->append(tr("Commandline options:")); + textedit->append(command); + textedit->append("\n"); + textedit->append(tr("Cache file:")); + textedit->append(cache); + + dialog.exec(); +} + diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h index 964ed6111..e75805656 100644 --- a/Source/QtDialog/CMakeSetupDialog.h +++ b/Source/QtDialog/CMakeSetupDialog.h @@ -76,6 +76,7 @@ protected slots: void startSearch(); void setDebugOutput(bool); void setViewType(int); + void showUserChanges(); protected: diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 79965594d..b98ffd35b 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include "QCMakeWidgets.h" @@ -633,14 +634,22 @@ bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model, Qt::CheckState state = (static_cast(value.toInt()) == Qt::Checked ? Qt::Unchecked : Qt::Checked); - return model->setData(index, state, Qt::CheckStateRole); + bool success = model->setData(index, state, Qt::CheckStateRole); + if(success) + { + this->recordChange(model, index); + } + return success; } +// Issue 205903 fixed in Qt 4.5.0. +// Can remove this function and FileDialogFlag when minimum Qt version is 4.5 bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event) { // workaround for what looks like a bug in Qt on Mac OS X // where it doesn't create a QWidget wrapper for the native file dialog // so the Qt library ends up assuming the focus was lost to something else + if(event->type() == QEvent::FocusOut && this->FileDialogFlag) { return false; @@ -648,4 +657,47 @@ bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event) return QItemDelegate::eventFilter(object, event); } +void QCMakeCacheModelDelegate::setModelData(QWidget* editor, + QAbstractItemModel* model, const QModelIndex& index ) const +{ + QItemDelegate::setModelData(editor, model, index); + const_cast(this)->recordChange(model, index); +} +QSet QCMakeCacheModelDelegate::changes() const +{ + return mChanges; +} + +void QCMakeCacheModelDelegate::clearChanges() +{ + mChanges.clear(); +} + +void QCMakeCacheModelDelegate::recordChange(QAbstractItemModel* model, const QModelIndex& index) +{ + QModelIndex idx = index; + QAbstractItemModel* mymodel = model; + while(qobject_cast(mymodel)) + { + idx = static_cast(mymodel)->mapToSource(idx); + mymodel = static_cast(mymodel)->sourceModel(); + } + QCMakeCacheModel* cache_model = qobject_cast(mymodel); + if(cache_model && idx.isValid()) + { + QCMakeProperty property; + idx = idx.sibling(idx.row(), 0); + cache_model->getPropertyData(idx, property); + + // clean out an old one + QSet::iterator iter = mChanges.find(property); + if(iter != mChanges.end()) + { + mChanges.erase(iter); + } + // now add the new item + mChanges.insert(property); + } +} + diff --git a/Source/QtDialog/QCMakeCacheView.h b/Source/QtDialog/QCMakeCacheView.h index 77422ecb9..d5005d052 100644 --- a/Source/QtDialog/QCMakeCacheView.h +++ b/Source/QtDialog/QCMakeCacheView.h @@ -20,6 +20,7 @@ #include "QCMake.h" #include +#include #include #include @@ -111,6 +112,10 @@ public: // return flags (overloaded to modify flag based on EditEnabled flag) Qt::ItemFlags flags (const QModelIndex& index) const; QModelIndex buddy(const QModelIndex& idx) const; + + // get the data in the model for this property + void getPropertyData(const QModelIndex& idx1, + QCMakeProperty& prop) const; protected: bool EditEnabled; @@ -120,9 +125,6 @@ protected: // set the data in the model for this property void setPropertyData(const QModelIndex& idx1, const QCMakeProperty& p, bool isNew); - // get the data in the model for this property - void getPropertyData(const QModelIndex& idx1, - QCMakeProperty& prop) const; // breaks up he property list into groups // where each group has the same prefix up to the first underscore @@ -147,10 +149,21 @@ public: bool editorEvent (QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index); bool eventFilter(QObject* object, QEvent* event); + void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const; + + QSet changes() const; + void clearChanges(); + protected slots: void setFileDialogFlag(bool); protected: bool FileDialogFlag; + // record a change to an item in the model. + // this simply saves the item in the set of changes + void recordChange(QAbstractItemModel* model, const QModelIndex& index); + + // properties changed by user via this delegate + QSet mChanges; }; #endif