CMakeSetupDialog.cxx 42 KB

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