BUG: Don't prompt for unsaved changes if no changes were made.

ENH:  Error messages go to output window instead of message boxes.
This commit is contained in:
Clinton Stimpson 2007-11-09 15:18:49 -05:00
parent e5bb99e010
commit 57e46c74d4
6 changed files with 36 additions and 51 deletions

View File

@ -66,7 +66,7 @@ void QCMakeThread::run()
} }
CMakeSetupDialog::CMakeSetupDialog() CMakeSetupDialog::CMakeSetupDialog()
: ExitAfterGenerate(true) : ExitAfterGenerate(true), CacheModified(false)
{ {
// create the GUI // create the GUI
QSettings settings; QSettings settings;
@ -170,9 +170,8 @@ void CMakeSetupDialog::initialize()
this, SLOT(showProgress(QString,float))); this, SLOT(showProgress(QString,float)));
QObject::connect(this->CMakeThread->cmakeInstance(), QObject::connect(this->CMakeThread->cmakeInstance(),
SIGNAL(error(QString, QString, bool*)), SIGNAL(errorMessage(QString)),
this, SLOT(error(QString,QString,bool*)), this, SLOT(error(QString)));
Qt::BlockingQueuedConnection);
QObject::connect(this->InterruptButton, SIGNAL(clicked(bool)), QObject::connect(this->InterruptButton, SIGNAL(clicked(bool)),
this, SLOT(doInterrupt())); this, SLOT(doInterrupt()));
@ -191,15 +190,14 @@ void CMakeSetupDialog::initialize()
this, SLOT(updateGeneratorLabel(QString))); this, SLOT(updateGeneratorLabel(QString)));
this->updateGeneratorLabel(QString()); this->updateGeneratorLabel(QString());
QObject::connect(this->CacheValues->cacheModel(),
SIGNAL(dataChanged(QModelIndex, QModelIndex)),
this, SLOT(cacheModelDirty()));
QObject::connect(this->CacheValues->cacheModel(), SIGNAL(modelReset()),
this, SLOT(cacheModelDirty()));
QObject::connect(this->DeleteCacheButton, SIGNAL(clicked(bool)), QObject::connect(this->DeleteCacheButton, SIGNAL(clicked(bool)),
this, SLOT(doDeleteCache())); this, SLOT(doDeleteCache()));
QObject::connect(this->CacheValues->cacheModel(),
SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(setCacheModified()));
// get the saved binary directories // get the saved binary directories
QStringList buildPaths = this->loadBuildPaths(); QStringList buildPaths = this->loadBuildPaths();
this->BinaryDirectory->blockSignals(true); this->BinaryDirectory->blockSignals(true);
@ -284,7 +282,7 @@ void CMakeSetupDialog::finishConfigure(int err)
tr("Error in configuration process, project files may be invalid"), tr("Error in configuration process, project files may be invalid"),
QMessageBox::Ok); QMessageBox::Ok);
} }
else if(!this->CacheValues->cacheModel()->modifiedValues()) else if(0 == this->CacheValues->cacheModel()->newCount())
{ {
this->setGenerateEnabled(true); this->setGenerateEnabled(true);
} }
@ -329,7 +327,7 @@ void CMakeSetupDialog::closeEvent(QCloseEvent* e)
} }
// prompt for close if there are unsaved changes // prompt for close if there are unsaved changes
if(this->CacheValues->cacheModel()->modifiedValues()) if(this->CacheModified)
{ {
QString message = tr("You have changed options but not rebuilt, " QString message = tr("You have changed options but not rebuilt, "
"are you sure you want to exit?"); "are you sure you want to exit?");
@ -426,6 +424,7 @@ void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir) void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
{ {
this->CacheModified = false;
this->CacheValues->cacheModel()->clear(); this->CacheValues->cacheModel()->clear();
this->Output->clear(); this->Output->clear();
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
@ -442,18 +441,9 @@ void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
this->ProgressBar->setValue(qRound(percent * 100)); this->ProgressBar->setValue(qRound(percent * 100));
} }
void CMakeSetupDialog::error(const QString& title, const QString& message, void CMakeSetupDialog::error(const QString& message)
bool* cancel)
{ {
QMessageBox::StandardButton btn; this->Output->append(QString("<b><font color=red>%1</font></b>").arg(message));
QString msg = message + "\n\n" +
tr("(Press cancel to suppress any further messages.)");
btn = QMessageBox::critical(this, title, msg,
QMessageBox::Ok | QMessageBox::Cancel);
if(btn == QMessageBox::Cancel)
{
*cancel = false;
}
} }
void CMakeSetupDialog::setEnabledState(bool enabled) void CMakeSetupDialog::setEnabledState(bool enabled)
@ -562,14 +552,6 @@ void CMakeSetupDialog::setExitAfterGenerate(bool b)
*/ */
} }
void CMakeSetupDialog::cacheModelDirty()
{
if(this->CacheValues->cacheModel()->modifiedValues())
{
this->setGenerateEnabled(false);
}
}
void CMakeSetupDialog::setGenerateEnabled(bool b) void CMakeSetupDialog::setGenerateEnabled(bool b)
{ {
this->GenerateButton->setEnabled(b); this->GenerateButton->setEnabled(b);
@ -682,4 +664,11 @@ void CMakeSetupDialog::saveBuildPaths(const QStringList& paths)
settings.setValue(QString("WhereBuild%1").arg(i), paths[i]); settings.setValue(QString("WhereBuild%1").arg(i), paths[i]);
} }
} }
void CMakeSetupDialog::setCacheModified()
{
this->CacheModified = true;
this->setGenerateEnabled(false);
}

