/Source/QtDialog/FirstConfigure.cxx

https://github.com/thewtex/CMake · C++ · 509 lines · 411 code · 90 blank · 8 comment · 15 complexity · 000111646c7bec2297137d0cf2c7f825 MD5 · raw file

  1. #include "FirstConfigure.h"
  2. #include "Compilers.h"
  3. #include <QSettings>
  4. #include <QRadioButton>
  5. #include <QComboBox>
  6. #include <QVBoxLayout>
  7. StartCompilerSetup::StartCompilerSetup(QWidget* p)
  8. : QWizardPage(p)
  9. {
  10. QVBoxLayout* l = new QVBoxLayout(this);
  11. l->addWidget(new QLabel(tr("Specify the generator for this project")));
  12. this->GeneratorOptions = new QComboBox(this);
  13. l->addWidget(this->GeneratorOptions);
  14. l->addSpacing(6);
  15. this->CompilerSetupOptions[0] = new QRadioButton(tr("Use default native compilers"), this);
  16. this->CompilerSetupOptions[1] = new QRadioButton(tr("Specify native compilers"), this);
  17. this->CompilerSetupOptions[2] = new QRadioButton(tr("Specify toolchain file for cross-compiling"), this);
  18. this->CompilerSetupOptions[3] = new QRadioButton(tr("Specify options for cross-compiling"), this);
  19. l->addWidget(this->CompilerSetupOptions[0]);
  20. l->addWidget(this->CompilerSetupOptions[1]);
  21. l->addWidget(this->CompilerSetupOptions[2]);
  22. l->addWidget(this->CompilerSetupOptions[3]);
  23. this->CompilerSetupOptions[0]->setChecked(true);
  24. QObject::connect(this->CompilerSetupOptions[0], SIGNAL(toggled(bool)),
  25. this, SLOT(onSelectionChanged(bool)));
  26. QObject::connect(this->CompilerSetupOptions[1], SIGNAL(toggled(bool)),
  27. this, SLOT(onSelectionChanged(bool)));
  28. QObject::connect(this->CompilerSetupOptions[2], SIGNAL(toggled(bool)),
  29. this, SLOT(onSelectionChanged(bool)));
  30. QObject::connect(this->CompilerSetupOptions[3], SIGNAL(toggled(bool)),
  31. this, SLOT(onSelectionChanged(bool)));
  32. }
  33. StartCompilerSetup::~StartCompilerSetup()
  34. {
  35. }
  36. void StartCompilerSetup::setGenerators(const QStringList& gens)
  37. {
  38. this->GeneratorOptions->clear();
  39. this->GeneratorOptions->addItems(gens);
  40. };
  41. void StartCompilerSetup::setCurrentGenerator(const QString& gen)
  42. {
  43. int idx = this->GeneratorOptions->findText(gen);
  44. if(idx != -1)
  45. {
  46. this->GeneratorOptions->setCurrentIndex(idx);
  47. }
  48. }
  49. QString StartCompilerSetup::getGenerator() const
  50. {
  51. return this->GeneratorOptions->currentText();
  52. };
  53. bool StartCompilerSetup::defaultSetup() const
  54. {
  55. return this->CompilerSetupOptions[0]->isChecked();
  56. }
  57. bool StartCompilerSetup::compilerSetup() const
  58. {
  59. return this->CompilerSetupOptions[1]->isChecked();
  60. }
  61. bool StartCompilerSetup::crossCompilerToolChainFile() const
  62. {
  63. return this->CompilerSetupOptions[2]->isChecked();
  64. }
  65. bool StartCompilerSetup::crossCompilerSetup() const
  66. {
  67. return this->CompilerSetupOptions[3]->isChecked();
  68. }
  69. void StartCompilerSetup::onSelectionChanged(bool on)
  70. {
  71. if(on)
  72. selectionChanged();
  73. }
  74. int StartCompilerSetup::nextId() const
  75. {
  76. if(compilerSetup())
  77. return NativeSetup;
  78. if(crossCompilerSetup())
  79. return CrossSetup;
  80. if(crossCompilerToolChainFile())
  81. return ToolchainSetup;
  82. return -1;
  83. }
  84. NativeCompilerSetup::NativeCompilerSetup(QWidget* p)
  85. : QWizardPage(p)
  86. {
  87. QVBoxLayout* l = new QVBoxLayout(this);
  88. QWidget* c = new QWidget(this);
  89. l->addWidget(c);
  90. this->setupUi(c);
  91. }
  92. NativeCompilerSetup::~NativeCompilerSetup()
  93. {
  94. }
  95. QString NativeCompilerSetup::getCCompiler() const
  96. {
  97. return this->CCompiler->text();
  98. }
  99. void NativeCompilerSetup::setCCompiler(const QString& s)
  100. {
  101. this->CCompiler->setText(s);
  102. }
  103. QString NativeCompilerSetup::getCXXCompiler() const
  104. {
  105. return this->CXXCompiler->text();
  106. }
  107. void NativeCompilerSetup::setCXXCompiler(const QString& s)
  108. {
  109. this->CXXCompiler->setText(s);
  110. }
  111. QString NativeCompilerSetup::getFortranCompiler() const
  112. {
  113. return this->FortranCompiler->text();
  114. }
  115. void NativeCompilerSetup::setFortranCompiler(const QString& s)
  116. {
  117. this->FortranCompiler->setText(s);
  118. }
  119. CrossCompilerSetup::CrossCompilerSetup(QWidget* p)
  120. : QWizardPage(p)
  121. {
  122. this->setupUi(this);
  123. QWidget::setTabOrder(systemName, systemVersion);
  124. QWidget::setTabOrder(systemVersion, systemProcessor);
  125. QWidget::setTabOrder(systemProcessor, CrossCompilers->CCompiler);
  126. QWidget::setTabOrder(CrossCompilers->CCompiler, CrossCompilers->CXXCompiler);
  127. QWidget::setTabOrder(CrossCompilers->CXXCompiler, CrossCompilers->FortranCompiler);
  128. QWidget::setTabOrder(CrossCompilers->FortranCompiler, crossFindRoot);
  129. QWidget::setTabOrder(crossFindRoot, crossProgramMode);
  130. QWidget::setTabOrder(crossProgramMode, crossLibraryMode);
  131. QWidget::setTabOrder(crossLibraryMode, crossIncludeMode);
  132. // fill in combo boxes
  133. QStringList modes;
  134. modes << tr("Search in Target Root, then native system");
  135. modes << tr("Search only in Target Root");
  136. modes << tr("Search only in native system");
  137. crossProgramMode->addItems(modes);
  138. crossLibraryMode->addItems(modes);
  139. crossIncludeMode->addItems(modes);
  140. crossProgramMode->setCurrentIndex(2);
  141. crossLibraryMode->setCurrentIndex(1);
  142. crossIncludeMode->setCurrentIndex(1);
  143. this->registerField("systemName*", this->systemName);
  144. }
  145. CrossCompilerSetup::~CrossCompilerSetup()
  146. {
  147. }
  148. QString CrossCompilerSetup::getCCompiler() const
  149. {
  150. return this->CrossCompilers->CCompiler->text();
  151. }
  152. void CrossCompilerSetup::setCCompiler(const QString& s)
  153. {
  154. this->CrossCompilers->CCompiler->setText(s);
  155. }
  156. QString CrossCompilerSetup::getCXXCompiler() const
  157. {
  158. return this->CrossCompilers->CXXCompiler->text();
  159. }
  160. void CrossCompilerSetup::setCXXCompiler(const QString& s)
  161. {
  162. this->CrossCompilers->CXXCompiler->setText(s);
  163. }
  164. QString CrossCompilerSetup::getFortranCompiler() const
  165. {
  166. return this->CrossCompilers->FortranCompiler->text();
  167. }
  168. void CrossCompilerSetup::setFortranCompiler(const QString& s)
  169. {
  170. this->CrossCompilers->FortranCompiler->setText(s);
  171. }
  172. QString CrossCompilerSetup::getSystem() const
  173. {
  174. return this->systemName->text();
  175. }
  176. void CrossCompilerSetup::setSystem(const QString& t)
  177. {
  178. this->systemName->setText(t);
  179. }
  180. QString CrossCompilerSetup::getVersion() const
  181. {
  182. return this->systemVersion->text();
  183. }
  184. void CrossCompilerSetup::setVersion(const QString& t)
  185. {
  186. this->systemVersion->setText(t);
  187. }
  188. QString CrossCompilerSetup::getProcessor() const
  189. {
  190. return this->systemProcessor->text();
  191. }
  192. void CrossCompilerSetup::setProcessor(const QString& t)
  193. {
  194. this->systemProcessor->setText(t);
  195. }
  196. QString CrossCompilerSetup::getFindRoot() const
  197. {
  198. return this->crossFindRoot->text();
  199. }
  200. void CrossCompilerSetup::setFindRoot(const QString& t)
  201. {
  202. return this->crossFindRoot->setText(t);
  203. }
  204. int CrossCompilerSetup::getProgramMode() const
  205. {
  206. return this->crossProgramMode->currentIndex();
  207. }
  208. int CrossCompilerSetup::getLibraryMode() const
  209. {
  210. return this->crossLibraryMode->currentIndex();
  211. }
  212. int CrossCompilerSetup::getIncludeMode() const
  213. {
  214. return this->crossIncludeMode->currentIndex();
  215. }
  216. void CrossCompilerSetup::setProgramMode(int m)
  217. {
  218. this->crossProgramMode->setCurrentIndex(m);
  219. }
  220. void CrossCompilerSetup::setLibraryMode(int m)
  221. {
  222. this->crossLibraryMode->setCurrentIndex(m);
  223. }
  224. void CrossCompilerSetup::setIncludeMode(int m)
  225. {
  226. this->crossIncludeMode->setCurrentIndex(m);
  227. }
  228. ToolchainCompilerSetup::ToolchainCompilerSetup(QWidget* p)
  229. : QWizardPage(p)
  230. {
  231. QVBoxLayout* l = new QVBoxLayout(this);
  232. l->addWidget(new QLabel(tr("Specify the Toolchain file")));
  233. this->ToolchainFile = new QCMakeFilePathEditor(this);
  234. l->addWidget(this->ToolchainFile);
  235. }
  236. ToolchainCompilerSetup::~ToolchainCompilerSetup()
  237. {
  238. }
  239. QString ToolchainCompilerSetup::toolchainFile() const
  240. {
  241. return this->ToolchainFile->text();
  242. }
  243. void ToolchainCompilerSetup::setToolchainFile(const QString& t)
  244. {
  245. this->ToolchainFile->setText(t);
  246. }
  247. FirstConfigure::FirstConfigure()
  248. {
  249. //this->setOption(QWizard::HaveFinishButtonOnEarlyPages, true);
  250. this->mStartCompilerSetupPage = new StartCompilerSetup(this);
  251. this->setPage(Start, this->mStartCompilerSetupPage);
  252. QObject::connect(this->mStartCompilerSetupPage, SIGNAL(selectionChanged()),
  253. this, SLOT(restart()));
  254. this->mNativeCompilerSetupPage = new NativeCompilerSetup(this);
  255. this->setPage(NativeSetup, this->mNativeCompilerSetupPage);
  256. this->mCrossCompilerSetupPage = new CrossCompilerSetup(this);
  257. this->setPage(CrossSetup, this->mCrossCompilerSetupPage);
  258. this->mToolchainCompilerSetupPage = new ToolchainCompilerSetup(this);
  259. this->setPage(ToolchainSetup, this->mToolchainCompilerSetupPage);
  260. }
  261. FirstConfigure::~FirstConfigure()
  262. {
  263. }
  264. void FirstConfigure::setGenerators(const QStringList& gens)
  265. {
  266. this->mStartCompilerSetupPage->setGenerators(gens);
  267. }
  268. QString FirstConfigure::getGenerator() const
  269. {
  270. return this->mStartCompilerSetupPage->getGenerator();
  271. }
  272. void FirstConfigure::loadFromSettings()
  273. {
  274. QSettings settings;
  275. // restore generator
  276. settings.beginGroup("Settings/StartPath");
  277. QString lastGen = settings.value("LastGenerator").toString();
  278. this->mStartCompilerSetupPage->setCurrentGenerator(lastGen);
  279. settings.endGroup();
  280. // restore compiler setup
  281. settings.beginGroup("Settings/Compiler");
  282. this->mNativeCompilerSetupPage->setCCompiler(settings.value("CCompiler").toString());
  283. this->mNativeCompilerSetupPage->setCXXCompiler(settings.value("CXXCompiler").toString());
  284. this->mNativeCompilerSetupPage->setFortranCompiler(settings.value("FortranCompiler").toString());
  285. settings.endGroup();
  286. // restore cross compiler setup
  287. settings.beginGroup("Settings/CrossCompiler");
  288. this->mCrossCompilerSetupPage->setCCompiler(settings.value("CCompiler").toString());
  289. this->mCrossCompilerSetupPage->setCXXCompiler(settings.value("CXXCompiler").toString());
  290. this->mCrossCompilerSetupPage->setFortranCompiler(settings.value("FortranCompiler").toString());
  291. this->mToolchainCompilerSetupPage->setToolchainFile(settings.value("ToolChainFile").toString());
  292. this->mCrossCompilerSetupPage->setSystem(settings.value("SystemName").toString());
  293. this->mCrossCompilerSetupPage->setVersion(settings.value("SystemVersion").toString());
  294. this->mCrossCompilerSetupPage->setProcessor(settings.value("SystemProcessor").toString());
  295. this->mCrossCompilerSetupPage->setFindRoot(settings.value("FindRoot").toString());
  296. this->mCrossCompilerSetupPage->setProgramMode(settings.value("ProgramMode", 0).toInt());
  297. this->mCrossCompilerSetupPage->setLibraryMode(settings.value("LibraryMode", 0).toInt());
  298. this->mCrossCompilerSetupPage->setIncludeMode(settings.value("IncludeMode", 0).toInt());
  299. settings.endGroup();
  300. }
  301. void FirstConfigure::saveToSettings()
  302. {
  303. QSettings settings;
  304. // save generator
  305. settings.beginGroup("Settings/StartPath");
  306. QString lastGen = this->mStartCompilerSetupPage->getGenerator();
  307. settings.setValue("LastGenerator", lastGen);
  308. settings.endGroup();
  309. // save compiler setup
  310. settings.beginGroup("Settings/Compiler");
  311. settings.setValue("CCompiler", this->mNativeCompilerSetupPage->getCCompiler());
  312. settings.setValue("CXXCompiler", this->mNativeCompilerSetupPage->getCXXCompiler());
  313. settings.setValue("FortranCompiler", this->mNativeCompilerSetupPage->getFortranCompiler());
  314. settings.endGroup();
  315. // save cross compiler setup
  316. settings.beginGroup("Settings/CrossCompiler");
  317. settings.setValue("CCompiler", this->mCrossCompilerSetupPage->getCCompiler());
  318. settings.setValue("CXXCompiler", this->mCrossCompilerSetupPage->getCXXCompiler());
  319. settings.setValue("FortranCompiler", this->mCrossCompilerSetupPage->getFortranCompiler());
  320. settings.setValue("ToolChainFile", this->getCrossCompilerToolChainFile());
  321. settings.setValue("SystemName", this->mCrossCompilerSetupPage->getSystem());
  322. settings.setValue("SystemVersion", this->mCrossCompilerSetupPage->getVersion());
  323. settings.setValue("SystemProcessor", this->mCrossCompilerSetupPage->getProcessor());
  324. settings.setValue("FindRoot", this->mCrossCompilerSetupPage->getFindRoot());
  325. settings.setValue("ProgramMode", this->mCrossCompilerSetupPage->getProgramMode());
  326. settings.setValue("LibraryMode", this->mCrossCompilerSetupPage->getLibraryMode());
  327. settings.setValue("IncludeMode", this->mCrossCompilerSetupPage->getIncludeMode());
  328. settings.endGroup();
  329. }
  330. bool FirstConfigure::defaultSetup() const
  331. {
  332. return this->mStartCompilerSetupPage->defaultSetup();
  333. }
  334. bool FirstConfigure::compilerSetup() const
  335. {
  336. return this->mStartCompilerSetupPage->compilerSetup();
  337. }
  338. bool FirstConfigure::crossCompilerSetup() const
  339. {
  340. return this->mStartCompilerSetupPage->crossCompilerSetup();
  341. }
  342. bool FirstConfigure::crossCompilerToolChainFile() const
  343. {
  344. return this->mStartCompilerSetupPage->crossCompilerToolChainFile();
  345. }
  346. QString FirstConfigure::getCrossCompilerToolChainFile() const
  347. {
  348. return this->mToolchainCompilerSetupPage->toolchainFile();
  349. }
  350. QString FirstConfigure::getSystemName() const
  351. {
  352. return this->mCrossCompilerSetupPage->getSystem();
  353. }
  354. QString FirstConfigure::getCCompiler() const
  355. {
  356. if(this->compilerSetup())
  357. {
  358. return this->mNativeCompilerSetupPage->getCCompiler();
  359. }
  360. else if(this->crossCompilerSetup())
  361. {
  362. return this->mCrossCompilerSetupPage->getCCompiler();
  363. }
  364. return QString();
  365. }
  366. QString FirstConfigure::getCXXCompiler() const
  367. {
  368. if(this->compilerSetup())
  369. {
  370. return this->mNativeCompilerSetupPage->getCXXCompiler();
  371. }
  372. else if(this->crossCompilerSetup())
  373. {
  374. return this->mCrossCompilerSetupPage->getCXXCompiler();
  375. }
  376. return QString();
  377. }
  378. QString FirstConfigure::getFortranCompiler() const
  379. {
  380. if(this->compilerSetup())
  381. {
  382. return this->mNativeCompilerSetupPage->getFortranCompiler();
  383. }
  384. else if(this->crossCompilerSetup())
  385. {
  386. return this->mCrossCompilerSetupPage->getFortranCompiler();
  387. }
  388. return QString();
  389. }
  390. QString FirstConfigure::getSystemVersion() const
  391. {
  392. return this->mCrossCompilerSetupPage->getVersion();
  393. }
  394. QString FirstConfigure::getSystemProcessor() const
  395. {
  396. return this->mCrossCompilerSetupPage->getProcessor();
  397. }
  398. QString FirstConfigure::getCrossRoot() const
  399. {
  400. return this->mCrossCompilerSetupPage->getFindRoot();
  401. }
  402. const QString CrossModes[] =
  403. {
  404. "BOTH",
  405. "ONLY",
  406. "NEVER"
  407. };
  408. QString FirstConfigure::getCrossProgramMode() const
  409. {
  410. return CrossModes[this->mCrossCompilerSetupPage->getProgramMode()];
  411. }
  412. QString FirstConfigure::getCrossLibraryMode() const
  413. {
  414. return CrossModes[this->mCrossCompilerSetupPage->getLibraryMode()];
  415. }
  416. QString FirstConfigure::getCrossIncludeMode() const
  417. {
  418. return CrossModes[this->mCrossCompilerSetupPage->getIncludeMode()];
  419. }