From f8f4140b6ca1d7f1944514741f61aaf631b59115 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Thu, 15 May 2008 19:21:01 -0400 Subject: [PATCH] ENH: Add cross compiling support in the GUI in the same dialog that prompts for the generator on the first configure. It either ask for a toolchain file or asks for all the information a toolchain file might contain. Also added option for setting non-default compilers if not cross compiling. Fixes #6849. Also a bit of code cleanup and re-organizing. --- Source/QtDialog/AddCacheEntry.cxx | 14 +- Source/QtDialog/AddCacheEntry.h | 2 +- Source/QtDialog/AddCacheEntry.ui | 8 +- Source/QtDialog/CMakeFirstConfigure.cxx | 244 ++++++++++ Source/QtDialog/CMakeFirstConfigure.h | 48 ++ Source/QtDialog/CMakeFirstConfigure.ui | 606 ++++++++++++++++++++++++ Source/QtDialog/CMakeLists.txt | 9 +- Source/QtDialog/CMakeSetupDialog.cxx | 150 +++--- Source/QtDialog/CMakeSetupDialog.h | 4 +- Source/QtDialog/QCMake.cxx | 42 +- Source/QtDialog/QCMake.h | 27 +- Source/QtDialog/QCMakeCacheView.cxx | 175 ++----- Source/QtDialog/QCMakeCacheView.h | 58 +-- Source/QtDialog/QCMakeWidgets.cxx | 122 +++++ Source/QtDialog/QCMakeWidgets.h | 71 +++ 15 files changed, 1298 insertions(+), 282 deletions(-) create mode 100644 Source/QtDialog/CMakeFirstConfigure.cxx create mode 100644 Source/QtDialog/CMakeFirstConfigure.h create mode 100644 Source/QtDialog/CMakeFirstConfigure.ui create mode 100644 Source/QtDialog/QCMakeWidgets.cxx create mode 100644 Source/QtDialog/QCMakeWidgets.h diff --git a/Source/QtDialog/AddCacheEntry.cxx b/Source/QtDialog/AddCacheEntry.cxx index a38449ace..eef106970 100644 --- a/Source/QtDialog/AddCacheEntry.cxx +++ b/Source/QtDialog/AddCacheEntry.cxx @@ -21,9 +21,9 @@ static const int NumTypes = 4; static const QString TypeStrings[NumTypes] = { "BOOL", "PATH", "FILEPATH", "STRING" }; -static const QCMakeCacheProperty::PropertyType Types[NumTypes] = - { QCMakeCacheProperty::BOOL, QCMakeCacheProperty::PATH, - QCMakeCacheProperty::FILEPATH, QCMakeCacheProperty::STRING}; +static const QCMakeProperty::PropertyType Types[NumTypes] = + { QCMakeProperty::BOOL, QCMakeProperty::PATH, + QCMakeProperty::FILEPATH, QCMakeProperty::STRING}; AddCacheEntry::AddCacheEntry(QWidget* p) : QWidget(p) @@ -34,8 +34,8 @@ AddCacheEntry::AddCacheEntry(QWidget* p) this->Type->addItem(TypeStrings[i]); } QWidget* cb = new QCheckBox(); - QWidget* path = new QCMakeCachePathEditor(); - QWidget* filepath = new QCMakeCacheFilePathEditor(); + QWidget* path = new QCMakePathEditor(); + QWidget* filepath = new QCMakeFilePathEditor(); QWidget* string = new QLineEdit(); this->StackedWidget->addWidget(cb); this->StackedWidget->addWidget(path); @@ -73,14 +73,14 @@ QString AddCacheEntry::description() const return this->Description->text(); } -QCMakeCacheProperty::PropertyType AddCacheEntry::type() const +QCMakeProperty::PropertyType AddCacheEntry::type() const { int idx = this->Type->currentIndex(); if(idx >= 0 && idx < NumTypes) { return Types[idx]; } - return QCMakeCacheProperty::BOOL; + return QCMakeProperty::BOOL; } diff --git a/Source/QtDialog/AddCacheEntry.h b/Source/QtDialog/AddCacheEntry.h index 000a1a250..691deb8e7 100644 --- a/Source/QtDialog/AddCacheEntry.h +++ b/Source/QtDialog/AddCacheEntry.h @@ -33,7 +33,7 @@ public: QString name() const; QVariant value() const; QString description() const; - QCMakeCacheProperty::PropertyType type() const; + QCMakeProperty::PropertyType type() const; }; #endif diff --git a/Source/QtDialog/AddCacheEntry.ui b/Source/QtDialog/AddCacheEntry.ui index 3ed9b490b..a81587473 100644 --- a/Source/QtDialog/AddCacheEntry.ui +++ b/Source/QtDialog/AddCacheEntry.ui @@ -65,14 +65,14 @@ - QCMakeCachePathEditor + QCMakePathEditor QLineEdit -
QCMakeCacheView.h
+
QCMakeWidgets.h
- QCMakeCacheFilePathEditor + QCMakeFilePathEditor QLineEdit -
QCMakeCacheView.h
+
QCMakeWidgets.h
diff --git a/Source/QtDialog/CMakeFirstConfigure.cxx b/Source/QtDialog/CMakeFirstConfigure.cxx new file mode 100644 index 000000000..8e81956c3 --- /dev/null +++ b/Source/QtDialog/CMakeFirstConfigure.cxx @@ -0,0 +1,244 @@ + +#include "CMakeFirstConfigure.h" + +#include + +CMakeFirstConfigure::CMakeFirstConfigure() +{ + this->UI.setupUi(this); + this->UI.useDefaults->setChecked(true); + this->updatePage(); + + this->UI.useToolChainFile->setChecked(true); + this->updateToolChainPage(); + + QObject::connect(this->UI.useDefaults, SIGNAL(toggled(bool)), + this, SLOT(updatePage())); + QObject::connect(this->UI.compilerSetup, SIGNAL(toggled(bool)), + this, SLOT(updatePage())); + QObject::connect(this->UI.crossCompilerSetup, SIGNAL(toggled(bool)), + this, SLOT(updatePage())); + + QObject::connect(this->UI.useToolChainFile, SIGNAL(toggled(bool)), + this, SLOT(updateToolChainPage())); +} + +CMakeFirstConfigure::~CMakeFirstConfigure() +{ +} + +void CMakeFirstConfigure::setGenerators(const QStringList& gens) +{ + this->UI.generators->clear(); + this->UI.generators->addItems(gens); +} + +QString CMakeFirstConfigure::getGenerator() const +{ + return this->UI.generators->currentText(); +} + +void CMakeFirstConfigure::loadFromSettings() +{ + QSettings settings; + settings.beginGroup("Settings/StartPath"); + + // restore generator + QString lastGen = settings.value("LastGenerator").toString(); + int idx = this->UI.generators->findText(lastGen); + if(idx != -1) + { + this->UI.generators->setCurrentIndex(idx); + } + settings.endGroup(); + + // restore compiler setup + settings.beginGroup("Settings/Compiler"); + this->UI.CCompiler->setText(settings.value("CCompiler").toString()); + this->UI.CXXCompiler->setText(settings.value("CXXCompiler").toString()); + this->UI.FortranCompiler->setText(settings.value("FortranCompiler").toString()); + settings.endGroup(); + + // restore cross compiler setup + settings.beginGroup("Settings/CrossCompiler"); + this->UI.crossCCompiler->setText(settings.value("CCompiler").toString()); + this->UI.crossCXXCompiler->setText(settings.value("CXXCompiler").toString()); + this->UI.crossFortranCompiler->setText(settings.value("FortranCompiler").toString()); + this->UI.useToolChainFile->setChecked(settings.value("UseToolChainFile", true).toBool()); + this->UI.toolChainFile->setText(settings.value("ToolChainFile").toString()); + this->UI.systemName->setText(settings.value("SystemName").toString()); + this->UI.systemVersion->setText(settings.value("SystemVersion").toString()); + this->UI.systemProcessor->setText(settings.value("SystemProcessor").toString()); + this->UI.crossFindRoot->setText(settings.value("FindRoot").toString()); + this->UI.crossProgramMode->setCurrentIndex(settings.value("ProgramMode", 0).toInt()); + this->UI.crossLibraryMode->setCurrentIndex(settings.value("LibraryMode", 0).toInt()); + this->UI.crossIncludeMode->setCurrentIndex(settings.value("IncludeMode", 0).toInt()); + settings.endGroup(); +} + +void CMakeFirstConfigure::saveToSettings() +{ + QSettings settings; + settings.beginGroup("Settings/StartPath"); + + // save generator + QString lastGen = this->UI.generators->currentText(); + settings.setValue("LastGenerator", lastGen); + + settings.endGroup(); + + // save compiler setup + settings.beginGroup("Settings/Compiler"); + settings.setValue("CCompiler", this->UI.CCompiler->text()); + settings.setValue("CXXCompiler", this->UI.CXXCompiler->text()); + settings.setValue("FortranCompiler", this->UI.FortranCompiler->text()); + settings.endGroup(); + + // save cross compiler setup + settings.beginGroup("Settings/CrossCompiler"); + settings.setValue("CCompiler", this->UI.crossCCompiler->text()); + settings.setValue("CXXCompiler", this->UI.crossCXXCompiler->text()); + settings.setValue("FortranCompiler", this->UI.crossFortranCompiler->text()); + settings.setValue("UseToolChainFile", this->UI.useToolChainFile->isChecked()); + settings.setValue("ToolChainFile", this->UI.toolChainFile->text()); + settings.setValue("SystemName", this->UI.systemName->text()); + settings.setValue("SystemVersion", this->UI.systemVersion->text()); + settings.setValue("SystemProcessor", this->UI.systemProcessor->text()); + settings.setValue("FindRoot", this->UI.crossFindRoot->text()); + settings.setValue("ProgramMode", this->UI.crossProgramMode->currentIndex()); + settings.setValue("LibraryMode", this->UI.crossLibraryMode->currentIndex()); + settings.setValue("IncludeMode", this->UI.crossIncludeMode->currentIndex()); + settings.endGroup(); +} + +void CMakeFirstConfigure::updatePage() +{ + if(this->UI.useDefaults->isChecked()) + { + this->UI.stackedWidget->setCurrentIndex(0); + } + else if(this->UI.compilerSetup->isChecked()) + { + this->UI.stackedWidget->setCurrentIndex(1); + } + else if(this->UI.crossCompilerSetup->isChecked()) + { + this->UI.stackedWidget->setCurrentIndex(2); + } +} + +void CMakeFirstConfigure::updateToolChainPage() +{ + if(this->UI.useToolChainFile->isChecked()) + { + this->UI.toolChainStack->setCurrentIndex(0); + } + else + { + this->UI.toolChainStack->setCurrentIndex(1); + } +} + +bool CMakeFirstConfigure::defaultSetup() const +{ + return this->UI.useDefaults->isChecked(); +} + +bool CMakeFirstConfigure::compilerSetup() const +{ + return this->UI.compilerSetup->isChecked(); +} + +bool CMakeFirstConfigure::crossCompilerSetup() const +{ + return this->UI.crossCompilerSetup->isChecked(); +} + +QString CMakeFirstConfigure::crossCompilerToolChainFile() const +{ + if(this->UI.useToolChainFile->isChecked()) + { + return this->UI.toolChainFile->text(); + } + return QString(); +} + +QString CMakeFirstConfigure::getSystemName() const +{ + return this->UI.systemName->text(); +} + +QString CMakeFirstConfigure::getCCompiler() const +{ + if(this->compilerSetup()) + { + return this->UI.CCompiler->text(); + } + else if(this->crossCompilerSetup()) + { + return this->UI.crossCCompiler->text(); + } + return QString(); +} + +QString CMakeFirstConfigure::getCXXCompiler() const +{ + if(this->compilerSetup()) + { + return this->UI.CXXCompiler->text(); + } + else if(this->crossCompilerSetup()) + { + return this->UI.crossCXXCompiler->text(); + } + return QString(); +} + +QString CMakeFirstConfigure::getFortranCompiler() const +{ + if(this->compilerSetup()) + { + return this->UI.FortranCompiler->text(); + } + else if(this->crossCompilerSetup()) + { + return this->UI.crossFortranCompiler->text(); + } + return QString(); +} + + +QString CMakeFirstConfigure::getSystemVersion() const +{ + return this->UI.systemVersion->text(); +} + +QString CMakeFirstConfigure::getSystemProcessor() const +{ + return this->UI.systemProcessor->text(); +} + + +QString CMakeFirstConfigure::getCrossRoot() const +{ + return this->UI.crossFindRoot->text(); +} + +static const char* crossModes[3] = {"BOTH", "ONLY", "NEVER" }; + +QString CMakeFirstConfigure::getCrossProgramMode() const +{ + return crossModes[this->UI.crossProgramMode->currentIndex()]; +} + +QString CMakeFirstConfigure::getCrossLibraryMode() const +{ + return crossModes[this->UI.crossLibraryMode->currentIndex()]; +} + +QString CMakeFirstConfigure::getCrossIncludeMode() const +{ + return crossModes[this->UI.crossIncludeMode->currentIndex()]; +} + + diff --git a/Source/QtDialog/CMakeFirstConfigure.h b/Source/QtDialog/CMakeFirstConfigure.h new file mode 100644 index 000000000..2cb6220c0 --- /dev/null +++ b/Source/QtDialog/CMakeFirstConfigure.h @@ -0,0 +1,48 @@ + +#ifndef CMakeFirstConfigure_h +#define CMakeFirstConfigure_h + +#include +#include "ui_CMakeFirstConfigure.h" + +class CMakeFirstConfigure : public QDialog +{ + Q_OBJECT +public: + CMakeFirstConfigure(); + ~CMakeFirstConfigure(); + + void setGenerators(const QStringList& gens); + QString getGenerator() const; + + bool defaultSetup() const; + bool compilerSetup() const; + bool crossCompilerSetup() const; + QString crossCompilerToolChainFile() const; + + QString getCCompiler() const; + QString getCXXCompiler() const; + QString getFortranCompiler() const; + + QString getSystemName() const; + QString getSystemVersion() const; + QString getSystemProcessor() const; + + QString getCrossRoot() const; + QString getCrossProgramMode() const; + QString getCrossLibraryMode() const; + QString getCrossIncludeMode() const; + + void loadFromSettings(); + void saveToSettings(); + +protected slots: + void updatePage(); + void updateToolChainPage(); + +protected: + Ui::CMakeFirstConfigure UI; +}; + +#endif // CMakeFirstConfigure_h + diff --git a/Source/QtDialog/CMakeFirstConfigure.ui b/Source/QtDialog/CMakeFirstConfigure.ui new file mode 100644 index 000000000..d5413f393 --- /dev/null +++ b/Source/QtDialog/CMakeFirstConfigure.ui @@ -0,0 +1,606 @@ + + CMakeFirstConfigure + + + + 0 + 0 + 609 + 547 + + + + First Configure Setup + + + + + + + 0 + 0 + + + + Please select what build system you want CMake to generate files for. You should select the tool that you will use to build the project. + + + true + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Use Defaults + + + true + + + + + + + Compiler Setup + + + + + + + Cross Compiler Setup + + + + + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + 2 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + The default compilers will be used. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Compilers + + + + + + C + + + + + + + + + + C++ + + + + + + + + + + Fortran + + + + + + + + + + + + + Qt::Vertical + + + + 566 + 71 + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + 1 + + + + + 9 + + + 9 + + + 9 + + + 9 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Tool Chain File + + + true + + + + + + + + + + + + 0 + 0 + + + + System + + + + + + + + + 0 + 0 + + + + Name + + + + + + + + + + + 0 + 0 + + + + Version + + + true + + + + + + + + + + + 0 + 0 + + + + Processor + + + true + + + + + + + + + + + + + + + + 0 + 0 + + + + Compilers + + + + + + C + + + + + + + + + + C++ + + + + + + + + + + Fortran + + + + + + + + + + + + + + 0 + 0 + + + + Find Program/Library/Include + + + + + + + 0 + 0 + + + + Root + + + true + + + + + + + + + + + 0 + 0 + + + + Program Mode + + + + + + + + Find from Root then system + + + + + Only find from Root + + + + + Don't find from Root + + + + + + + + + 0 + 0 + + + + Library Mode + + + + + + + + Find from Root then system + + + + + Only find from Root + + + + + Don't find from Root + + + + + + + + + 0 + 0 + + + + Include Mode + + + + + + + + Find from Root then system + + + + + Only find from Root + + + + + Don't find from Root + + + + + + + + + + + + + + + Use ToolChain File + + + true + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 0 + 20 + + + + + + + + + QCMakeFilePathEditor + QLineEdit +
QCMakeWidgets.h
+
+ + QCMakePathEditor + QLineEdit +
QCMakeWidgets.h
+
+
+ + + + buttonBox + accepted() + CMakeFirstConfigure + accept() + + + 227 + 284 + + + 157 + 274 + + + + + buttonBox + rejected() + CMakeFirstConfigure + reject() + + + 295 + 290 + + + 286 + 274 + + + + +
diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index 37f96ed6f..b74987ef5 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -1,5 +1,5 @@ PROJECT(QtDialog) -SET(QT_MIN_VERSION "4.2.0") +SET(QT_MIN_VERSION "4.3.0") FIND_PACKAGE(Qt4 REQUIRED) IF(NOT QT4_FOUND) @@ -16,6 +16,8 @@ ELSE(NOT QT4_FOUND) SET(SRCS AddCacheEntry.cxx AddCacheEntry.h + CMakeFirstConfigure.cxx + CMakeFirstConfigure.h CMakeSetup.cxx CMakeSetupDialog.cxx CMakeSetupDialog.h @@ -23,19 +25,24 @@ ELSE(NOT QT4_FOUND) QCMake.h QCMakeCacheView.cxx QCMakeCacheView.h + QCMakeWidgets.cxx + QCMakeWidgets.h QMacInstallDialog.cxx QMacInstallDialog.h ) QT4_WRAP_UI(UI_SRCS + CMakeFirstConfigure.ui CMakeSetupDialog.ui AddCacheEntry.ui MacInstallDialog.ui ) QT4_WRAP_CPP(MOC_SRCS AddCacheEntry.h + CMakeFirstConfigure.h CMakeSetupDialog.h QCMake.h QCMakeCacheView.h + QCMakeWidgets.h QMacInstallDialog.h ) QT4_ADD_RESOURCES(RC_SRCS CMakeSetup.qrc) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 56ee7ac73..3eda31d9a 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -36,6 +36,7 @@ #include "QCMake.h" #include "QCMakeCacheView.h" #include "AddCacheEntry.h" +#include "CMakeFirstConfigure.h" QCMakeThread::QCMakeThread(QObject* p) : QThread(p), CMakeInstance(NULL) @@ -60,7 +61,6 @@ void QCMakeThread::run() CMakeSetupDialog::CMakeSetupDialog() : ExitAfterGenerate(true), CacheModified(false), CurrentState(Interrupting) { - this->SuppressDevWarnings = false; // create the GUI QSettings settings; settings.beginGroup("Settings/StartPath"); @@ -104,11 +104,9 @@ CMakeSetupDialog::CMakeSetupDialog() this, SLOT(doInstallForCommandLine())); #endif QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options")); - QAction* supressDevWarningsAction = OptionsMenu->addAction(tr("&Suppress dev Warnings (-Wno-dev)")); - QObject::connect(supressDevWarningsAction, SIGNAL(triggered(bool)), - this, SLOT(doSuppressDev())); + this->SuppressDevWarningsAction = OptionsMenu->addAction(tr("&Suppress dev Warnings (-Wno-dev)")); + this->SuppressDevWarningsAction->setCheckable(true); - supressDevWarningsAction->setCheckable(true); QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output")); debugAction->setCheckable(true); QObject::connect(debugAction, SIGNAL(toggled(bool)), @@ -153,9 +151,9 @@ void CMakeSetupDialog::initialize() { // now the cmake worker thread is running, lets make our connections to it QObject::connect(this->CMakeThread->cmakeInstance(), - SIGNAL(propertiesChanged(const QCMakeCachePropertyList&)), + SIGNAL(propertiesChanged(const QCMakePropertyList&)), this->CacheValues->cacheModel(), - SLOT(setProperties(const QCMakeCachePropertyList&))); + SLOT(setProperties(const QCMakePropertyList&))); QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)), this, SLOT(doConfigure())); @@ -220,6 +218,8 @@ void CMakeSetupDialog::initialize() QObject::connect(this->AddEntry, SIGNAL(clicked(bool)), this, SLOT(addCacheEntry())); + QObject::connect(this->SuppressDevWarningsAction, SIGNAL(triggered(bool)), + this->CMakeThread->cmakeInstance(), SLOT(setSuppressDevWarnings(bool))); if(!this->SourceDirectory->text().isEmpty() || !this->BinaryDirectory->lineEdit()->text().isEmpty()) @@ -275,10 +275,10 @@ void CMakeSetupDialog::doConfigure() dir.mkpath("."); } - // prompt for generator if it hasn't been set + // if no generator, prompt for it and other setup stuff if(this->CMakeThread->cmakeInstance()->generator().isEmpty()) { - if(!this->promptForGenerator()) + if(!this->setupFirstConfigure()) { return; } @@ -292,7 +292,7 @@ void CMakeSetupDialog::doConfigure() this->CacheValues->selectionModel()->clear(); QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "setProperties", Qt::QueuedConnection, - Q_ARG(QCMakeCachePropertyList, + Q_ARG(QCMakePropertyList, this->CacheValues->cacheModel()->properties())); QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "configure", Qt::QueuedConnection); @@ -329,13 +329,6 @@ void CMakeSetupDialog::finishGenerate(int err) } } -void CMakeSetupDialog::doSuppressDev() -{ - this->SuppressDevWarnings = !this->SuppressDevWarnings; - this->CMakeThread->cmakeInstance()-> - SetSuppressDevWarnings(this->SuppressDevWarnings); -} - void CMakeSetupDialog::doInstallForCommandLine() { QMacInstallDialog setupdialog(0); @@ -542,41 +535,89 @@ void CMakeSetupDialog::setEnabledState(bool enabled) this->RemoveEntry->setEnabled(false); // let selection re-enable it } -bool CMakeSetupDialog::promptForGenerator() +bool CMakeSetupDialog::setupFirstConfigure() { - QSettings settings; - settings.beginGroup("Settings/StartPath"); - QString lastGen = settings.value("LastGenerator").toString(); + CMakeFirstConfigure dialog; - QStringList gens = this->CMakeThread->cmakeInstance()->availableGenerators(); - QDialog dialog; - dialog.setWindowTitle(tr("Choose Generator")); - QLabel* lab = new QLabel(&dialog); - lab->setText(tr("Please select what build system you want CMake to generate files for.\n" - "You should select the tool that you will use to build the project.\n" - "Press OK once you have made your selection.")); - QComboBox* combo = new QComboBox(&dialog); - combo->addItems(gens); - int idx = combo->findText(lastGen); - if(idx != -1) - { - combo->setCurrentIndex(idx); - } - QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok | - QDialogButtonBox::Cancel, - Qt::Horizontal, &dialog); - QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept())); - QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(reject())); + // initialize dialog and restore saved settings + + // add generators + dialog.setGenerators(this->CMakeThread->cmakeInstance()->availableGenerators()); + + // restore from settings + dialog.loadFromSettings(); - QVBoxLayout* l = new QVBoxLayout(&dialog); - l->addWidget(lab); - l->addWidget(combo); - l->addWidget(btns); if(dialog.exec() == QDialog::Accepted) { - lastGen = combo->currentText(); - settings.setValue("LastGenerator", lastGen); - this->CMakeThread->cmakeInstance()->setGenerator(combo->currentText()); + dialog.saveToSettings(); + this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator()); + + QCMakeCacheModel* m = this->CacheValues->cacheModel(); + + if(dialog.compilerSetup()) + { + QString fortranCompiler = dialog.getFortranCompiler(); + if(!fortranCompiler.isEmpty()) + { + m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER", + "Fortran compiler.", fortranCompiler, false); + } + QString cxxCompiler = dialog.getCXXCompiler(); + if(!cxxCompiler.isEmpty()) + { + m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER", + "CXX compiler.", cxxCompiler, false); + } + + QString cCompiler = dialog.getCCompiler(); + if(!cCompiler.isEmpty()) + { + m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER", + "C compiler.", cCompiler, false); + } + } + else if(dialog.crossCompilerSetup()) + { + QString toolchainFile = dialog.crossCompilerToolChainFile(); + if(!toolchainFile.isEmpty()) + { + m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE", + "Cross Compile ToolChain File", toolchainFile, false); + } + else + { + QString fortranCompiler = dialog.getFortranCompiler(); + if(!fortranCompiler.isEmpty()) + { + m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER", + "Fortran compiler.", fortranCompiler, false); + } + + QString mode = dialog.getCrossIncludeMode(); + m->insertProperty(0, QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE", + "CMake Find Include Mode", mode, false); + mode = dialog.getCrossLibraryMode(); + m->insertProperty(0, QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY", + "CMake Find Library Mode", mode, false); + mode = dialog.getCrossProgramMode(); + m->insertProperty(0, QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM", + "CMake Find Program Mode", mode, false); + + QString rootPath = dialog.getCrossRoot(); + m->insertProperty(0, QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH", + "CMake Find Root Path", rootPath, false); + + QString systemName = dialog.getSystemName(); + m->insertProperty(0, QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME", + "CMake System Name", systemName, false); + QString cxxCompiler = dialog.getCXXCompiler(); + m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER", + "CXX compiler.", cxxCompiler, false); + QString cCompiler = dialog.getCCompiler(); + m->insertProperty(0, QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER", + "C compiler.", cCompiler, false); + } + } return true; } @@ -856,20 +897,7 @@ void CMakeSetupDialog::addCacheEntry() if(QDialog::Accepted == dialog.exec()) { QCMakeCacheModel* m = this->CacheValues->cacheModel(); - m->insertRows(0, 1, QModelIndex()); - m->setData(m->index(0, 0), w->type(), QCMakeCacheModel::TypeRole); - m->setData(m->index(0, 0), w->name(), Qt::DisplayRole); - m->setData(m->index(0, 0), w->description(), QCMakeCacheModel::HelpRole); - m->setData(m->index(0, 0), 0, QCMakeCacheModel::AdvancedRole); - if(w->type() == QCMakeCacheProperty::BOOL) - { - m->setData(m->index(0, 1), w->value().toBool() ? - Qt::Checked : Qt::Unchecked, Qt::CheckStateRole); - } - else - { - m->setData(m->index(0, 1), w->value(), Qt::DisplayRole); - } + m->insertProperty(0, w->type(), w->name(), w->description(), w->value(), false); } } diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h index c942d154e..5c781f0a3 100644 --- a/Source/QtDialog/CMakeSetupDialog.h +++ b/Source/QtDialog/CMakeSetupDialog.h @@ -44,7 +44,6 @@ protected slots: void initialize(); void doConfigure(); void doGenerate(); - void doSuppressDev(); void doInstallForCommandLine(); void doHelp(); void doAbout(); @@ -62,7 +61,7 @@ protected slots: void updateBinaryDirectory(const QString& dir); void showProgress(const QString& msg, float percent); void setEnabledState(bool); - bool promptForGenerator(); + bool setupFirstConfigure(); void updateGeneratorLabel(const QString& gen); void setExitAfterGenerate(bool); void addBinaryPath(const QString&); @@ -89,7 +88,6 @@ protected: QCMakeThread* CMakeThread; bool ExitAfterGenerate; bool CacheModified; - bool SuppressDevWarnings; QAction* ReloadCacheAction; QAction* DeleteCacheAction; QAction* ExitAction; diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 60ca2fe33..dd1608ea6 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -29,8 +29,8 @@ QCMake::QCMake(QObject* p) : QObject(p) { this->SuppressDevWarnings = false; - qRegisterMetaType(); - qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); QDir execDir(QCoreApplication::applicationDirPath()); @@ -111,7 +111,7 @@ void QCMake::setBinaryDirectory(const QString& dir) } } - QCMakeCachePropertyList props = this->properties(); + QCMakePropertyList props = this->properties(); emit this->propertiesChanged(props); cmCacheManager::CacheIterator itm = cachem->NewIterator(); if ( itm.Find("CMAKE_HOME_DIRECTORY")) @@ -165,9 +165,9 @@ void QCMake::generate() emit this->generateDone(err); } -void QCMake::setProperties(const QCMakeCachePropertyList& newProps) +void QCMake::setProperties(const QCMakePropertyList& newProps) { - QCMakeCachePropertyList props = newProps; + QCMakePropertyList props = newProps; QStringList toremove; @@ -183,7 +183,7 @@ void QCMake::setProperties(const QCMakeCachePropertyList& newProps) continue; } - QCMakeCacheProperty prop; + QCMakeProperty prop; prop.Key = i.GetName(); int idx = props.indexOf(prop); if(idx == -1) @@ -213,30 +213,30 @@ void QCMake::setProperties(const QCMakeCachePropertyList& newProps) } // add some new properites - foreach(QCMakeCacheProperty s, props) + foreach(QCMakeProperty s, props) { - if(s.Type == QCMakeCacheProperty::BOOL) + if(s.Type == QCMakeProperty::BOOL) { this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(), s.Value.toBool() ? "ON" : "OFF", s.Help.toAscii().data(), cmCacheManager::BOOL); } - else if(s.Type == QCMakeCacheProperty::STRING) + else if(s.Type == QCMakeProperty::STRING) { this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(), s.Value.toString().toAscii().data(), s.Help.toAscii().data(), cmCacheManager::STRING); } - else if(s.Type == QCMakeCacheProperty::PATH) + else if(s.Type == QCMakeProperty::PATH) { this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(), s.Value.toString().toAscii().data(), s.Help.toAscii().data(), cmCacheManager::PATH); } - else if(s.Type == QCMakeCacheProperty::FILEPATH) + else if(s.Type == QCMakeProperty::FILEPATH) { this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(), s.Value.toString().toAscii().data(), @@ -248,9 +248,9 @@ void QCMake::setProperties(const QCMakeCachePropertyList& newProps) cachem->SaveCache(this->BinaryDirectory.toAscii().data()); } -QCMakeCachePropertyList QCMake::properties() const +QCMakePropertyList QCMake::properties() const { - QCMakeCachePropertyList ret; + QCMakePropertyList ret; cmCacheManager *cachem = this->CMakeInstance->GetCacheManager(); for(cmCacheManager::CacheIterator i = cachem->NewIterator(); @@ -264,7 +264,7 @@ QCMakeCachePropertyList QCMake::properties() const continue; } - QCMakeCacheProperty prop; + QCMakeProperty prop; prop.Key = i.GetName(); prop.Help = i.GetProperty("HELPSTRING"); prop.Value = i.GetValue(); @@ -272,20 +272,20 @@ QCMakeCachePropertyList QCMake::properties() const if(i.GetType() == cmCacheManager::BOOL) { - prop.Type = QCMakeCacheProperty::BOOL; + prop.Type = QCMakeProperty::BOOL; prop.Value = cmSystemTools::IsOn(i.GetValue()); } else if(i.GetType() == cmCacheManager::PATH) { - prop.Type = QCMakeCacheProperty::PATH; + prop.Type = QCMakeProperty::PATH; } else if(i.GetType() == cmCacheManager::FILEPATH) { - prop.Type = QCMakeCacheProperty::FILEPATH; + prop.Type = QCMakeProperty::FILEPATH; } else if(i.GetType() == cmCacheManager::STRING) { - prop.Type = QCMakeCacheProperty::STRING; + prop.Type = QCMakeProperty::STRING; } ret.append(prop); @@ -349,14 +349,14 @@ void QCMake::deleteCache() this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toAscii().data()); // emit no generator and no properties this->setGenerator(QString()); - QCMakeCachePropertyList props = this->properties(); + QCMakePropertyList props = this->properties(); emit this->propertiesChanged(props); } void QCMake::reloadCache() { // emit that the cache was cleaned out - QCMakeCachePropertyList props; + QCMakePropertyList props; emit this->propertiesChanged(props); // reload this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toAscii().data()); @@ -380,7 +380,7 @@ bool QCMake::getDebugOutput() const } -void QCMake::SetSuppressDevWarnings(bool value) +void QCMake::setSuppressDevWarnings(bool value) { this->SuppressDevWarnings = value; } diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index c46aab6d6..909c1acc4 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -31,9 +31,9 @@ class cmake; -/// struct to represent cache properties in Qt +/// struct to represent cmake properties in Qt /// Value is of type String or Bool -struct QCMakeCacheProperty +struct QCMakeProperty { enum PropertyType { BOOL, PATH, FILEPATH, STRING }; QString Key; @@ -41,20 +41,22 @@ struct QCMakeCacheProperty QString Help; PropertyType Type; bool Advanced; - bool operator==(const QCMakeCacheProperty& other) const + bool operator==(const QCMakeProperty& other) const { return this->Key == other.Key; } - bool operator<(const QCMakeCacheProperty& other) const + bool operator<(const QCMakeProperty& other) const { return this->Key < other.Key; } }; -// make types usable with QVariant -Q_DECLARE_METATYPE(QCMakeCacheProperty) -typedef QList QCMakeCachePropertyList; -Q_DECLARE_METATYPE(QCMakeCachePropertyList) +// list of properties +typedef QList QCMakePropertyList; + +// allow QVariant to be a property or list of properties +Q_DECLARE_METATYPE(QCMakeProperty) +Q_DECLARE_METATYPE(QCMakePropertyList) /// Qt API for CMake library. /// Wrapper like class allows for easier integration with @@ -65,7 +67,6 @@ class QCMake : public QObject public: QCMake(QObject* p=0); ~QCMake(); - void SetSuppressDevWarnings(bool value); public slots: /// load the cache file in a directory void loadCache(const QString& dir); @@ -80,7 +81,7 @@ public slots: /// generate the files void generate(); /// set the property values - void setProperties(const QCMakeCachePropertyList&); + void setProperties(const QCMakePropertyList&); /// interrupt the configure or generate process void interrupt(); /// delete the cache in binary directory @@ -89,10 +90,12 @@ public slots: void reloadCache(); /// set whether to do debug output void setDebugOutput(bool); + /// set whether to do suppress dev warnings + void setSuppressDevWarnings(bool value); public: /// get the list of cache properties - QCMakeCachePropertyList properties() const; + QCMakePropertyList properties() const; /// get the current binary directory QString binaryDirectory() const; /// get the current source directory @@ -106,7 +109,7 @@ public: signals: /// signal when properties change (during read from disk or configure process) - void propertiesChanged(const QCMakeCachePropertyList& vars); + void propertiesChanged(const QCMakePropertyList& vars); /// signal when the generator changes void generatorChanged(const QString& gen); /// signal when the source directory changes (binary directory already diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 8a8f8193a..245de8eb7 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -17,16 +17,14 @@ #include "QCMakeCacheView.h" -#include -#include #include #include #include -#include #include #include -#include -#include +#include + +#include "QCMakeWidgets.h" static QRegExp AdvancedRegExp[2] = { QRegExp("(false)"), QRegExp("(true|false)") }; @@ -145,21 +143,21 @@ QCMakeCacheModel::~QCMakeCacheModel() { } -static uint qHash(const QCMakeCacheProperty& p) +static uint qHash(const QCMakeProperty& p) { return qHash(p.Key); } void QCMakeCacheModel::clear() { - this->setProperties(QCMakeCachePropertyList()); + this->setProperties(QCMakePropertyList()); } -void QCMakeCacheModel::setProperties(const QCMakeCachePropertyList& props) +void QCMakeCacheModel::setProperties(const QCMakePropertyList& props) { - QSet newProps = props.toSet(); - QSet newProps2 = props.toSet(); - QSet oldProps = this->Properties.toSet(); + QSet newProps = props.toSet(); + QSet newProps2 = props.toSet(); + QSet oldProps = this->Properties.toSet(); oldProps.intersect(newProps); newProps.subtract(oldProps); @@ -170,17 +168,44 @@ void QCMakeCacheModel::setProperties(const QCMakeCachePropertyList& props) this->Properties = newProps.toList(); qSort(this->Properties); - QCMakeCachePropertyList tmp = newProps2.toList(); + QCMakePropertyList tmp = newProps2.toList(); qSort(tmp); this->Properties += tmp; this->reset(); } -QCMakeCachePropertyList QCMakeCacheModel::properties() const +QCMakePropertyList QCMakeCacheModel::properties() const { return this->Properties; } + +bool QCMakeCacheModel::insertProperty(int row, QCMakeProperty::PropertyType t, + const QString& name, const QString& description, + const QVariant& value, bool advanced) +{ + if(this->insertRows(row, 1, QModelIndex())) + { + QModelIndex idx1 = this->index(row, 0); + QModelIndex idx2 = this->index(row, 1); + + this->setData(idx1, t, QCMakeCacheModel::TypeRole); + this->setData(idx1, name, Qt::DisplayRole); + this->setData(idx1, description, QCMakeCacheModel::HelpRole); + this->setData(idx1, advanced, QCMakeCacheModel::AdvancedRole); + if(t == QCMakeProperty::BOOL) + { + this->setData(idx2, value.toBool() ? Qt::Checked : Qt::Unchecked, + Qt::CheckStateRole); + } + else + { + this->setData(idx2, value, Qt::DisplayRole); + } + return true; + } + return false; +} void QCMakeCacheModel::setEditEnabled(bool e) { @@ -215,14 +240,14 @@ QVariant QCMakeCacheModel::data (const QModelIndex& idx, int role) const } else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole)) { - if(this->Properties[idx.row()].Type != QCMakeCacheProperty::BOOL) + if(this->Properties[idx.row()].Type != QCMakeProperty::BOOL) { return this->Properties[idx.row()].Value; } } else if(idx.column() == 1 && role == Qt::CheckStateRole) { - if(this->Properties[idx.row()].Type == QCMakeCacheProperty::BOOL) + if(this->Properties[idx.row()].Type == QCMakeProperty::BOOL) { return this->Properties[idx.row()].Value.toBool() ? Qt::Checked : Qt::Unchecked; } @@ -278,7 +303,7 @@ Qt::ItemFlags QCMakeCacheModel::flags (const QModelIndex& idx) const { f |= Qt::ItemIsEditable; // booleans are editable in place - if(this->Properties[idx.row()].Type == QCMakeCacheProperty::BOOL) + if(this->Properties[idx.row()].Type == QCMakeProperty::BOOL) { f |= Qt::ItemIsUserCheckable; } @@ -311,7 +336,7 @@ bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, i } else if(role == QCMakeCacheModel::TypeRole) { - this->Properties[idx.row()].Type = static_cast(value.toInt()); + this->Properties[idx.row()].Type = static_cast(value.toInt()); } else if(role == QCMakeCacheModel::AdvancedRole) { @@ -324,7 +349,7 @@ QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const { if(idx.column() == 0) { - if(this->Properties[idx.row()].Type != QCMakeCacheProperty::BOOL) + if(this->Properties[idx.row()].Type != QCMakeProperty::BOOL) { return this->index(idx.row(), 1); } @@ -361,7 +386,7 @@ bool QCMakeCacheModel::insertRows(int row, int num, const QModelIndex&) this->beginInsertRows(QModelIndex(), row, row+num-1); for(int i=0; iProperties.insert(row+i, QCMakeCacheProperty()); + this->Properties.insert(row+i, QCMakeProperty()); if(this->NewCount >= row) { this->NewCount++; @@ -387,23 +412,23 @@ QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p, const QAbstractItemModel* model = idx.model(); QModelIndex var = model->index(idx.row(), 0); QVariant type = idx.data(QCMakeCacheModel::TypeRole); - if(type == QCMakeCacheProperty::BOOL) + if(type == QCMakeProperty::BOOL) { return NULL; } - else if(type == QCMakeCacheProperty::PATH) + else if(type == QCMakeProperty::PATH) { - QCMakeCachePathEditor* editor = - new QCMakeCachePathEditor(p, + QCMakePathEditor* editor = + new QCMakePathEditor(p, var.data(Qt::DisplayRole).toString()); QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this, SLOT(setFileDialogFlag(bool))); return editor; } - else if(type == QCMakeCacheProperty::FILEPATH) + else if(type == QCMakeProperty::FILEPATH) { - QCMakeCacheFilePathEditor* editor = - new QCMakeCacheFilePathEditor(p, + QCMakeFilePathEditor* editor = + new QCMakeFilePathEditor(p, var.data(Qt::DisplayRole).toString()); QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this, SLOT(setFileDialogFlag(bool))); @@ -467,101 +492,3 @@ bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event) } -QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p, const QString& var) - : QLineEdit(p), Variable(var) -{ - // this *is* instead of has a line edit so QAbstractItemView - // doesn't get confused with what the editor really is - this->setContentsMargins(0, 0, 0, 0); - this->ToolButton = new QToolButton(this); - this->ToolButton->setText("..."); - this->ToolButton->setCursor(QCursor(Qt::ArrowCursor)); - QObject::connect(this->ToolButton, SIGNAL(clicked(bool)), - this, SLOT(chooseFile())); -} - -QCMakeCacheFilePathEditor::QCMakeCacheFilePathEditor(QWidget* p, const QString& var) - : QCMakeCacheFileEditor(p, var) -{ - this->setCompleter(new QCMakeFileCompleter(this, false)); -} - -QCMakeCachePathEditor::QCMakeCachePathEditor(QWidget* p, const QString& var) - : QCMakeCacheFileEditor(p, var) -{ -this->setCompleter(new QCMakeFileCompleter(this, true)); -} - -void QCMakeCacheFileEditor::resizeEvent(QResizeEvent* e) -{ - // make the tool button fit on the right side - int h = e->size().height(); - this->ToolButton->resize(h, h); - this->ToolButton->move(this->width() - h, 0); - this->setContentsMargins(0, 0, h, 0); -} - -void QCMakeCacheFilePathEditor::chooseFile() -{ - // choose a file and set it - QString path; - QFileInfo info(this->text()); - QString title; - if(this->Variable.isEmpty()) - { - title = tr("Select File"); - } - else - { - title = tr("Select File for %1"); - title = title.arg(this->Variable); - } - this->fileDialogExists(true); - path = QFileDialog::getOpenFileName(this, title, info.absolutePath()); - this->fileDialogExists(false); - - if(!path.isEmpty()) - { - this->setText(QDir::fromNativeSeparators(path)); - } -} - -void QCMakeCachePathEditor::chooseFile() -{ - // choose a file and set it - QString path; - QString title; - if(this->Variable.isEmpty()) - { - title = tr("Select Path"); - } - else - { - title = tr("Select Path for %1"); - title = title.arg(this->Variable); - } - this->fileDialogExists(true); - path = QFileDialog::getExistingDirectory(this, title, this->text()); - this->fileDialogExists(false); - if(!path.isEmpty()) - { - this->setText(QDir::fromNativeSeparators(path)); - } -} - -QCMakeFileCompleter::QCMakeFileCompleter(QObject* o, bool dirs) - : QCompleter(o) -{ - QDirModel* model = new QDirModel(this); - if(dirs) - { - model->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot); - } - this->setModel(model); -} - -QString QCMakeFileCompleter::pathFromIndex(const QModelIndex& idx) const -{ - return QDir::fromNativeSeparators(QCompleter::pathFromIndex(idx)); -} - diff --git a/Source/QtDialog/QCMakeCacheView.h b/Source/QtDialog/QCMakeCacheView.h index 45a858e4a..41b3e1f2a 100644 --- a/Source/QtDialog/QCMakeCacheView.h +++ b/Source/QtDialog/QCMakeCacheView.h @@ -21,14 +21,10 @@ #include "QCMake.h" #include #include -#include -#include #include -#include -#include +class QSortFilterProxyModel; class QCMakeCacheModel; -class QToolButton; /// Qt view class for cache properties @@ -65,11 +61,17 @@ public: enum { HelpRole = Qt::UserRole, TypeRole, AdvancedRole }; public slots: - void setProperties(const QCMakeCachePropertyList& props); + void setProperties(const QCMakePropertyList& props); void clear(); void setEditEnabled(bool); bool removeRows(int row, int count, const QModelIndex& idx = QModelIndex()); bool insertRows(int row, int num, const QModelIndex&); + + // insert a property at a row specifying all the information about the + // property + bool insertProperty(int row, QCMakeProperty::PropertyType t, + const QString& name, const QString& description, + const QVariant& value, bool advanced); public: // satisfy [pure] virtuals @@ -83,7 +85,7 @@ public: QModelIndex buddy (const QModelIndex& index) const; // get the properties - QCMakeCachePropertyList properties() const; + QCMakePropertyList properties() const; // editing enabled bool editEnabled() const; @@ -91,7 +93,7 @@ public: int newCount() const; protected: - QCMakeCachePropertyList Properties; + QCMakePropertyList Properties; int NewCount; bool EditEnabled; }; @@ -115,45 +117,5 @@ protected: bool FileDialogFlag; }; -/// Editor widget for editing paths or file paths -class QCMakeCacheFileEditor : public QLineEdit -{ - Q_OBJECT -public: - QCMakeCacheFileEditor(QWidget* p, const QString& var); -protected slots: - virtual void chooseFile() = 0; -signals: - void fileDialogExists(bool); -protected: - void resizeEvent(QResizeEvent* e); - QToolButton* ToolButton; - QString Variable; -}; - -class QCMakeCachePathEditor : public QCMakeCacheFileEditor -{ - Q_OBJECT -public: - QCMakeCachePathEditor(QWidget* p = NULL, const QString& var = QString()); - void chooseFile(); -}; - -class QCMakeCacheFilePathEditor : public QCMakeCacheFileEditor -{ - Q_OBJECT -public: - QCMakeCacheFilePathEditor(QWidget* p = NULL, const QString& var = QString()); - void chooseFile(); -}; - -/// completer class that returns native cmake paths -class QCMakeFileCompleter : public QCompleter -{ -public: - QCMakeFileCompleter(QObject* o, bool dirs); - virtual QString pathFromIndex(const QModelIndex& idx) const; -}; - #endif diff --git a/Source/QtDialog/QCMakeWidgets.cxx b/Source/QtDialog/QCMakeWidgets.cxx new file mode 100644 index 000000000..3dbec1154 --- /dev/null +++ b/Source/QtDialog/QCMakeWidgets.cxx @@ -0,0 +1,122 @@ +/*========================================================================= + + Program: CMake - Cross-Platform Makefile Generator + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. + See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "QCMakeWidgets.h" + +#include +#include +#include +#include +#include + +QCMakeFileEditor::QCMakeFileEditor(QWidget* p, const QString& var) + : QLineEdit(p), Variable(var) +{ + this->ToolButton = new QToolButton(this); + this->ToolButton->setText("..."); + this->ToolButton->setCursor(QCursor(Qt::ArrowCursor)); + QObject::connect(this->ToolButton, SIGNAL(clicked(bool)), + this, SLOT(chooseFile())); +} + +QCMakeFilePathEditor::QCMakeFilePathEditor(QWidget* p, const QString& var) + : QCMakeFileEditor(p, var) +{ + this->setCompleter(new QCMakeFileCompleter(this, false)); +} + +QCMakePathEditor::QCMakePathEditor(QWidget* p, const QString& var) + : QCMakeFileEditor(p, var) +{ + this->setCompleter(new QCMakeFileCompleter(this, true)); +} + +void QCMakeFileEditor::resizeEvent(QResizeEvent* e) +{ + // make the tool button fit on the right side + int h = e->size().height(); + // move the line edit to make room for the tool button + this->setContentsMargins(0, 0, h, 0); + // put the tool button in its place + this->ToolButton->resize(h, h); + this->ToolButton->move(this->width() - h, 0); +} + +void QCMakeFilePathEditor::chooseFile() +{ + // choose a file and set it + QString path; + QFileInfo info(this->text()); + QString title; + if(this->Variable.isEmpty()) + { + title = tr("Select File"); + } + else + { + title = tr("Select File for %1"); + title = title.arg(this->Variable); + } + this->fileDialogExists(true); + path = QFileDialog::getOpenFileName(this, title, info.absolutePath()); + this->fileDialogExists(false); + + if(!path.isEmpty()) + { + this->setText(QDir::fromNativeSeparators(path)); + } +} + +void QCMakePathEditor::chooseFile() +{ + // choose a file and set it + QString path; + QString title; + if(this->Variable.isEmpty()) + { + title = tr("Select Path"); + } + else + { + title = tr("Select Path for %1"); + title = title.arg(this->Variable); + } + this->fileDialogExists(true); + path = QFileDialog::getExistingDirectory(this, title, this->text()); + this->fileDialogExists(false); + if(!path.isEmpty()) + { + this->setText(QDir::fromNativeSeparators(path)); + } +} + +QCMakeFileCompleter::QCMakeFileCompleter(QObject* o, bool dirs) + : QCompleter(o) +{ + QDirModel* model = new QDirModel(this); + if(dirs) + { + model->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot); + } + this->setModel(model); +} + +QString QCMakeFileCompleter::pathFromIndex(const QModelIndex& idx) const +{ + return QDir::fromNativeSeparators(QCompleter::pathFromIndex(idx)); +} + diff --git a/Source/QtDialog/QCMakeWidgets.h b/Source/QtDialog/QCMakeWidgets.h new file mode 100644 index 000000000..231f72818 --- /dev/null +++ b/Source/QtDialog/QCMakeWidgets.h @@ -0,0 +1,71 @@ +/*========================================================================= + + Program: CMake - Cross-Platform Makefile Generator + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. + See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef QCMakeWidgets_h +#define QCMakeWidgets_h + +#include +#include +class QToolButton; + +// common widgets for Qt based CMake + +/// Editor widget for editing paths or file paths +class QCMakeFileEditor : public QLineEdit +{ + Q_OBJECT +public: + QCMakeFileEditor(QWidget* p, const QString& var); +protected slots: + virtual void chooseFile() = 0; +signals: + void fileDialogExists(bool); +protected: + void resizeEvent(QResizeEvent* e); + QToolButton* ToolButton; + QString Variable; +}; + +/// editor widget for editing files +class QCMakePathEditor : public QCMakeFileEditor +{ + Q_OBJECT +public: + QCMakePathEditor(QWidget* p = NULL, const QString& var = QString()); + void chooseFile(); +}; + +/// editor widget for editing paths +class QCMakeFilePathEditor : public QCMakeFileEditor +{ + Q_OBJECT +public: + QCMakeFilePathEditor(QWidget* p = NULL, const QString& var = QString()); + void chooseFile(); +}; + +/// completer class that returns native cmake paths +class QCMakeFileCompleter : public QCompleter +{ + Q_OBJECT +public: + QCMakeFileCompleter(QObject* o, bool dirs); + virtual QString pathFromIndex(const QModelIndex& idx) const; +}; + +#endif +