View File

@ -49,7 +49,7 @@ protected slots:
void doInterrupt(); void doInterrupt();
void finishConfigure(int error); void finishConfigure(int error);
void finishGenerate(int error); void finishGenerate(int error);
void error(const QString& title, const QString& message, bool* cancel); void error(const QString& message);
void doSourceBrowse(); void doSourceBrowse();
void doBinaryBrowse(); void doBinaryBrowse();
@ -61,13 +61,13 @@ protected slots:
void promptForGenerator(); void promptForGenerator();
void updateGeneratorLabel(const QString& gen); void updateGeneratorLabel(const QString& gen);
void setExitAfterGenerate(bool); void setExitAfterGenerate(bool);
void cacheModelDirty();
void setGenerateEnabled(bool); void setGenerateEnabled(bool);
void addBinaryPath(const QString&); void addBinaryPath(const QString&);
QStringList loadBuildPaths(); QStringList loadBuildPaths();
void saveBuildPaths(const QStringList&); void saveBuildPaths(const QStringList&);
void onBinaryDirectoryChanged(const QString& dir); void onBinaryDirectoryChanged(const QString& dir);
void onSourceDirectoryChanged(const QString& dir); void onSourceDirectoryChanged(const QString& dir);
void setCacheModified();
protected: protected:
void closeEvent(QCloseEvent*); void closeEvent(QCloseEvent*);
@ -76,6 +76,7 @@ protected:
QCMakeThread* CMakeThread; QCMakeThread* CMakeThread;
bool ExitAfterGenerate; bool ExitAfterGenerate;
bool CacheModified;
QAction* ReloadCacheAction; QAction* ReloadCacheAction;
QAction* DeleteCacheAction; QAction* DeleteCacheAction;
QAction* ExitAction; QAction* ExitAction;

View File

@ -255,11 +255,11 @@ void QCMake::progressCallback(const char* msg, float percent, void* cd)
} }
} }
void QCMake::errorCallback(const char* msg, const char* title, void QCMake::errorCallback(const char* msg, const char* /*title*/,
bool& stop, void* cd) bool& /*stop*/, void* cd)
{ {
QCMake* self = reinterpret_cast<QCMake*>(cd); QCMake* self = reinterpret_cast<QCMake*>(cd);
emit self->error(title, msg, &stop); emit self->errorMessage(msg);
} }
QString QCMake::binaryDirectory() const QString QCMake::binaryDirectory() const

View File

