CMakeSetupDialog.cxx 40 KB

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