CMakeSetupDialog.cxx 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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 macOS
  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() &&
  863. (this->CurrentState == ReadyConfigure ||
  864. this->CurrentState == ReadyGenerate)) {
  865. this->RemoveEntry->setEnabled(true);
  866. } else {
  867. this->RemoveEntry->setEnabled(false);
  868. }
  869. }
  870. void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
  871. {
  872. if (s == this->CurrentState) {
  873. return;
  874. }
  875. this->CurrentState = s;
  876. if (s == Interrupting) {
  877. this->ConfigureButton->setEnabled(false);
  878. this->GenerateButton->setEnabled(false);
  879. this->OpenProjectButton->setEnabled(false);
  880. } else if (s == Configuring) {
  881. this->setEnabledState(false);
  882. this->GenerateButton->setEnabled(false);
  883. this->GenerateAction->setEnabled(false);
  884. this->OpenProjectButton->setEnabled(false);
  885. this->ConfigureButton->setText(tr("&Stop"));
  886. } else if (s == Generating) {
  887. this->CacheModified = false;
  888. this->setEnabledState(false);
  889. this->ConfigureButton->setEnabled(false);
  890. this->GenerateAction->setEnabled(false);
  891. this->OpenProjectButton->setEnabled(false);
  892. this->GenerateButton->setText(tr("&Stop"));
  893. } else if (s == ReadyConfigure) {
  894. this->setEnabledState(true);
  895. this->GenerateButton->setEnabled(true);
  896. this->GenerateAction->setEnabled(true);
  897. this->ConfigureButton->setEnabled(true);
  898. this->ConfigureButton->setText(tr("&Configure"));
  899. this->GenerateButton->setText(tr("&Generate"));
  900. } else if (s == ReadyGenerate) {
  901. this->setEnabledState(true);
  902. this->GenerateButton->setEnabled(true);
  903. this->GenerateAction->setEnabled(true);
  904. this->ConfigureButton->setEnabled(true);
  905. this->ConfigureButton->setText(tr("&Configure"));
  906. this->GenerateButton->setText(tr("&Generate"));
  907. }
  908. }
  909. void CMakeSetupDialog::addCacheEntry()
  910. {
  911. QDialog dialog(this);
  912. dialog.resize(400, 200);
  913. dialog.setWindowTitle(tr("Add Cache Entry"));
  914. QVBoxLayout* l = new QVBoxLayout(&dialog);
  915. AddCacheEntry* w =
  916. new AddCacheEntry(&dialog, this->AddVariableNames, this->AddVariableTypes);
  917. QDialogButtonBox* btns = new QDialogButtonBox(
  918. QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
  919. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  920. QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(reject()));
  921. l->addWidget(w);
  922. l->addStretch();
  923. l->addWidget(btns);
  924. if (QDialog::Accepted == dialog.exec()) {
  925. QCMakeCacheModel* m = this->CacheValues->cacheModel();
  926. m->insertProperty(w->type(), w->name(), w->description(), w->value(),
  927. false);
  928. // only add variable names to the completion which are new
  929. if (!this->AddVariableNames.contains(w->name())) {
  930. this->AddVariableNames << w->name();
  931. this->AddVariableTypes << w->typeString();
  932. // limit to at most 100 completion items
  933. if (this->AddVariableNames.size() > 100) {
  934. this->AddVariableNames.removeFirst();
  935. this->AddVariableTypes.removeFirst();
  936. }
  937. // make sure CMAKE_INSTALL_PREFIX is always there
  938. if (!this->AddVariableNames.contains("CMAKE_INSTALL_PREFIX")) {
  939. this->AddVariableNames << "CMAKE_INSTALL_PREFIX";
  940. this->AddVariableTypes << "PATH";
  941. }
  942. QSettings settings;
  943. settings.beginGroup("Settings/StartPath");
  944. settings.setValue("AddVariableNames", this->AddVariableNames);
  945. settings.setValue("AddVariableTypes", this->AddVariableTypes);
  946. }
  947. }
  948. }
  949. void CMakeSetupDialog::startSearch()
  950. {
  951. this->Search->setFocus(Qt::OtherFocusReason);
  952. this->Search->selectAll();
  953. }
  954. void CMakeSetupDialog::setDebugOutput(bool flag)
  955. {
  956. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  957. "setDebugOutput", Qt::QueuedConnection,
  958. Q_ARG(bool, flag));
  959. }
  960. void CMakeSetupDialog::setGroupedView(bool v)
  961. {
  962. this->CacheValues->cacheModel()->setViewType(v ? QCMakeCacheModel::GroupView
  963. : QCMakeCacheModel::FlatView);
  964. this->CacheValues->setRootIsDecorated(v);
  965. QSettings settings;
  966. settings.beginGroup("Settings/StartPath");
  967. settings.setValue("GroupView", v);
  968. }
  969. void CMakeSetupDialog::setAdvancedView(bool v)
  970. {
  971. this->CacheValues->setShowAdvanced(v);
  972. QSettings settings;
  973. settings.beginGroup("Settings/StartPath");
  974. settings.setValue("AdvancedView", v);
  975. }
  976. void CMakeSetupDialog::showUserChanges()
  977. {
  978. QSet<QCMakeProperty> changes =
  979. qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())
  980. ->changes();
  981. QDialog dialog(this);
  982. dialog.setWindowTitle(tr("My Changes"));
  983. dialog.resize(600, 400);
  984. QVBoxLayout* l = new QVBoxLayout(&dialog);
  985. QTextEdit* textedit = new QTextEdit(&dialog);
  986. textedit->setReadOnly(true);
  987. l->addWidget(textedit);
  988. QDialogButtonBox* btns =
  989. new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
  990. QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(accept()));
  991. l->addWidget(btns);
  992. QString command;
  993. QString cache;
  994. foreach (QCMakeProperty const& prop, changes) {
  995. QString type;
  996. switch (prop.Type) {
  997. case QCMakeProperty::BOOL:
  998. type = "BOOL";
  999. break;
  1000. case QCMakeProperty::PATH:
  1001. type = "PATH";
  1002. break;
  1003. case QCMakeProperty::FILEPATH:
  1004. type = "FILEPATH";
  1005. break;
  1006. case QCMakeProperty::STRING:
  1007. type = "STRING";
  1008. break;
  1009. }
  1010. QString value;
  1011. if (prop.Type == QCMakeProperty::BOOL) {
  1012. value = prop.Value.toBool() ? "1" : "0";
  1013. } else {
  1014. value = prop.Value.toString();
  1015. }
  1016. QString const line = QString("%1:%2=").arg(prop.Key, type);
  1017. command += QString("-D%1\"%2\" ").arg(line, value);
  1018. cache += QString("%1%2\n").arg(line, value);
  1019. }
  1020. textedit->append(tr("Commandline options:"));
  1021. textedit->append(command);
  1022. textedit->append("\n");
  1023. textedit->append(tr("Cache file:"));
  1024. textedit->append(cache);
  1025. dialog.exec();
  1026. }
  1027. void CMakeSetupDialog::setSearchFilter(const QString& str)
  1028. {
  1029. this->CacheValues->selectionModel()->clear();
  1030. this->CacheValues->setSearchFilter(str);
  1031. }
  1032. void CMakeSetupDialog::doOutputContextMenu(QPoint pt)
  1033. {
  1034. QMenu* menu = this->Output->createStandardContextMenu();
  1035. menu->addSeparator();
  1036. menu->addAction(tr("Find..."), this, SLOT(doOutputFindDialog()),
  1037. QKeySequence::Find);
  1038. menu->addAction(tr("Find Next"), this, SLOT(doOutputFindNext()),
  1039. QKeySequence::FindNext);
  1040. menu->addAction(tr("Find Previous"), this, SLOT(doOutputFindPrev()),
  1041. QKeySequence::FindPrevious);
  1042. menu->addSeparator();
  1043. menu->addAction(tr("Goto Next Error"), this, SLOT(doOutputErrorNext()),
  1044. QKeySequence(Qt::Key_F8));
  1045. menu->exec(this->Output->mapToGlobal(pt));
  1046. delete menu;
  1047. }
  1048. void CMakeSetupDialog::doOutputFindDialog()
  1049. {
  1050. QStringList strings(this->FindHistory);
  1051. QString selection = this->Output->textCursor().selectedText();
  1052. if (!selection.isEmpty() && !selection.contains(QChar::ParagraphSeparator) &&
  1053. !selection.contains(QChar::LineSeparator)) {
  1054. strings.push_front(selection);
  1055. }
  1056. bool ok;
  1057. QString search = QInputDialog::getItem(this, tr("Find in Output"),
  1058. tr("Find:"), strings, 0, true, &ok);
  1059. if (ok && !search.isEmpty()) {
  1060. if (!this->FindHistory.contains(search)) {
  1061. this->FindHistory.push_front(search);
  1062. }
  1063. doOutputFindNext();
  1064. }
  1065. }
  1066. void CMakeSetupDialog::doRegexExplorerDialog()
  1067. {
  1068. RegexExplorer dialog(this);
  1069. dialog.exec();
  1070. }
  1071. void CMakeSetupDialog::doOutputFindPrev()
  1072. {
  1073. doOutputFindNext(false);
  1074. }
  1075. void CMakeSetupDialog::doOutputFindNext(bool directionForward)
  1076. {
  1077. if (this->FindHistory.isEmpty()) {
  1078. doOutputFindDialog(); // will re-call this function again
  1079. return;
  1080. }
  1081. QString search = this->FindHistory.front();
  1082. QTextCursor textCursor = this->Output->textCursor();
  1083. QTextDocument* document = this->Output->document();
  1084. QTextDocument::FindFlags flags;
  1085. if (!directionForward) {
  1086. flags |= QTextDocument::FindBackward;
  1087. }
  1088. textCursor = document->find(search, textCursor, flags);
  1089. if (textCursor.isNull()) {
  1090. // first search found nothing, wrap around and search again
  1091. textCursor = this->Output->textCursor();
  1092. textCursor.movePosition(directionForward ? QTextCursor::Start
  1093. : QTextCursor::End);
  1094. textCursor = document->find(search, textCursor, flags);
  1095. }
  1096. if (textCursor.hasSelection()) {
  1097. this->Output->setTextCursor(textCursor);
  1098. }
  1099. }
  1100. void CMakeSetupDialog::doOutputErrorNext()
  1101. {
  1102. QTextCursor textCursor = this->Output->textCursor();
  1103. bool atEnd = false;
  1104. // move cursor out of current error-block
  1105. if (textCursor.blockCharFormat() == this->ErrorFormat) {
  1106. atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
  1107. }
  1108. // move cursor to next error-block
  1109. while (textCursor.blockCharFormat() != this->ErrorFormat && !atEnd) {
  1110. atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
  1111. }
  1112. if (atEnd) {
  1113. // first search found nothing, wrap around and search again
  1114. atEnd = !textCursor.movePosition(QTextCursor::Start);
  1115. // move cursor to next error-block
  1116. while (textCursor.blockCharFormat() != this->ErrorFormat && !atEnd) {
  1117. atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
  1118. }
  1119. }
  1120. if (!atEnd) {
  1121. textCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
  1122. QTextCharFormat selectionFormat;
  1123. selectionFormat.setBackground(Qt::yellow);
  1124. QTextEdit::ExtraSelection extraSelection = { textCursor, selectionFormat };
  1125. this->Output->setExtraSelections(QList<QTextEdit::ExtraSelection>()
  1126. << extraSelection);
  1127. // make the whole error-block visible
  1128. this->Output->setTextCursor(textCursor);
  1129. // remove the selection to see the extraSelection
  1130. textCursor.setPosition(textCursor.anchor());
  1131. this->Output->setTextCursor(textCursor);
  1132. }
  1133. }
  1134. void CMakeSetupDialog::doWarningMessagesDialog()
  1135. {
  1136. WarningMessagesDialog dialog(this, this->CMakeThread->cmakeInstance());
  1137. dialog.exec();
  1138. }