iqtprojectgenerator.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include <QDir>
  2. #include <QDebug>
  3. #include <QVBoxLayout>
  4. #include <QGroupBox>
  5. #include <QComboBox>
  6. #include <QGridLayout>
  7. #include <QLabel>
  8. #include "iqtprojectgenerator.h"
  9. IQtProjectGenerator::IQtProjectGenerator(QObject * parent)
  10. : QObject(parent), m_selectionDone(false)
  11. {
  12. // Read available plugin information
  13. QDir pluginDirectory(QDir::currentPath() + PLUGINS_DIR);
  14. foreach (QString plugin, pluginDirectory.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
  15. {
  16. QFile pluginXml(pluginDirectory.canonicalPath() + "/" + plugin + "/" + plugin + ".xml");
  17. if (pluginXml.exists() && pluginXml.open(QFile::ReadOnly))
  18. {
  19. HybridPluginXmlHandler handler(&pluginXml);
  20. QSharedPointer<HybridPlugin> plugin = handler.parse();
  21. m_plugins.append(plugin);
  22. qDebug() << "Found plugin:" << m_plugins.last()->name();
  23. }
  24. }
  25. }
  26. IQtProjectGenerator::~IQtProjectGenerator()
  27. {
  28. ;
  29. }
  30. void IQtProjectGenerator::confirmPluginPlatform()
  31. {
  32. foreach (QSharedPointer<HybridPlugin> plugin, m_plugins)
  33. {
  34. plugin->conformingVersion(platform());
  35. }
  36. m_selectionDone = true;
  37. }
  38. const QList< QSharedPointer<HybridPlugin> >& IQtProjectGenerator::plugins()
  39. {
  40. if (!m_selectionDone)
  41. confirmPluginPlatform();
  42. return m_plugins;
  43. }
  44. QWidget * IQtProjectGenerator::createSettingsPluginsWidget(QWidget * parent)
  45. {
  46. qDebug() << "Create plugins widget";
  47. QWidget *widget = new QWidget(parent);
  48. QVBoxLayout *layout = new QVBoxLayout();
  49. layout->setContentsMargins(0, 0, 0, 0);
  50. QGroupBox *group = new QGroupBox(widget);
  51. group->setTitle("Plugin Settings");
  52. layout->addWidget(group);
  53. QGridLayout *grid = new QGridLayout(widget);
  54. group->setLayout(grid);
  55. int rows = 0; // Counter for rows in the grid layout
  56. int item = 1; // Counter for platforms
  57. foreach (QSharedPointer<HybridPlugin> plugin, plugins())
  58. {
  59. QLabel *label = new QLabel(widget);
  60. label->setText("Plugin \"" + plugin->name() + "\"");
  61. grid->addWidget(label, rows, 0);
  62. QComboBox *combo = new QComboBox(widget);
  63. // An empty selection, identify by plugin name and zero index
  64. combo->addItem("Do not include any version in the project", plugin->name() + "_0");
  65. foreach (QSharedPointer<HybridPluginPlatform> platform, plugin->platforms())
  66. {
  67. QString format = platform->format() == HybridPluginPlatform::Source ? "Source" : "Library";
  68. QString config = platform->configuration() == HybridPluginPlatform::Release ? "Release" : "Debug";
  69. QString identification = plugin->name() + "_" + QString::number(item); // Identification for lookup
  70. m_selection.insert(identification, platform); // Add the item to map to enable selection lookup
  71. combo->addItem(format + ": " +
  72. platform->name() + " " +
  73. QString::number(platform->version()) +
  74. " (Qt " + QString::number(platform->qtVersion()) + ", " + config + ")",
  75. identification);
  76. if (platform == plugin->selectedPlatform())
  77. {
  78. // Set the current item active
  79. combo->setCurrentIndex(combo->count() - 1);
  80. }
  81. item++;
  82. }
  83. grid->addWidget(combo, rows, 1);
  84. rows++;
  85. }
  86. QLabel *note = new QLabel(widget);
  87. note->setText("Note: A compatible version is selected by default. Using a non-compatible version may cause the project not to compile. These settings are not persisted across sessions.");
  88. note->setWordWrap(true);
  89. grid->addWidget(note, rows, 1);
  90. grid->setColumnStretch(1, 1);
  91. layout->addStretch(1);
  92. widget->setLayout(layout);
  93. return widget;
  94. }
  95. void IQtProjectGenerator::savePluginSettings(QWidget *settingsWidget)
  96. {
  97. // Check that the plugin widget is prepared, and extract the current selection
  98. // from it. The layout *must* be exactly as in the widget creation function above,
  99. // or we are going to have problems.
  100. if (settingsWidget)
  101. {
  102. QGridLayout *grid = qobject_cast<QGridLayout *>(settingsWidget->layout()->itemAt(0)->widget()->layout());
  103. if (grid)
  104. {
  105. for (int row = 0; row < grid->rowCount(); row++)
  106. {
  107. QComboBox *combo = qobject_cast<QComboBox *>(grid->itemAtPosition(row, 1)->widget());
  108. if (combo)
  109. {
  110. QRegExp rx("^(.+)_([0-9]+)$");
  111. QString identification = combo->itemData(combo->currentIndex()).toString();
  112. if (rx.indexIn(identification) != -1)
  113. {
  114. QString pluginName = rx.cap(1);
  115. qDebug() << "Checking settings for" << pluginName;
  116. bool ok;
  117. int index = rx.cap(2).toInt(&ok);
  118. if (ok && index > 0)
  119. {
  120. QSharedPointer<HybridPluginPlatform> platform = m_selection.value(identification);
  121. platform->plugin().selectPlatform(platform);
  122. qDebug() << "Selected platform" << platform->name() << platform->version();
  123. }
  124. else
  125. {
  126. // Clear selection. First we have to find the plugin by its name
  127. qDebug() << "Clearing platform selection for plugin" << pluginName;
  128. foreach (QSharedPointer<HybridPlugin> plugin, m_plugins)
  129. {
  130. if (plugin->name() == pluginName)
  131. {
  132. plugin->selectPlatform(QSharedPointer<HybridPluginPlatform>(0));
  133. qDebug() << "Cleared platform selection";
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
  142. // Plugin selection is done here at the latest
  143. m_selectionDone = true;
  144. }