cmake-gui: always enable generate button.

This commit is contained in:
Clinton Stimpson 2010-12-17 19:04:57 -07:00
parent d11c70295b
commit 3f158c6dfa
4 changed files with 150 additions and 55 deletions

View File

@ -55,7 +55,7 @@ void QCMakeThread::run()
} }
CMakeSetupDialog::CMakeSetupDialog() CMakeSetupDialog::CMakeSetupDialog()
: ExitAfterGenerate(true), CacheModified(false), CurrentState(Interrupting) : ExitAfterGenerate(true), CacheModified(false), ConfigureNeeded(true), CurrentState(Interrupting)
{ {
QString title = QString(tr("CMake %1")); QString title = QString(tr("CMake %1"));
title = title.arg(cmVersion::GetCMakeVersion()); title = title.arg(cmVersion::GetCMakeVersion());
@ -167,6 +167,9 @@ CMakeSetupDialog::CMakeSetupDialog()
this->CMakeThread->start(); this->CMakeThread->start();
this->enterState(ReadyConfigure); this->enterState(ReadyConfigure);
ProgressOffset = 0.0;
ProgressFactor = 1.0;
} }
void CMakeSetupDialog::initialize() void CMakeSetupDialog::initialize()
@ -179,12 +182,11 @@ void CMakeSetupDialog::initialize()
QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)), QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)),
this, SLOT(doConfigure())); this, SLOT(doConfigure()));
QObject::connect(this->CMakeThread->cmakeInstance(),
SIGNAL(configureDone(int)), QObject::connect(this->CMakeThread->cmakeInstance(), SIGNAL(configureDone(int)),
this, SLOT(finishConfigure(int))); this, SLOT(exitLoop(int)));
QObject::connect(this->CMakeThread->cmakeInstance(), QObject::connect(this->CMakeThread->cmakeInstance(), SIGNAL(generateDone(int)),
SIGNAL(generateDone(int)), this, SLOT(exitLoop(int)));
this, SLOT(finishGenerate(int)));
QObject::connect(this->GenerateButton, SIGNAL(clicked(bool)), QObject::connect(this->GenerateButton, SIGNAL(clicked(bool)),
this, SLOT(doGenerate())); this, SLOT(doGenerate()));
@ -270,15 +272,8 @@ CMakeSetupDialog::~CMakeSetupDialog()
this->CMakeThread->wait(2000); this->CMakeThread->wait(2000);
} }
void CMakeSetupDialog::doConfigure() bool CMakeSetupDialog::prepareConfigure()
{ {
if(this->CurrentState == Configuring)
{
// stop configure
doInterrupt();
return;
}
// make sure build directory exists // make sure build directory exists
QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory(); QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
QDir dir(bindir); QDir dir(bindir);
@ -295,7 +290,7 @@ void CMakeSetupDialog::doConfigure()
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
if(btn == QMessageBox::No) if(btn == QMessageBox::No)
{ {
return; return false;
} }
if(!dir.mkpath(".")) if(!dir.mkpath("."))
{ {
@ -303,7 +298,7 @@ void CMakeSetupDialog::doConfigure()
QString(tr("Failed to create directory %1")).arg(dir.path()), QString(tr("Failed to create directory %1")).arg(dir.path()),
QMessageBox::Ok); QMessageBox::Ok);
return; return false;
} }
} }
@ -312,27 +307,45 @@ void CMakeSetupDialog::doConfigure()
{ {
if(!this->setupFirstConfigure()) if(!this->setupFirstConfigure())
{ {
return; return false;
} }
} }
// remember path // remember path
this->addBinaryPath(dir.absolutePath()); this->addBinaryPath(dir.absolutePath());
this->enterState(Configuring); return true;
this->CacheValues->selectionModel()->clear();
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
"setProperties", Qt::QueuedConnection,
Q_ARG(QCMakePropertyList,
this->CacheValues->cacheModel()->properties()));
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
"configure", Qt::QueuedConnection);
} }
void CMakeSetupDialog::finishConfigure(int err) void CMakeSetupDialog::exitLoop(int err)
{ {
if(0 == err && !this->CacheValues->cacheModel()->newPropertyCount()) this->LocalLoop.exit(err);
}
void CMakeSetupDialog::doConfigure()
{
if(this->CurrentState == Configuring)
{
// stop configure
doInterrupt();
return;
}
if(!prepareConfigure())
{
return;
}
this->enterState(Configuring);
bool ret = doConfigureInternal();
if(ret)
{
this->ConfigureNeeded = false;
}
if(ret && !this->CacheValues->cacheModel()->newPropertyCount())
{ {
this->enterState(ReadyGenerate); this->enterState(ReadyGenerate);
} }
@ -341,6 +354,22 @@ void CMakeSetupDialog::finishConfigure(int err)
this->enterState(ReadyConfigure); this->enterState(ReadyConfigure);
this->CacheValues->scrollToTop(); this->CacheValues->scrollToTop();
} }
this->ProgressBar->reset();
}
bool CMakeSetupDialog::doConfigureInternal()
{
this->Output->clear();
this->CacheValues->selectionModel()->clear();
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
"setProperties", Qt::QueuedConnection,
Q_ARG(QCMakePropertyList,
this->CacheValues->cacheModel()->properties()));
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
"configure", Qt::QueuedConnection);
int err = this->LocalLoop.exec();
if(err != 0) if(err != 0)
{ {
@ -348,17 +377,8 @@ 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);
} }
}
void CMakeSetupDialog::finishGenerate(int err) return 0 == err;
{
this->enterState(ReadyConfigure);
if(err != 0)
{
QMessageBox::critical(this, tr("Error"),
tr("Error in generation process, project files may be invalid"),
QMessageBox::Ok);
}
} }
void CMakeSetupDialog::doInstallForCommandLine() void CMakeSetupDialog::doInstallForCommandLine()
@ -367,6 +387,23 @@ void CMakeSetupDialog::doInstallForCommandLine()
setupdialog.exec(); setupdialog.exec();
} }
bool CMakeSetupDialog::doGenerateInternal()
{
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
"generate", Qt::QueuedConnection);
int err = this->LocalLoop.exec();
if(err != 0)
{
QMessageBox::critical(this, tr("Error"),
tr("Error in generation process, project files may be invalid"),
QMessageBox::Ok);
}
return 0 == err;
}
void CMakeSetupDialog::doGenerate() void CMakeSetupDialog::doGenerate()
{ {
if(this->CurrentState == Generating) if(this->CurrentState == Generating)
@ -375,9 +412,43 @@ void CMakeSetupDialog::doGenerate()
doInterrupt(); doInterrupt();
return; return;
} }
// see if we need to configure
// we'll need to configure if:
// the configure step hasn't been done yet
// generate was the last step done
if(this->ConfigureNeeded)
{
if(!prepareConfigure())
{
return;
}
}
this->enterState(Generating); this->enterState(Generating);
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
"generate", Qt::QueuedConnection); bool config_passed = true;
if(this->ConfigureNeeded)
{
this->CacheValues->cacheModel()->setShowNewProperties(false);
this->ProgressFactor = 0.5;
config_passed = doConfigureInternal();
this->ProgressOffset = 0.5;
}
if(config_passed)
{
doGenerateInternal();
}
this->ProgressOffset = 0.0;
this->ProgressFactor = 1.0;
this->CacheValues->cacheModel()->setShowNewProperties(true);
this->enterState(ReadyConfigure);
this->ProgressBar->reset();
this->ConfigureNeeded = true;
} }
void CMakeSetupDialog::closeEvent(QCloseEvent* e) void CMakeSetupDialog::closeEvent(QCloseEvent* e)
@ -542,6 +613,7 @@ void CMakeSetupDialog::setSourceDirectory(const QString& dir)
void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent) void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
{ {
percent = (percent * ProgressFactor) + ProgressOffset;
this->ProgressBar->setValue(qRound(percent * 100)); this->ProgressBar->setValue(qRound(percent * 100));
} }
@ -883,7 +955,6 @@ void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
} }
else if(s == Configuring) else if(s == Configuring)
{ {
this->Output->clear();
this->setEnabledState(false); this->setEnabledState(false);
this->GenerateButton->setEnabled(false); this->GenerateButton->setEnabled(false);
this->GenerateAction->setEnabled(false); this->GenerateAction->setEnabled(false);
@ -899,17 +970,15 @@ void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
} }
else if(s == ReadyConfigure) else if(s == ReadyConfigure)
{ {
this->ProgressBar->reset();
this->setEnabledState(true); this->setEnabledState(true);
this->GenerateButton->setEnabled(false); this->GenerateButton->setEnabled(true);
this->GenerateAction->setEnabled(false); this->GenerateAction->setEnabled(true);
this->ConfigureButton->setEnabled(true); this->ConfigureButton->setEnabled(true);
this->ConfigureButton->setText(tr("&Configure")); this->ConfigureButton->setText(tr("&Configure"));
this->GenerateButton->setText(tr("&Generate")); this->GenerateButton->setText(tr("&Generate"));
} }
else if(s == ReadyGenerate) else if(s == ReadyGenerate)
{ {
this->ProgressBar->reset();
this->setEnabledState(true); this->setEnabledState(true);
this->GenerateButton->setEnabled(true); this->GenerateButton->setEnabled(true);
this->GenerateAction->setEnabled(true); this->GenerateAction->setEnabled(true);

View File

@ -16,6 +16,7 @@
#include "QCMake.h" #include "QCMake.h"
#include <QMainWindow> #include <QMainWindow>
#include <QThread> #include <QThread>
#include <QEventLoop>
#include "ui_CMakeSetupDialog.h" #include "ui_CMakeSetupDialog.h"
class QCMakeThread; class QCMakeThread;
@ -43,8 +44,6 @@ protected slots:
void doHelp(); void doHelp();
void doAbout(); void doAbout();
void doInterrupt(); void doInterrupt();
void finishConfigure(int error);
void finishGenerate(int error);
void error(const QString& message); void error(const QString& message);
void message(const QString& message); void message(const QString& message);
@ -74,6 +73,10 @@ protected slots:
void setGroupedView(bool); void setGroupedView(bool);
void showUserChanges(); void showUserChanges();
void setSearchFilter(const QString& str); void setSearchFilter(const QString& str);
bool prepareConfigure();
bool doConfigureInternal();
bool doGenerateInternal();
void exitLoop(int);
protected: protected:
@ -87,6 +90,7 @@ protected:
QCMakeThread* CMakeThread; QCMakeThread* CMakeThread;
bool ExitAfterGenerate; bool ExitAfterGenerate;
bool CacheModified; bool CacheModified;
bool ConfigureNeeded;
QAction* ReloadCacheAction; QAction* ReloadCacheAction;
QAction* DeleteCacheAction; QAction* DeleteCacheAction;
QAction* ExitAction; QAction* ExitAction;
@ -99,6 +103,10 @@ protected:
QTextCharFormat ErrorFormat; QTextCharFormat ErrorFormat;
QTextCharFormat MessageFormat; QTextCharFormat MessageFormat;
QEventLoop LocalLoop;
float ProgressOffset;
float ProgressFactor;
}; };
// QCMake instance on a thread // QCMake instance on a thread

