CMakeSetupDialog.cxx 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "CMakeSetupDialog.h"
  11. #include <QFileDialog>
  12. #include <QProgressBar>
  13. #include <QMessageBox>
  14. #include <QStatusBar>
  15. #include <QToolButton>
  16. #include <QDialogButtonBox>
  17. #include <QCloseEvent>
  18. #include <QCoreApplication>
  19. #include <QSettings>
  20. #include <QMenu>
  21. #include <QMenuBar>
  22. #include <QDragEnterEvent>
  23. #include <QMimeData>
  24. #include <QUrl>
  25. #include <QShortcut>
  26. #include <QKeySequence>
  27. #include <QInputDialog>
  28. #include "QCMake.h"
  29. #include "QCMakeCacheView.h"
  30. #include "AddCacheEntry.h"
  31. #include "FirstConfigure.h"
  32. #include "RegexExplorer.h"
  33. #include "cmSystemTools.h"
  34. #include "cmVersion.h"
  35. QCMakeThread::QCMakeThread(QObject* p)
  36. : QThread(p), CMakeInstance(NULL)
  37. {
  38. }
  39. QCMake* QCMakeThread::cmakeInstance() const
  40. {
  41. return this->CMakeInstance;
  42. }
  43. void QCMakeThread::run()
  44. {
  45. this->CMakeInstance = new QCMake;
  46. // emit that this cmake thread is ready for use
  47. emit this->cmakeInitialized();
  48. this->exec();
  49. delete this->CMakeInstance;
  50. this->CMakeInstance = NULL;
  51. }
  52. CMakeSetupDialog::CMakeSetupDialog()
  53. : ExitAfterGenerate(true), CacheModified(false), ConfigureNeeded(true), CurrentState(Interrupting)
  54. {
  55. QString title = QString(tr("CMake %1"));
  56. title = title.arg(cmVersion::GetCMakeVersion());
  57. this->setWindowTitle(title);
  58. // create the GUI
  59. QSettings settings;
  60. settings.beginGroup("Settings/StartPath");
  61. restoreGeometry(settings.value("geometry").toByteArray());
  62. restoreState(settings.value("windowState").toByteArray());
  63. this->AddVariableNames = settings.value("AddVariableNames",
  64. QStringList("CMAKE_INSTALL_PREFIX")).toStringList();
  65. this->AddVariableTypes = settings.value("AddVariableTypes",
  66. QStringList("PATH")).toStringList();
  67. QWidget* cont = new QWidget(this);
  68. this->setupUi(cont);
  69. this->Splitter->setStretchFactor(0, 3);
  70. this->Splitter->setStretchFactor(1, 1);
  71. this->setCentralWidget(cont);
  72. this->ProgressBar->reset();
  73. this->RemoveEntry->setEnabled(false);
  74. this->AddEntry->setEnabled(false);
  75. QByteArray p = settings.value("SplitterSizes").toByteArray();
  76. this->Splitter->restoreState(p);
  77. bool groupView = settings.value("GroupView", false).toBool();
  78. this->setGroupedView(groupView);
  79. this->groupedCheck->setCheckState(groupView ? Qt::Checked : Qt::Unchecked);
  80. bool advancedView = settings.value("AdvancedView", false).toBool();
  81. this->setAdvancedView(advancedView);
  82. this->advancedCheck->setCheckState(advancedView?Qt::Checked : Qt::Unchecked);
  83. QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
  84. this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
  85. QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)),
  86. this, SLOT(doReloadCache()));
  87. this->DeleteCacheAction = FileMenu->addAction(tr("&Delete Cache"));
  88. QObject::connect(this->DeleteCacheAction, SIGNAL(triggered(bool)),
  89. this, SLOT(doDeleteCache()));
  90. this->ExitAction = FileMenu->addAction(tr("E&xit"));
  91. this->ExitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
  92. QObject::connect(this->ExitAction, SIGNAL(triggered(bool)),
  93. this, SLOT(close()));
  94. QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
  95. this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
  96. // prevent merging with Preferences menu item on Mac OS X
  97. this->ConfigureAction->setMenuRole(QAction::NoRole);
  98. QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)),
  99. this, SLOT(doConfigure()));
  100. this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
  101. QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)),
  102. this, SLOT(doGenerate()));
  103. QAction* showChangesAction = ToolsMenu->addAction(tr("&Show My Changes"));
  104. QObject::connect(showChangesAction, SIGNAL(triggered(bool)),
  105. this, SLOT(showUserChanges()));
  106. #if defined(Q_WS_MAC) || defined(Q_OS_MAC)
  107. this->InstallForCommandLineAction
  108. = ToolsMenu->addAction(tr("&How to Install For Command Line Use"));
  109. QObject::connect(this->InstallForCommandLineAction, SIGNAL(triggered(bool)),
  110. this, SLOT(doInstallForCommandLine()));
  111. #endif
  112. ToolsMenu->addSeparator();
  113. ToolsMenu->addAction(tr("Regular Expression Explorer..."),
  114. this, SLOT(doRegexExplorerDialog()));
  115. ToolsMenu->addSeparator();
  116. ToolsMenu->addAction(tr("&Find in Output..."),
  117. this, SLOT(doOutputFindDialog()),
  118. QKeySequence::Find);
  119. ToolsMenu->addAction(tr("Find Next"),
  120. this, SLOT(doOutputFindNext()),
  121. QKeySequence::FindNext);
  122. ToolsMenu->addAction(tr("Find Previous"),
  123. this, SLOT(doOutputFindPrev()),
  124. QKeySequence::FindPrevious);
  125. ToolsMenu->addAction(tr("Goto Next Error"),
  126. this, SLOT(doOutputErrorNext()),
  127. QKeySequence(Qt::Key_F8)); // in Visual Studio
  128. new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Period),
  129. this, SLOT(doOutputErrorNext())); // in Eclipse
  130. QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options"));
  131. this->SuppressDevWarningsAction =
  132. OptionsMenu->addAction(tr("&Suppress dev Warnings (-Wno-dev)"));
  133. this->SuppressDevWarningsAction->setCheckable(true);
  134. this->WarnUninitializedAction =
  135. OptionsMenu->addAction(tr("&Warn Uninitialized (--warn-uninitialized)"));
  136. this->WarnUninitializedAction->setCheckable(true);
  137. this->WarnUnusedAction =
  138. OptionsMenu->addAction(tr("&Warn Unused (--warn-unused-vars)"));
  139. this->WarnUnusedAction->setCheckable(true);
  140. QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output"));
  141. debugAction->setCheckable(true);
  142. QObject::connect(debugAction, SIGNAL(toggled(bool)),
  143. this, SLOT(setDebugOutput(bool)));
  144. OptionsMenu->addSeparator();
  145. QAction* expandAction = OptionsMenu->addAction(tr("&Expand Grouped Entries"));
  146. QObject::connect(expandAction, SIGNAL(triggered(bool)),
  147. this->CacheValues, SLOT(expandAll()));
  148. QAction* collapseAction = OptionsMenu->addAction(tr("&Collapse Grouped Entries"));
  149. QObject::connect(collapseAction, SIGNAL(triggered(bool)),
  150. this->CacheValues, SLOT(collapseAll()));
  151. QMenu* HelpMenu = this->menuBar()->addMenu(tr("&Help"));
  152. QAction* a = HelpMenu->addAction(tr("About"));
  153. QObject::connect(a, SIGNAL(triggered(bool)),
  154. this, SLOT(doAbout()));
  155. a = HelpMenu->addAction(tr("Help"));
  156. QObject::connect(a, SIGNAL(triggered(bool)),
  157. this, SLOT(doHelp()));
  158. this->setAcceptDrops(true);
  159. // get the saved binary directories
  160. QStringList buildPaths = this->loadBuildPaths();
  161. this->BinaryDirectory->addItems(buildPaths);
  162. this->BinaryDirectory->setCompleter(new QCMakeFileCompleter(this, true));
  163. this->SourceDirectory->setCompleter(new QCMakeFileCompleter(this, true));
  164. // fixed pitch font in output window
  165. QFont outputFont("Courier");
  166. this->Output->setFont(outputFont);
  167. this->ErrorFormat.setForeground(QBrush(Qt::red));
  168. this->Output->setContextMenuPolicy(Qt::CustomContextMenu);
  169. connect(this->Output, SIGNAL(customContextMenuRequested(const QPoint&)),
  170. this, SLOT(doOutputContextMenu(const QPoint &)));
  171. // start the cmake worker thread
  172. this->CMakeThread = new QCMakeThread(this);
  173. QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()),
  174. this, SLOT(initialize()), Qt::QueuedConnection);
  175. this->CMakeThread->start();
  176. this->enterState(ReadyConfigure);
  177. ProgressOffset = 0.0;
  178. ProgressFactor = 1.0;
  179. }
  180. void CMakeSetupDialog::initialize()
  181. {
  182. // now the cmake worker thread is running, lets make our connections to it
  183. QObject::connect(this->CMakeThread->cmakeInstance(),
  184. SIGNAL(propertiesChanged(const QCMakePropertyList&)),
  185. this->CacheValues->cacheModel(),
  186. SLOT(setProperties(const QCMakePropertyList&)));
  187. QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)),
  188. this, SLOT(doConfigure()));
  189. QObject::connect(this->CMakeThread->cmakeInstance(), SIGNAL(configureDone(int)),
  190. this, SLOT(exitLoop(int)));
  191. QObject::connect(this->CMakeThread->cmakeInstance(), SIGNAL(generateDone(int)),
  192. this, SLOT(exitLoop(int)));
  193. QObject::connect(this->GenerateButton, SIGNAL(clicked(bool)),
  194. this, SLOT(doGenerate()));
  195. QObject::connect(this->BrowseSourceDirectoryButton, SIGNAL(clicked(bool)),
  196. this, SLOT(doSourceBrowse()));
  197. QObject::connect(this->BrowseBinaryDirectoryButton, SIGNAL(clicked(bool)),
  198. this, SLOT(doBinaryBrowse()));
  199. QObject::connect(this->BinaryDirectory, SIGNAL(editTextChanged(QString)),
  200. this, SLOT(onBinaryDirectoryChanged(QString)));
  201. QObject::connect(this->SourceDirectory, SIGNAL(textChanged(QString)),
  202. this, SLOT(onSourceDirectoryChanged(QString)));
  203. QObject::connect(this->CMakeThread->cmakeInstance(),
  204. SIGNAL(sourceDirChanged(QString)),
  205. this, SLOT(updateSourceDirectory(QString)));
  206. QObject::connect(this->CMakeThread->cmakeInstance(),
  207. SIGNAL(binaryDirChanged(QString)),
  208. this, SLOT(updateBinaryDirectory(QString)));
  209. QObject::connect(this->CMakeThread->cmakeInstance(),
  210. SIGNAL(progressChanged(QString, float)),
  211. this, SLOT(showProgress(QString,float)));
  212. QObject::connect(this->CMakeThread->cmakeInstance(),
  213. SIGNAL(errorMessage(QString)),
  214. this, SLOT(error(QString)));
  215. QObject::connect(this->CMakeThread->cmakeInstance(),
  216. SIGNAL(outputMessage(QString)),
  217. this, SLOT(message(QString)));
  218. QObject::connect(this->groupedCheck, SIGNAL(toggled(bool)),
  219. this, SLOT(setGroupedView(bool)));
  220. QObject::connect(this->advancedCheck, SIGNAL(toggled(bool)),
  221. this, SLOT(setAdvancedView(bool)));
  222. QObject::connect(this->Search, SIGNAL(textChanged(QString)),
  223. this, SLOT(setSearchFilter(QString)));
  224. QObject::connect(this->CMakeThread->cmakeInstance(),
  225. SIGNAL(generatorChanged(QString)),
  226. this, SLOT(updateGeneratorLabel(QString)));
  227. this->updateGeneratorLabel(QString());
  228. QObject::connect(this->CacheValues->cacheModel(),
  229. SIGNAL(dataChanged(QModelIndex,QModelIndex)),
  230. this, SLOT(setCacheModified()));
  231. QObject::connect(this->CacheValues->selectionModel(),
  232. SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
  233. this, SLOT(selectionChanged()));
  234. QObject::connect(this->RemoveEntry, SIGNAL(clicked(bool)),
  235. this, SLOT(removeSelectedCacheEntries()));
  236. QObject::connect(this->AddEntry, SIGNAL(clicked(bool)),
  237. this, SLOT(addCacheEntry()));
  238. QObject::connect(this->SuppressDevWarningsAction, SIGNAL(triggered(bool)),
  239. this->CMakeThread->cmakeInstance(), SLOT(setSuppressDevWarnings(bool)));
  240. QObject::connect(this->WarnUninitializedAction, SIGNAL(triggered(bool)),
  241. this->CMakeThread->cmakeInstance(),
  242. SLOT(setWarnUninitializedMode(bool)));
  243. QObject::connect(this->WarnUnusedAction, SIGNAL(triggered(bool)),
  244. this->CMakeThread->cmakeInstance(),
  245. SLOT(setWarnUnusedMode(bool)));
  246. if(!this->SourceDirectory->text().isEmpty() ||
  247. !this->BinaryDirectory->lineEdit()->text().isEmpty())
  248. {
  249. this->onSourceDirectoryChanged(this->SourceDirectory->text());
  250. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  251. }
  252. else
  253. {
  254. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  255. }
  256. }
  257. CMakeSetupDialog::~CMakeSetupDialog()
  258. {
  259. QSettings settings;
  260. settings.beginGroup("Settings/StartPath");
  261. settings.setValue("windowState", QVariant(saveState()));
  262. settings.setValue("geometry", QVariant(saveGeometry()));
  263. settings.setValue("SplitterSizes", this->Splitter->saveState());
  264. // wait for thread to stop
  265. this->CMakeThread->quit();
  266. this->CMakeThread->wait();
  267. }
  268. bool CMakeSetupDialog::prepareConfigure()
  269. {
  270. // make sure build directory exists
  271. QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
  272. QDir dir(bindir);
  273. if(!dir.exists())
  274. {
  275. QString msg = tr("Build directory does not exist, "
  276. "should I create it?\n\n"
  277. "Directory: ");
  278. msg += bindir;
  279. QString title = tr("Create Directory");
  280. QMessageBox::StandardButton btn;
  281. btn = QMessageBox::information(this, title, msg,
  282. QMessageBox::Yes | QMessageBox::No);
  283. if(btn == QMessageBox::No)
  284. {
  285. return false;
  286. }
  287. if(!dir.mkpath("."))
  288. {
  289. QMessageBox::information(this, tr("Create Directory Failed"),
  290. QString(tr("Failed to create directory %1")).arg(dir.path()),
  291. QMessageBox::Ok);
  292. return false;
  293. }
  294. }
  295. // if no generator, prompt for it and other setup stuff
  296. if(this->CMakeThread->cmakeInstance()->generator().isEmpty())
  297. {
  298. if(!this->setupFirstConfigure())
  299. {
  300. return false;
  301. }
  302. }
  303. // remember path
  304. this->addBinaryPath(dir.absolutePath());
  305. return true;
  306. }
  307. void CMakeSetupDialog::exitLoop(int err)
  308. {
  309. this->LocalLoop.exit(err);
  310. }
  311. void CMakeSetupDialog::doConfigure()
  312. {
  313. if(this->CurrentState == Configuring)
  314. {
  315. // stop configure
  316. doInterrupt();
  317. return;
  318. }
  319. if(!prepareConfigure())
  320. {
  321. return;
  322. }
  323. this->enterState(Configuring);
  324. bool ret = doConfigureInternal();
  325. if(ret)
  326. {
  327. this->ConfigureNeeded = false;
  328. }
  329. if(ret && !this->CacheValues->cacheModel()->newPropertyCount())
  330. {
  331. this->enterState(ReadyGenerate);
  332. }
  333. else
  334. {
  335. this->enterState(ReadyConfigure);
  336. this->CacheValues->scrollToTop();
  337. }
  338. this->ProgressBar->reset();
  339. }
  340. bool CMakeSetupDialog::doConfigureInternal()
  341. {
  342. this->Output->clear();
  343. this->CacheValues->selectionModel()->clear();
  344. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  345. "setProperties", Qt::QueuedConnection,
  346. Q_ARG(QCMakePropertyList,
  347. this->CacheValues->cacheModel()->properties()));
  348. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  349. "configure", Qt::QueuedConnection);
  350. int err = this->LocalLoop.exec();
  351. if(err != 0)
  352. {
  353. QMessageBox::critical(this, tr("Error"),
  354. tr("Error in configuration process, project files may be invalid"),
  355. QMessageBox::Ok);
  356. }
  357. return 0 == err;
  358. }
  359. void CMakeSetupDialog::doInstallForCommandLine()
  360. {
  361. QString title = tr("How to Install For Command Line Use");
  362. QString msg = tr(
  363. "One may add CMake to the PATH:\n"
  364. "\n"
  365. " PATH=\"%1\":\"$PATH\"\n"
  366. "\n"
  367. "Or, to install symlinks to '/usr/local/bin', run:\n"
  368. "\n"
  369. " sudo \"%2\" --install\n"
  370. "\n"
  371. "Or, to install symlinks to another directory, run:\n"
  372. "\n"
  373. " sudo \"%3\" --install=/path/to/bin\n"
  374. );
  375. msg = msg.arg(cmSystemTools::GetFilenamePath(
  376. cmSystemTools::GetCMakeCommand()).c_str());
  377. msg = msg.arg(cmSystemTools::GetCMakeGUICommand().c_str());
  378. msg = msg.arg(cmSystemTools::GetCMakeGUICommand().c_str());
  379. QDialog dialog;
  380. dialog.setWindowTitle(title);
  381. QVBoxLayout* l = new QVBoxLayout(&dialog);
  382. QLabel* lab = new QLabel(&dialog);
  383. l->addWidget(lab);
  384. lab->setText(msg);
  385. lab->setWordWrap(false);
  386. lab->setTextInteractionFlags(Qt::TextSelectableByMouse);
  387. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
  388. Qt::Horizontal, &dialog);
  389. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  390. l->addWidget(btns);
  391. dialog.exec();
  392. }
  393. bool CMakeSetupDialog::doGenerateInternal()
  394. {
  395. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  396. "generate", Qt::QueuedConnection);
  397. int err = this->LocalLoop.exec();
  398. if(err != 0)
  399. {
  400. QMessageBox::critical(this, tr("Error"),
  401. tr("Error in generation process, project files may be invalid"),
  402. QMessageBox::Ok);
  403. }
  404. return 0 == err;
  405. }
  406. void CMakeSetupDialog::doGenerate()
  407. {
  408. if(this->CurrentState == Generating)
  409. {
  410. // stop generate
  411. doInterrupt();
  412. return;
  413. }
  414. // see if we need to configure
  415. // we'll need to configure if:
  416. // the configure step hasn't been done yet
  417. // generate was the last step done
  418. if(this->ConfigureNeeded)
  419. {
  420. if(!prepareConfigure())
  421. {
  422. return;
  423. }
  424. }
  425. this->enterState(Generating);
  426. bool config_passed = true;
  427. if(this->ConfigureNeeded)
  428. {
  429. this->CacheValues->cacheModel()->setShowNewProperties(false);
  430. this->ProgressFactor = 0.5;
  431. config_passed = doConfigureInternal();
  432. this->ProgressOffset = 0.5;
  433. }
  434. if(config_passed)
  435. {
  436. doGenerateInternal();
  437. }
  438. this->ProgressOffset = 0.0;
  439. this->ProgressFactor = 1.0;
  440. this->CacheValues->cacheModel()->setShowNewProperties(true);
  441. this->enterState(ReadyConfigure);
  442. this->ProgressBar->reset();
  443. this->ConfigureNeeded = true;
  444. }
  445. void CMakeSetupDialog::closeEvent(QCloseEvent* e)
  446. {
  447. // prompt for close if there are unsaved changes, and we're not busy
  448. if(this->CacheModified)
  449. {
  450. QString msg = tr("You have changed options but not rebuilt, "
  451. "are you sure you want to exit?");
  452. QString title = tr("Confirm Exit");
  453. QMessageBox::StandardButton btn;
  454. btn = QMessageBox::critical(this, title, msg,
  455. QMessageBox::Yes | QMessageBox::No);
  456. if(btn == QMessageBox::No)
  457. {
  458. e->ignore();
  459. }
  460. }
  461. // don't close if we're busy, unless the user really wants to
  462. if(this->CurrentState == Configuring)
  463. {
  464. QString msg = tr("You are in the middle of a Configure.\n"
  465. "If you Exit now the configure information will be lost.\n"
  466. "Are you sure you want to Exit?");
  467. QString title = tr("Confirm Exit");
  468. QMessageBox::StandardButton btn;
  469. btn = QMessageBox::critical(this, title, msg,
  470. QMessageBox::Yes | QMessageBox::No);
  471. if(btn == QMessageBox::No)
  472. {
  473. e->ignore();
  474. }
  475. else
  476. {
  477. this->doInterrupt();
  478. }
  479. }
  480. // let the generate finish
  481. if(this->CurrentState == Generating)
  482. {
  483. e->ignore();
  484. }
  485. }
  486. void CMakeSetupDialog::doHelp()
  487. {
  488. QString msg = tr("CMake is used to configure and generate build files for "
  489. "software projects. The basic steps for configuring a project are as "
  490. "follows:\r\n\r\n1. Select the source directory for the project. This should "
  491. "contain the CMakeLists.txt files for the project.\r\n\r\n2. Select the build "
  492. "directory for the project. This is the directory where the project will be "
  493. "built. It can be the same or a different directory than the source "
  494. "directory. For easy clean up, a separate build directory is recommended. "
  495. "CMake will create the directory if it does not exist.\r\n\r\n3. Once the "
  496. "source and binary directories are selected, it is time to press the "
  497. "Configure button. This will cause CMake to read all of the input files and "
  498. "discover all the variables used by the project. The first time a variable "
  499. "is displayed it will be in Red. Users should inspect red variables making "
  500. "sure the values are correct. For some projects the Configure process can "
  501. "be iterative, so continue to press the Configure button until there are no "
  502. "longer red entries.\r\n\r\n4. Once there are no longer red entries, you "
  503. "should click the Generate button. This will write the build files to the build "
  504. "directory.");
  505. QDialog dialog;
  506. QFontMetrics met(this->font());
  507. int msgWidth = met.width(msg);
  508. dialog.setMinimumSize(msgWidth/15,20);
  509. dialog.setWindowTitle(tr("Help"));
  510. QVBoxLayout* l = new QVBoxLayout(&dialog);
  511. QLabel* lab = new QLabel(&dialog);
  512. lab->setText(msg);
  513. lab->setWordWrap(true);
  514. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
  515. Qt::Horizontal, &dialog);
  516. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  517. l->addWidget(lab);
  518. l->addWidget(btns);
  519. dialog.exec();
  520. }
  521. void CMakeSetupDialog::doInterrupt()
  522. {
  523. this->enterState(Interrupting);
  524. this->CMakeThread->cmakeInstance()->interrupt();
  525. }
  526. void CMakeSetupDialog::doSourceBrowse()
  527. {
  528. QString dir = QFileDialog::getExistingDirectory(this,
  529. tr("Enter Path to Source"), this->SourceDirectory->text(),
  530. QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
  531. if(!dir.isEmpty())
  532. {
  533. this->setSourceDirectory(dir);
  534. }
  535. }
  536. void CMakeSetupDialog::updateSourceDirectory(const QString& dir)
  537. {
  538. if(this->SourceDirectory->text() != dir)
  539. {
  540. this->SourceDirectory->blockSignals(true);
  541. this->SourceDirectory->setText(dir);
  542. this->SourceDirectory->blockSignals(false);
  543. }
  544. }
  545. void CMakeSetupDialog::updateBinaryDirectory(const QString& dir)
  546. {
  547. if(this->BinaryDirectory->currentText() != dir)
  548. {
  549. this->BinaryDirectory->blockSignals(true);
  550. this->BinaryDirectory->setEditText(dir);
  551. this->BinaryDirectory->blockSignals(false);
  552. }
  553. }
  554. void CMakeSetupDialog::doBinaryBrowse()
  555. {
  556. QString dir = QFileDialog::getExistingDirectory(this,
  557. tr("Enter Path to Build"), this->BinaryDirectory->currentText(),
  558. QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
  559. if(!dir.isEmpty() && dir != this->BinaryDirectory->currentText())
  560. {
  561. this->setBinaryDirectory(dir);
  562. }
  563. }
  564. void CMakeSetupDialog::setBinaryDirectory(const QString& dir)
  565. {
  566. this->BinaryDirectory->setEditText(dir);
  567. }
  568. void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
  569. {
  570. this->Output->clear();
  571. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  572. "setSourceDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
  573. }
  574. void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
  575. {
  576. QString title = QString(tr("CMake %1 - %2"));
  577. title = title.arg(cmVersion::GetCMakeVersion());
  578. title = title.arg(dir);
  579. this->setWindowTitle(title);
  580. this->CacheModified = false;
  581. this->CacheValues->cacheModel()->clear();
  582. qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())->clearChanges();
  583. this->Output->clear();
  584. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  585. "setBinaryDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
  586. }
  587. void CMakeSetupDialog::setSourceDirectory(const QString& dir)
  588. {
  589. this->SourceDirectory->setText(dir);
  590. }
  591. void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
  592. {
  593. percent = (percent * ProgressFactor) + ProgressOffset;
  594. this->ProgressBar->setValue(qRound(percent * 100));
  595. }
  596. void CMakeSetupDialog::error(const QString& msg)
  597. {
  598. this->Output->setCurrentCharFormat(this->ErrorFormat);
  599. //QTextEdit will terminate the msg with a ParagraphSeparator, but it also replaces
  600. //all newlines with ParagraphSeparators. By replacing the newlines by ourself, one
  601. //error msg will be one paragraph.
  602. QString paragraph(msg);
  603. paragraph.replace(QLatin1Char('\n'), QChar::LineSeparator);
  604. this->Output->append(paragraph);
  605. }
  606. void CMakeSetupDialog::message(const QString& msg)
  607. {
  608. this->Output->setCurrentCharFormat(this->MessageFormat);
  609. this->Output->append(msg);
  610. }
  611. void CMakeSetupDialog::setEnabledState(bool enabled)
  612. {
  613. // disable parts of the GUI during configure/generate
  614. this->CacheValues->cacheModel()->setEditEnabled(enabled);
  615. this->SourceDirectory->setEnabled(enabled);
  616. this->BrowseSourceDirectoryButton->setEnabled(enabled);
  617. this->BinaryDirectory->setEnabled(enabled);
  618. this->BrowseBinaryDirectoryButton->setEnabled(enabled);
  619. this->ReloadCacheAction->setEnabled(enabled);
  620. this->DeleteCacheAction->setEnabled(enabled);
  621. this->ExitAction->setEnabled(enabled);
  622. this->ConfigureAction->setEnabled(enabled);
  623. this->AddEntry->setEnabled(enabled);
  624. this->RemoveEntry->setEnabled(false); // let selection re-enable it
  625. }
  626. bool CMakeSetupDialog::setupFirstConfigure()
  627. {
  628. FirstConfigure dialog;
  629. // initialize dialog and restore saved settings
  630. // add generators
  631. dialog.setGenerators(this->CMakeThread->cmakeInstance()->availableGenerators());
  632. // restore from settings
  633. dialog.loadFromSettings();
  634. if(dialog.exec() == QDialog::Accepted)
  635. {
  636. dialog.saveToSettings();
  637. this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator());
  638. this->CMakeThread->cmakeInstance()->setToolset(dialog.getToolset());
  639. QCMakeCacheModel* m = this->CacheValues->cacheModel();
  640. if(dialog.compilerSetup())
  641. {
  642. QString fortranCompiler = dialog.getFortranCompiler();
  643. if(!fortranCompiler.isEmpty())
  644. {
  645. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
  646. "Fortran compiler.", fortranCompiler, false);
  647. }
  648. QString cxxCompiler = dialog.getCXXCompiler();
  649. if(!cxxCompiler.isEmpty())
  650. {
  651. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
  652. "CXX compiler.", cxxCompiler, false);
  653. }
  654. QString cCompiler = dialog.getCCompiler();
  655. if(!cCompiler.isEmpty())
  656. {
  657. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
  658. "C compiler.", cCompiler, false);
  659. }
  660. }
  661. else if(dialog.crossCompilerSetup())
  662. {
  663. QString fortranCompiler = dialog.getFortranCompiler();
  664. if(!fortranCompiler.isEmpty())
  665. {
  666. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
  667. "Fortran compiler.", fortranCompiler, false);
  668. }
  669. QString mode = dialog.getCrossIncludeMode();
  670. m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE",
  671. tr("CMake Find Include Mode"), mode, false);
  672. mode = dialog.getCrossLibraryMode();
  673. m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
  674. tr("CMake Find Library Mode"), mode, false);
  675. mode = dialog.getCrossProgramMode();
  676. m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
  677. tr("CMake Find Program Mode"), mode, false);
  678. QString rootPath = dialog.getCrossRoot();
  679. m->insertProperty(QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH",
  680. tr("CMake Find Root Path"), rootPath, false);
  681. QString systemName = dialog.getSystemName();
  682. m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME",
  683. tr("CMake System Name"), systemName, false);
  684. QString systemVersion = dialog.getSystemVersion();
  685. m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_VERSION",
  686. tr("CMake System Version"), systemVersion, false);
  687. QString cxxCompiler = dialog.getCXXCompiler();
  688. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
  689. tr("CXX compiler."), cxxCompiler, false);
  690. QString cCompiler = dialog.getCCompiler();
  691. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
  692. tr("C compiler."), cCompiler, false);
  693. }
  694. else if(dialog.crossCompilerToolChainFile())
  695. {
  696. QString toolchainFile = dialog.getCrossCompilerToolChainFile();
  697. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE",
  698. tr("Cross Compile ToolChain File"), toolchainFile, false);
  699. }
  700. return true;
  701. }
  702. return false;
  703. }
  704. void CMakeSetupDialog::updateGeneratorLabel(const QString& gen)
  705. {
  706. QString str = tr("Current Generator: ");
  707. if(gen.isEmpty())
  708. {
  709. str += tr("None");
  710. }
  711. else
  712. {
  713. str += gen;
  714. }
  715. this->Generator->setText(str);
  716. }
  717. void CMakeSetupDialog::doReloadCache()
  718. {
  719. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  720. "reloadCache", Qt::QueuedConnection);
  721. }
  722. void CMakeSetupDialog::doDeleteCache()
  723. {
  724. QString title = tr("Delete Cache");
  725. QString msg = tr("Are you sure you want to delete the cache?");
  726. QMessageBox::StandardButton btn;
  727. btn = QMessageBox::information(this, title, msg,
  728. QMessageBox::Yes | QMessageBox::No);
  729. if(btn == QMessageBox::No)
  730. {
  731. return;
  732. }
  733. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  734. "deleteCache", Qt::QueuedConnection);
  735. }
  736. void CMakeSetupDialog::doAbout()
  737. {
  738. QString msg = tr(
  739. "CMake %1 (cmake.org).\n"
  740. "CMake suite maintained and supported by Kitware (kitware.com/cmake).\n"
  741. "Distributed under terms of the BSD 3-Clause License.\n"
  742. "\n"
  743. "CMake GUI maintained by csimsoft,\n"
  744. "built using Qt %2 (qt-project.org).\n"
  745. #ifdef CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL
  746. "\n"
  747. "The Qt Toolkit is Copyright (C) Digia Plc and/or its subsidiary(-ies).\n"
  748. "Qt is licensed under terms of the GNU LGPLv2.1, available at:\n"
  749. " \"%3\""
  750. #endif
  751. );
  752. msg = msg.arg(cmVersion::GetCMakeVersion());
  753. msg = msg.arg(qVersion());
  754. #ifdef CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL
  755. std::string lgpl = cmSystemTools::GetCMakeRoot()+"/Licenses/LGPLv2.1.txt";
  756. msg = msg.arg(lgpl.c_str());
  757. #endif
  758. QDialog dialog;
  759. dialog.setWindowTitle(tr("About"));
  760. QVBoxLayout* l = new QVBoxLayout(&dialog);
  761. QLabel* lab = new QLabel(&dialog);
  762. l->addWidget(lab);
  763. lab->setText(msg);
  764. lab->setWordWrap(true);
  765. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
  766. Qt::Horizontal, &dialog);
  767. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  768. l->addWidget(btns);
  769. dialog.exec();
  770. }
  771. void CMakeSetupDialog::setExitAfterGenerate(bool b)
  772. {
  773. this->ExitAfterGenerate = b;
  774. }
  775. void CMakeSetupDialog::addBinaryPath(const QString& path)
  776. {
  777. QString cleanpath = QDir::cleanPath(path);
  778. // update UI
  779. this->BinaryDirectory->blockSignals(true);
  780. int idx = this->BinaryDirectory->findText(cleanpath);
  781. if(idx != -1)
  782. {
  783. this->BinaryDirectory->removeItem(idx);
  784. }
  785. this->BinaryDirectory->insertItem(0, cleanpath);
  786. this->BinaryDirectory->setCurrentIndex(0);
  787. this->BinaryDirectory->blockSignals(false);
  788. // save to registry
  789. QStringList buildPaths = this->loadBuildPaths();
  790. buildPaths.removeAll(cleanpath);
  791. buildPaths.prepend(cleanpath);
  792. this->saveBuildPaths(buildPaths);
  793. }
  794. void CMakeSetupDialog::dragEnterEvent(QDragEnterEvent* e)
  795. {
  796. if(!(this->CurrentState == ReadyConfigure ||
  797. this->CurrentState == ReadyGenerate))
  798. {
  799. e->ignore();
  800. return;
  801. }
  802. const QMimeData* dat = e->mimeData();
  803. QList<QUrl> urls = dat->urls();
  804. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  805. if(!file.isEmpty() &&
  806. (file.endsWith("CMakeCache.txt", Qt::CaseInsensitive) ||
  807. file.endsWith("CMakeLists.txt", Qt::CaseInsensitive) ) )
  808. {
  809. e->accept();
  810. }
  811. else
  812. {
  813. e->ignore();
  814. }
  815. }
  816. void CMakeSetupDialog::dropEvent(QDropEvent* e)
  817. {
  818. if(!(this->CurrentState == ReadyConfigure ||
  819. this->CurrentState == ReadyGenerate))
  820. {
  821. return;
  822. }
  823. const QMimeData* dat = e->mimeData();
  824. QList<QUrl> urls = dat->urls();
  825. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  826. if(file.endsWith("CMakeCache.txt", Qt::CaseInsensitive))
  827. {
  828. QFileInfo info(file);
  829. if(this->CMakeThread->cmakeInstance()->binaryDirectory() != info.absolutePath())
  830. {
  831. this->setBinaryDirectory(info.absolutePath());
  832. }
  833. }
  834. else if(file.endsWith("CMakeLists.txt", Qt::CaseInsensitive))
  835. {
  836. QFileInfo info(file);
  837. if(this->CMakeThread->cmakeInstance()->binaryDirectory() != info.absolutePath())
  838. {
  839. this->setSourceDirectory(info.absolutePath());
  840. this->setBinaryDirectory(info.absolutePath());
  841. }
  842. }
  843. }
  844. QStringList CMakeSetupDialog::loadBuildPaths()
  845. {
  846. QSettings settings;
  847. settings.beginGroup("Settings/StartPath");
  848. QStringList buildPaths;
  849. for(int i=0; i<10; i++)
  850. {
  851. QString p = settings.value(QString("WhereBuild%1").arg(i)).toString();
  852. if(!p.isEmpty())
  853. {
  854. buildPaths.append(p);
  855. }
  856. }
  857. return buildPaths;
  858. }
  859. void CMakeSetupDialog::saveBuildPaths(const QStringList& paths)
  860. {
  861. QSettings settings;
  862. settings.beginGroup("Settings/StartPath");
  863. int num = paths.count();
  864. if(num > 10)
  865. {
  866. num = 10;
  867. }
  868. for(int i=0; i<num; i++)
  869. {
  870. settings.setValue(QString("WhereBuild%1").arg(i), paths[i]);
  871. }
  872. }
  873. void CMakeSetupDialog::setCacheModified()
  874. {
  875. this->CacheModified = true;
  876. this->ConfigureNeeded = true;
  877. this->enterState(ReadyConfigure);
  878. }
  879. void CMakeSetupDialog::removeSelectedCacheEntries()
  880. {
  881. QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
  882. QList<QPersistentModelIndex> pidxs;
  883. foreach(QModelIndex i, idxs)
  884. {
  885. pidxs.append(i);
  886. }
  887. foreach(QPersistentModelIndex pi, pidxs)
  888. {
  889. this->CacheValues->model()->removeRow(pi.row(), pi.parent());
  890. }
  891. }
  892. void CMakeSetupDialog::selectionChanged()
  893. {
  894. QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
  895. if(idxs.count() &&
  896. (this->CurrentState == ReadyConfigure ||
  897. this->CurrentState == ReadyGenerate) )
  898. {
  899. this->RemoveEntry->setEnabled(true);
  900. }
  901. else
  902. {
  903. this->RemoveEntry->setEnabled(false);
  904. }
  905. }
  906. void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
  907. {
  908. if(s == this->CurrentState)
  909. {
  910. return;
  911. }
  912. this->CurrentState = s;
  913. if(s == Interrupting)
  914. {
  915. this->ConfigureButton->setEnabled(false);
  916. this->GenerateButton->setEnabled(false);
  917. }
  918. else if(s == Configuring)
  919. {
  920. this->setEnabledState(false);
  921. this->GenerateButton->setEnabled(false);
  922. this->GenerateAction->setEnabled(false);
  923. this->ConfigureButton->setText(tr("&Stop"));
  924. }
  925. else if(s == Generating)
  926. {
  927. this->CacheModified = false;
  928. this->setEnabledState(false);
  929. this->ConfigureButton->setEnabled(false);
  930. this->GenerateAction->setEnabled(false);
  931. this->GenerateButton->setText(tr("&Stop"));
  932. }
  933. else if(s == ReadyConfigure)
  934. {
  935. this->setEnabledState(true);
  936. this->GenerateButton->setEnabled(true);
  937. this->GenerateAction->setEnabled(true);
  938. this->ConfigureButton->setEnabled(true);
  939. this->ConfigureButton->setText(tr("&Configure"));
  940. this->GenerateButton->setText(tr("&Generate"));
  941. }
  942. else if(s == ReadyGenerate)
  943. {
  944. this->setEnabledState(true);
  945. this->GenerateButton->setEnabled(true);
  946. this->GenerateAction->setEnabled(true);
  947. this->ConfigureButton->setEnabled(true);
  948. this->ConfigureButton->setText(tr("&Configure"));
  949. this->GenerateButton->setText(tr("&Generate"));
  950. }
  951. }
  952. void CMakeSetupDialog::addCacheEntry()
  953. {
  954. QDialog dialog(this);
  955. dialog.resize(400, 200);
  956. dialog.setWindowTitle(tr("Add Cache Entry"));
  957. QVBoxLayout* l = new QVBoxLayout(&dialog);
  958. AddCacheEntry* w = new AddCacheEntry(&dialog, this->AddVariableNames,
  959. this->AddVariableTypes);
  960. QDialogButtonBox* btns = new QDialogButtonBox(
  961. QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
  962. Qt::Horizontal, &dialog);
  963. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  964. QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(reject()));
  965. l->addWidget(w);
  966. l->addStretch();
  967. l->addWidget(btns);
  968. if(QDialog::Accepted == dialog.exec())
  969. {
  970. QCMakeCacheModel* m = this->CacheValues->cacheModel();
  971. m->insertProperty(w->type(), w->name(), w->description(), w->value(), false);
  972. // only add variable names to the completion which are new
  973. if (!this->AddVariableNames.contains(w->name()))
  974. {
  975. this->AddVariableNames << w->name();
  976. this->AddVariableTypes << w->typeString();
  977. // limit to at most 100 completion items
  978. if (this->AddVariableNames.size() > 100)
  979. {
  980. this->AddVariableNames.removeFirst();
  981. this->AddVariableTypes.removeFirst();
  982. }
  983. // make sure CMAKE_INSTALL_PREFIX is always there
  984. if (!this->AddVariableNames.contains("CMAKE_INSTALL_PREFIX"))
  985. {
  986. this->AddVariableNames << "CMAKE_INSTALL_PREFIX";
  987. this->AddVariableTypes << "PATH";
  988. }
  989. QSettings settings;
  990. settings.beginGroup("Settings/StartPath");
  991. settings.setValue("AddVariableNames", this->AddVariableNames);
  992. settings.setValue("AddVariableTypes", this->AddVariableTypes);
  993. }
  994. }
  995. }
  996. void CMakeSetupDialog::startSearch()
  997. {
  998. this->Search->setFocus(Qt::OtherFocusReason);
  999. this->Search->selectAll();
  1000. }
  1001. void CMakeSetupDialog::setDebugOutput(bool flag)
  1002. {
  1003. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  1004. "setDebugOutput", Qt::QueuedConnection, Q_ARG(bool, flag));
  1005. }
  1006. void CMakeSetupDialog::setGroupedView(bool v)
  1007. {
  1008. this->CacheValues->cacheModel()->setViewType(v ? QCMakeCacheModel::GroupView : QCMakeCacheModel::FlatView);
  1009. this->CacheValues->setRootIsDecorated(v);
  1010. QSettings settings;
  1011. settings.beginGroup("Settings/StartPath");
  1012. settings.setValue("GroupView", v);
  1013. }
  1014. void CMakeSetupDialog::setAdvancedView(bool v)
  1015. {
  1016. this->CacheValues->setShowAdvanced(v);
  1017. QSettings settings;
  1018. settings.beginGroup("Settings/StartPath");
  1019. settings.setValue("AdvancedView", v);
  1020. }
  1021. void CMakeSetupDialog::showUserChanges()
  1022. {
  1023. QSet<QCMakeProperty> changes =
  1024. qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())->changes();
  1025. QDialog dialog(this);
  1026. dialog.setWindowTitle(tr("My Changes"));
  1027. dialog.resize(600, 400);
  1028. QVBoxLayout* l = new QVBoxLayout(&dialog);
  1029. QTextEdit* textedit = new QTextEdit(&dialog);
  1030. textedit->setReadOnly(true);
  1031. l->addWidget(textedit);
  1032. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Close,
  1033. Qt::Horizontal, &dialog);
  1034. QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(accept()));
  1035. l->addWidget(btns);
  1036. QString command;
  1037. QString cache;
  1038. foreach(QCMakeProperty prop, changes)
  1039. {
  1040. QString type;
  1041. switch(prop.Type)
  1042. {
  1043. case QCMakeProperty::BOOL:
  1044. type = "BOOL";
  1045. break;
  1046. case QCMakeProperty::PATH:
  1047. type = "PATH";
  1048. break;
  1049. case QCMakeProperty::FILEPATH:
  1050. type = "FILEPATH";
  1051. break;
  1052. case QCMakeProperty::STRING:
  1053. type = "STRING";
  1054. break;
  1055. }
  1056. QString value;
  1057. if(prop.Type == QCMakeProperty::BOOL)
  1058. {
  1059. value = prop.Value.toBool() ? "1" : "0";
  1060. }
  1061. else
  1062. {
  1063. value = prop.Value.toString();
  1064. }
  1065. QString line("%1:%2=");
  1066. line = line.arg(prop.Key);
  1067. line = line.arg(type);
  1068. command += QString("-D%1\"%2\" ").arg(line).arg(value);
  1069. cache += QString("%1%2\n").arg(line).arg(value);
  1070. }
  1071. textedit->append(tr("Commandline options:"));
  1072. textedit->append(command);
  1073. textedit->append("\n");
  1074. textedit->append(tr("Cache file:"));
  1075. textedit->append(cache);
  1076. dialog.exec();
  1077. }
  1078. void CMakeSetupDialog::setSearchFilter(const QString& str)
  1079. {
  1080. this->CacheValues->selectionModel()->clear();
  1081. this->CacheValues->setSearchFilter(str);
  1082. }
  1083. void CMakeSetupDialog::doOutputContextMenu(const QPoint &pt)
  1084. {
  1085. QMenu *menu = this->Output->createStandardContextMenu();
  1086. menu->addSeparator();
  1087. menu->addAction(tr("Find..."),
  1088. this, SLOT(doOutputFindDialog()), QKeySequence::Find);
  1089. menu->addAction(tr("Find Next"),
  1090. this, SLOT(doOutputFindNext()), QKeySequence::FindNext);
  1091. menu->addAction(tr("Find Previous"),
  1092. this, SLOT(doOutputFindPrev()), QKeySequence::FindPrevious);
  1093. menu->addSeparator();
  1094. menu->addAction(tr("Goto Next Error"),
  1095. this, SLOT(doOutputErrorNext()), QKeySequence(Qt::Key_F8));
  1096. menu->exec(this->Output->mapToGlobal(pt));
  1097. delete menu;
  1098. }
  1099. void CMakeSetupDialog::doOutputFindDialog()
  1100. {
  1101. QStringList strings(this->FindHistory);
  1102. QString selection = this->Output->textCursor().selectedText();
  1103. if (!selection.isEmpty() &&
  1104. !selection.contains(QChar::ParagraphSeparator) &&
  1105. !selection.contains(QChar::LineSeparator))
  1106. {
  1107. strings.push_front(selection);
  1108. }
  1109. bool ok;
  1110. QString search = QInputDialog::getItem(this, tr("Find in Output"),
  1111. tr("Find:"), strings, 0, true, &ok);
  1112. if (ok && !search.isEmpty())
  1113. {
  1114. if (!this->FindHistory.contains(search))
  1115. {
  1116. this->FindHistory.push_front(search);
  1117. }
  1118. doOutputFindNext();
  1119. }
  1120. }
  1121. void CMakeSetupDialog::doRegexExplorerDialog()
  1122. {
  1123. RegexExplorer dialog(this);
  1124. dialog.exec();
  1125. }
  1126. void CMakeSetupDialog::doOutputFindPrev()
  1127. {
  1128. doOutputFindNext(false);
  1129. }
  1130. void CMakeSetupDialog::doOutputFindNext(bool directionForward)
  1131. {
  1132. if (this->FindHistory.isEmpty())
  1133. {
  1134. doOutputFindDialog(); //will re-call this function again
  1135. return;
  1136. }
  1137. QString search = this->FindHistory.front();
  1138. QTextCursor textCursor = this->Output->textCursor();
  1139. QTextDocument* document = this->Output->document();
  1140. QTextDocument::FindFlags flags;
  1141. if (!directionForward)
  1142. {
  1143. flags |= QTextDocument::FindBackward;
  1144. }
  1145. textCursor = document->find(search, textCursor, flags);
  1146. if (textCursor.isNull())
  1147. {
  1148. // first search found nothing, wrap around and search again
  1149. textCursor = this->Output->textCursor();
  1150. textCursor.movePosition(directionForward ? QTextCursor::Start
  1151. : QTextCursor::End);
  1152. textCursor = document->find(search, textCursor, flags);
  1153. }
  1154. if (textCursor.hasSelection())
  1155. {
  1156. this->Output->setTextCursor(textCursor);
  1157. }
  1158. }
  1159. void CMakeSetupDialog::doOutputErrorNext()
  1160. {
  1161. QTextCursor textCursor = this->Output->textCursor();
  1162. bool atEnd = false;
  1163. // move cursor out of current error-block
  1164. if (textCursor.blockCharFormat() == this->ErrorFormat)
  1165. {
  1166. atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
  1167. }
  1168. // move cursor to next error-block
  1169. while (textCursor.blockCharFormat() != this->ErrorFormat && !atEnd)
  1170. {
  1171. atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
  1172. }
  1173. if (atEnd)
  1174. {
  1175. // first search found nothing, wrap around and search again
  1176. atEnd = !textCursor.movePosition(QTextCursor::Start);
  1177. // move cursor to next error-block
  1178. while (textCursor.blockCharFormat() != this->ErrorFormat && !atEnd)
  1179. {
  1180. atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
  1181. }
  1182. }
  1183. if (!atEnd)
  1184. {
  1185. textCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
  1186. QTextCharFormat selectionFormat;
  1187. selectionFormat.setBackground(Qt::yellow);
  1188. QTextEdit::ExtraSelection extraSelection = {textCursor, selectionFormat};
  1189. this->Output->setExtraSelections(QList<QTextEdit::ExtraSelection>()
  1190. << extraSelection);
  1191. // make the whole error-block visible
  1192. this->Output->setTextCursor(textCursor);
  1193. // remove the selection to see the extraSelection
  1194. textCursor.setPosition(textCursor.anchor());
  1195. this->Output->setTextCursor(textCursor);
  1196. }
  1197. }