CMakeSetupDialog.cxx 43 KB

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