summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClinton Stimpson <clinton@elemtech.com>2009-07-17 18:38:36 (GMT)
committerClinton Stimpson <clinton@elemtech.com>2009-07-17 18:38:36 (GMT)
commit17acf0a310a8f10543c2be9fe902095a5a3c3c1d (patch)
tree4052fa5cd94ae8131c53db5c4e5ac358c581237d
parent3250cb3d3b5b4ed60e620ff78cad7fa8fb24113f (diff)
downloadCMake-17acf0a310a8f10543c2be9fe902095a5a3c3c1d.zip
CMake-17acf0a310a8f10543c2be9fe902095a5a3c3c1d.tar.gz
CMake-17acf0a310a8f10543c2be9fe902095a5a3c3c1d.tar.bz2
ENH: Add a "Show my changes" to the Tools menu.
Changes by the user are recorded and when requested, it shows -D arguments for commandline or contents for a cache file.
-rw-r--r--Source/QtDialog/CMakeSetupDialog.cxx69
-rw-r--r--Source/QtDialog/CMakeSetupDialog.h1
-rw-r--r--Source/QtDialog/QCMakeCacheView.cxx54
-rw-r--r--Source/QtDialog/QCMakeCacheView.h19
4 files changed, 139 insertions, 4 deletions
diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx
index ce7c786..cafff1d 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<QCMakeCacheModelDelegate*>(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<QCMakeProperty> changes =
+ qobject_cast<QCMakeCacheModelDelegate*>(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 964ed61..e758056 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 7996559..b98ffd3 100644
--- a/Source/QtDialog/QCMakeCacheView.cxx
+++ b/Source/QtDialog/QCMakeCacheView.cxx
@@ -23,6 +23,7 @@
#include <QStyle>
#include <QKeyEvent>
#include <QSortFilterProxyModel>
+#include <QMetaProperty>
#include "QCMakeWidgets.h"
@@ -633,14 +634,22 @@ bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model,
Qt::CheckState state = (static_cast<Qt::CheckState>(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<QCMakeCacheModelDelegate*>(this)->recordChange(model, index);
+}
+QSet<QCMakeProperty> 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<QAbstractProxyModel*>(mymodel))
+ {
+ idx = static_cast<QAbstractProxyModel*>(mymodel)->mapToSource(idx);
+ mymodel = static_cast<QAbstractProxyModel*>(mymodel)->sourceModel();
+ }
+ QCMakeCacheModel* cache_model = qobject_cast<QCMakeCacheModel*>(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<QCMakeProperty>::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 77422ec..d5005d0 100644
--- a/Source/QtDialog/QCMakeCacheView.h
+++ b/Source/QtDialog/QCMakeCacheView.h
@@ -20,6 +20,7 @@
#include "QCMake.h"
#include <QTreeView>
+#include <QSet>
#include <QStandardItemModel>
#include <QItemDelegate>
@@ -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<QCMakeProperty> 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<QCMakeProperty> mChanges;
};
#endif