@ -105,8 +105,6 @@ signals:
void propertiesChanged(const QCMakeCachePropertyList& vars); void propertiesChanged(const QCMakeCachePropertyList& vars);
/// signal when the generator changes /// signal when the generator changes
void generatorChanged(const QString& gen); void generatorChanged(const QString& gen);
/// signal when there is an error message
void error(const QString& title, const QString& message, bool*);
/// signal when the source directory changes (binary directory already /// signal when the source directory changes (binary directory already
/// containing a CMakeCache.txt file) /// containing a CMakeCache.txt file)
void sourceDirChanged(const QString& dir); void sourceDirChanged(const QString& dir);
@ -118,6 +116,8 @@ signals:
void generateDone(int error); void generateDone(int error);
/// signal when there is an output message /// signal when there is an output message
void outputMessage(const QString& msg); void outputMessage(const QString& msg);
/// signal when there is an error message
void errorMessage(const QString& msg);
protected: protected:
cmake* CMakeInstance; cmake* CMakeInstance;

View File

@ -207,7 +207,7 @@ void QCMakeCacheView::setSearchFilter(const QString& s)
QCMakeCacheModel::QCMakeCacheModel(QObject* p) QCMakeCacheModel::QCMakeCacheModel(QObject* p)
: QAbstractTableModel(p), : QAbstractTableModel(p),
NewCount(0), ModifiedValues(false), EditEnabled(true) NewCount(0), EditEnabled(true)
{ {
} }
@ -215,11 +215,6 @@ QCMakeCacheModel::~QCMakeCacheModel()
{ {
} }
bool QCMakeCacheModel::modifiedValues() const
{
return this->ModifiedValues;
}
static uint qHash(const QCMakeCacheProperty& p) static uint qHash(const QCMakeCacheProperty& p)
{ {
return qHash(p.Key); return qHash(p.Key);
@ -247,7 +242,6 @@ void QCMakeCacheModel::setProperties(const QCMakeCachePropertyList& props)
qSort(tmp); qSort(tmp);
this->Properties += tmp; this->Properties += tmp;
this->ModifiedValues = NewCount != 0;
this->reset(); this->reset();
} }
@ -266,6 +260,11 @@ bool QCMakeCacheModel::editEnabled() const
return this->EditEnabled; return this->EditEnabled;
} }
int QCMakeCacheModel::newCount() const
{
return this->NewCount;
}
int QCMakeCacheModel::columnCount (const QModelIndex& /*p*/ ) const int QCMakeCacheModel::columnCount (const QModelIndex& /*p*/ ) const
{ {
return 2; return 2;
@ -361,19 +360,16 @@ bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, i
if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole)) if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole))
{ {
this->Properties[idx.row()].Key = value.toString(); this->Properties[idx.row()].Key = value.toString();
this->ModifiedValues = true;
emit this->dataChanged(idx, idx); emit this->dataChanged(idx, idx);
} }
else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole)) else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
{ {
this->Properties[idx.row()].Value = value.toString(); this->Properties[idx.row()].Value = value.toString();
this->ModifiedValues = true;
emit this->dataChanged(idx, idx); emit this->dataChanged(idx, idx);
} }
else if(idx.column() == 1 && (role == Qt::CheckStateRole)) else if(idx.column() == 1 && (role == Qt::CheckStateRole))
{ {
this->Properties[idx.row()].Value = value.toInt() == Qt::Checked; this->Properties[idx.row()].Value = value.toInt() == Qt::Checked;
this->ModifiedValues = true;
emit this->dataChanged(idx, idx); emit this->dataChanged(idx, idx);
} }
return false; return false;

View File

@ -81,18 +81,17 @@ public:
bool setData ( const QModelIndex& index, const QVariant& value, int role ); bool setData ( const QModelIndex& index, const QVariant& value, int role );
QModelIndex buddy ( const QModelIndex& index ) const; QModelIndex buddy ( const QModelIndex& index ) const;
// flag if a cache property has been modified
bool modifiedValues() const;
// get the properties // get the properties
QCMakeCachePropertyList properties() const; QCMakeCachePropertyList properties() const;
// editing enabled // editing enabled
bool editEnabled() const; bool editEnabled() const;
int newCount() const;
protected: protected:
QCMakeCachePropertyList Properties; QCMakeCachePropertyList Properties;
int NewCount; int NewCount;
bool ModifiedValues;
bool EditEnabled; bool EditEnabled;
}; };