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.
This commit is contained in:
parent
3250cb3d3b
commit
17acf0a310
@ -108,6 +108,9 @@ CMakeSetupDialog::CMakeSetupDialog()
|
|||||||
this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
|
this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
|
||||||
QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)),
|
QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)),
|
||||||
this, SLOT(doGenerate()));
|
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)
|
#if defined(Q_WS_MAC)
|
||||||
this->InstallForCommandLineAction
|
this->InstallForCommandLineAction
|
||||||
= ToolsMenu->addAction(tr("&Install For Command Line Use"));
|
= ToolsMenu->addAction(tr("&Install For Command Line Use"));
|
||||||
@ -512,6 +515,7 @@ void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
|
|||||||
{
|
{
|
||||||
this->CacheModified = false;
|
this->CacheModified = false;
|
||||||
this->CacheValues->cacheModel()->clear();
|
this->CacheValues->cacheModel()->clear();
|
||||||
|
qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())->clearChanges();
|
||||||
this->Output->clear();
|
this->Output->clear();
|
||||||
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
|
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
|
||||||
"setBinaryDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
|
"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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ protected slots:
|
|||||||
void startSearch();
|
void startSearch();
|
||||||
void setDebugOutput(bool);
|
void setDebugOutput(bool);
|
||||||
void setViewType(int);
|
void setViewType(int);
|
||||||
|
void showUserChanges();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <QMetaProperty>
|
||||||
|
|
||||||
#include "QCMakeWidgets.h"
|
#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::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
|
||||||
? Qt::Unchecked : 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)
|
bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event)
|
||||||
{
|
{
|
||||||
// workaround for what looks like a bug in Qt on Mac OS X
|
// 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
|
// 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
|
// so the Qt library ends up assuming the focus was lost to something else
|
||||||
|
|
||||||
if(event->type() == QEvent::FocusOut && this->FileDialogFlag)
|
if(event->type() == QEvent::FocusOut && this->FileDialogFlag)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -648,4 +657,47 @@ bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event)
|
|||||||
return QItemDelegate::eventFilter(object, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "QCMake.h"
|
#include "QCMake.h"
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
#include <QSet>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QItemDelegate>
|
#include <QItemDelegate>
|
||||||
|
|
||||||
@ -111,6 +112,10 @@ public:
|
|||||||
// return flags (overloaded to modify flag based on EditEnabled flag)
|
// return flags (overloaded to modify flag based on EditEnabled flag)
|
||||||
Qt::ItemFlags flags (const QModelIndex& index) const;
|
Qt::ItemFlags flags (const QModelIndex& index) const;
|
||||||
QModelIndex buddy(const QModelIndex& idx) 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:
|
protected:
|
||||||
bool EditEnabled;
|
bool EditEnabled;
|
||||||
@ -120,9 +125,6 @@ protected:
|
|||||||
// set the data in the model for this property
|
// set the data in the model for this property
|
||||||
void setPropertyData(const QModelIndex& idx1,
|
void setPropertyData(const QModelIndex& idx1,
|
||||||
const QCMakeProperty& p, bool isNew);
|
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
|
// breaks up he property list into groups
|
||||||
// where each group has the same prefix up to the first underscore
|
// where each group has the same prefix up to the first underscore
|
||||||
@ -147,10 +149,21 @@ public:
|
|||||||
bool editorEvent (QEvent* event, QAbstractItemModel* model,
|
bool editorEvent (QEvent* event, QAbstractItemModel* model,
|
||||||
const QStyleOptionViewItem& option, const QModelIndex& index);
|
const QStyleOptionViewItem& option, const QModelIndex& index);
|
||||||
bool eventFilter(QObject* object, QEvent* event);
|
bool eventFilter(QObject* object, QEvent* event);
|
||||||
|
void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const;
|
||||||
|
|
||||||
|
QSet<QCMakeProperty> changes() const;
|
||||||
|
void clearChanges();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void setFileDialogFlag(bool);
|
void setFileDialogFlag(bool);
|
||||||
protected:
|
protected:
|
||||||
bool FileDialogFlag;
|
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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user