View File

@ -200,6 +200,7 @@ QCMakeCacheModel::QCMakeCacheModel(QObject* p)
NewPropertyCount(0), NewPropertyCount(0),
View(FlatView) View(FlatView)
{ {
this->ShowNewProperties = true;
QStringList labels; QStringList labels;
labels << tr("Name") << tr("Value"); labels << tr("Name") << tr("Value");
this->setHorizontalHeaderLabels(labels); this->setHorizontalHeaderLabels(labels);
@ -214,6 +215,11 @@ static uint qHash(const QCMakeProperty& p)
return qHash(p.Key); return qHash(p.Key);
} }
void QCMakeCacheModel::setShowNewProperties(bool f)
{
this->ShowNewProperties = f;
}
void QCMakeCacheModel::clear() void QCMakeCacheModel::clear()
{ {
this->QStandardItemModel::clear(); this->QStandardItemModel::clear();
@ -226,13 +232,21 @@ void QCMakeCacheModel::clear()
void QCMakeCacheModel::setProperties(const QCMakePropertyList& props) void QCMakeCacheModel::setProperties(const QCMakePropertyList& props)
{ {
QSet<QCMakeProperty> newProps = props.toSet(); QSet<QCMakeProperty> newProps, newProps2;
QSet<QCMakeProperty> newProps2 = newProps;
QSet<QCMakeProperty> oldProps = this->properties().toSet(); if(this->ShowNewProperties)
{
oldProps.intersect(newProps); newProps = props.toSet();
newProps.subtract(oldProps); newProps2 = newProps;
newProps2.subtract(newProps); QSet<QCMakeProperty> oldProps = this->properties().toSet();
oldProps.intersect(newProps);
newProps.subtract(oldProps);
newProps2.subtract(newProps);
}
else
{
newProps2 = props.toSet();
}
bool b = this->blockSignals(true); bool b = this->blockSignals(true);

View File

@ -78,6 +78,9 @@ public slots:
// become new properties and be marked red. // become new properties and be marked red.
void setProperties(const QCMakePropertyList& props); void setProperties(const QCMakePropertyList& props);
// set whether to show new properties in red
void setShowNewProperties(bool);
// clear everything from the model // clear everything from the model
void clear(); void clear();
@ -115,6 +118,7 @@ public:
protected: protected:
bool EditEnabled; bool EditEnabled;
int NewPropertyCount; int NewPropertyCount;
bool ShowNewProperties;
ViewType View; ViewType View;
// set the data in the model for this property // set the data in the model for this property