get rid of most clazy warnings (https://github.com/KDE/clazy) * range loop use refs * qcolor ctor with ints * missing Q_OBJECT macro * use .constfirst instead of .first enabled ccache for unix systems for fasterr recompiling * if ccache is in path we use it now
215 lines
7.3 KiB
C++
215 lines
7.3 KiB
C++
#include "qt/window/project_wizzard/QtProjectWizzardContentSelect.h"
|
|
|
|
#include <QButtonGroup>
|
|
#include <QMessageBox>
|
|
#include <QLabel>
|
|
#include <QPushButton>
|
|
|
|
#include "qt/window/project_wizzard/QtProjectWizzardWindow.h"
|
|
#include "settings/LanguageType.h"
|
|
#include "utility/ResourcePaths.h"
|
|
#include "utility/utilityString.h"
|
|
|
|
QtProjectWizzardContentSelect::QtProjectWizzardContentSelect(
|
|
QtProjectWizzardWindow* window
|
|
)
|
|
: QtProjectWizzardContent(window)
|
|
{
|
|
}
|
|
|
|
void QtProjectWizzardContentSelect::populate(QGridLayout* layout, int& row)
|
|
{
|
|
struct SourceGroupInfo
|
|
{
|
|
SourceGroupInfo(SourceGroupType type) :type(type) {}
|
|
const SourceGroupType type;
|
|
};
|
|
|
|
// define which kind of source groups are available for each language
|
|
std::map<LanguageType, std::vector<SourceGroupInfo>> sourceGroupInfos;
|
|
sourceGroupInfos[LANGUAGE_C].push_back(SourceGroupInfo(SOURCE_GROUP_C_EMPTY));
|
|
sourceGroupInfos[LANGUAGE_C].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_CDB));
|
|
sourceGroupInfos[LANGUAGE_C].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_VS));
|
|
sourceGroupInfos[LANGUAGE_CPP].push_back(SourceGroupInfo(SOURCE_GROUP_CPP_EMPTY));
|
|
sourceGroupInfos[LANGUAGE_CPP].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_CDB));
|
|
sourceGroupInfos[LANGUAGE_CPP].push_back(SourceGroupInfo(SOURCE_GROUP_CXX_VS));
|
|
sourceGroupInfos[LANGUAGE_JAVA].push_back(SourceGroupInfo(SOURCE_GROUP_JAVA_EMPTY));
|
|
sourceGroupInfos[LANGUAGE_JAVA].push_back(SourceGroupInfo(SOURCE_GROUP_JAVA_MAVEN));
|
|
|
|
// define which icons should be used for which kind of source group
|
|
m_sourceGroupTypeIconName[SOURCE_GROUP_C_EMPTY] = "empty_icon";
|
|
m_sourceGroupTypeIconName[SOURCE_GROUP_CPP_EMPTY] = "empty_icon";
|
|
m_sourceGroupTypeIconName[SOURCE_GROUP_CXX_CDB] = "cdb_icon";
|
|
m_sourceGroupTypeIconName[SOURCE_GROUP_CXX_VS] = "vs_icon";
|
|
m_sourceGroupTypeIconName[SOURCE_GROUP_JAVA_EMPTY] = "empty_icon";
|
|
m_sourceGroupTypeIconName[SOURCE_GROUP_JAVA_MAVEN] = "mvn_icon";
|
|
|
|
// define descriptions for each kind of Source Group
|
|
m_sourceGroupTypeDescriptions[SOURCE_GROUP_C_EMPTY] = "Create a new Sourcetrail Source Group by defining which C files will be indexed.";
|
|
m_sourceGroupTypeDescriptions[SOURCE_GROUP_CPP_EMPTY] = "Create a new Sourcetrail Source Group by defining which C++ files will be indexed.";
|
|
m_sourceGroupTypeDescriptions[SOURCE_GROUP_CXX_CDB] = "Create a Source Group from an existing Compilation Database (compile_commands.json). They can be created from Make and "
|
|
"CMake projects. Have a look at the <a href=\"https://sourcetrail.com/documentation/#CreateAProjectFromCompilationDatabase\">"
|
|
"documentation</a> to find out more.";
|
|
m_sourceGroupTypeDescriptions[SOURCE_GROUP_CXX_VS] = "Create a new Source Group from an existing Visual Studio Solution file. "
|
|
"<b>Note: Requires a running Visual Studio instance with the "
|
|
"<a href=\"https://sourcetrail.com/documentation/index.html#VisualStudio\">Visual Studio plugin</a> installed.";
|
|
m_sourceGroupTypeDescriptions[SOURCE_GROUP_JAVA_EMPTY] = "Create a new Sourcetrail Source Group by defining which Java files will be indexed.";
|
|
m_sourceGroupTypeDescriptions[SOURCE_GROUP_JAVA_MAVEN] = "Create a new Source Group from an existing Maven project.";
|
|
|
|
QVBoxLayout* vlayout = new QVBoxLayout();
|
|
vlayout->setContentsMargins(0, 30, 0, 0);
|
|
vlayout->setSpacing(10);
|
|
|
|
m_languages = new QButtonGroup();
|
|
for (auto& it: sourceGroupInfos)
|
|
{
|
|
QPushButton* b = new QPushButton(languageTypeToString(it.first).c_str(), this);
|
|
b->setObjectName("menuButton");
|
|
b->setCheckable(true);
|
|
b->setProperty("language_type", it.first);
|
|
m_languages->addButton(b);
|
|
vlayout->addWidget(b);
|
|
}
|
|
|
|
vlayout->addStretch();
|
|
layout->addLayout(vlayout, 0, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight);
|
|
|
|
connect(m_languages, static_cast<void(QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked),
|
|
[this](QAbstractButton* button)
|
|
{
|
|
LanguageType selectedLanguage = LANGUAGE_UNKNOWN;
|
|
bool ok = false;
|
|
int languageTypeInt = button->property("language_type").toInt(&ok);
|
|
if (ok)
|
|
{
|
|
selectedLanguage = LanguageType(languageTypeInt);
|
|
}
|
|
|
|
for (auto& it: m_buttons)
|
|
{
|
|
it.second->setExclusive(false);
|
|
for (QAbstractButton* button : it.second->buttons())
|
|
{
|
|
button->setChecked(false);
|
|
button->setVisible(it.first == selectedLanguage);
|
|
}
|
|
it.second->setExclusive(true);
|
|
}
|
|
|
|
m_window->setNextEnabled(false);
|
|
m_title->setText("Source Group Types - " + m_languages->checkedButton()->text());
|
|
m_description->setText("");
|
|
}
|
|
);
|
|
|
|
QHBoxLayout* hlayout = new QHBoxLayout();
|
|
|
|
for (auto& languageIt: sourceGroupInfos)
|
|
{
|
|
QButtonGroup* sourceGroupButtons = new QButtonGroup(this);
|
|
|
|
for (auto& sourceGroupIt: languageIt.second)
|
|
{
|
|
QToolButton* b = createSourceGroupButton(
|
|
utility::insertLineBreaksAtBlankSpaces(sourceGroupTypeToProjectSetupString(sourceGroupIt.type), 15).c_str(),
|
|
(ResourcePaths::getGuiPath().str() + "icon/" + m_sourceGroupTypeIconName[sourceGroupIt.type] + ".png").c_str()
|
|
);
|
|
b->setProperty("source_group_type", int(sourceGroupIt.type));
|
|
sourceGroupButtons->addButton(b);
|
|
hlayout->addWidget(b);
|
|
}
|
|
|
|
m_buttons[languageIt.first] = sourceGroupButtons;
|
|
}
|
|
|
|
for (auto& it: m_buttons)
|
|
{
|
|
connect(it.second, static_cast<void(QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked),
|
|
[this](QAbstractButton* button)
|
|
{
|
|
SourceGroupType selectedType = SOURCE_GROUP_UNKNOWN;
|
|
bool ok = false;
|
|
int selectedTypeInt = button->property("source_group_type").toInt(&ok);
|
|
if (ok)
|
|
{
|
|
selectedType = SourceGroupType(selectedTypeInt);
|
|
}
|
|
|
|
m_description->setText(m_sourceGroupTypeDescriptions[selectedType].c_str());
|
|
|
|
m_window->setNextEnabled(true);
|
|
}
|
|
);
|
|
}
|
|
|
|
QFrame* container = new QFrame();
|
|
container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
container->setObjectName("sourceGroupContainer");
|
|
container->setLayout(hlayout);
|
|
|
|
layout->addWidget(container, 0, QtProjectWizzardWindow::BACK_COL);
|
|
|
|
m_description = new QLabel(" \n \n");
|
|
m_description->setWordWrap(true);
|
|
m_description->setOpenExternalLinks(true);
|
|
m_description->setObjectName("sourceGroupDescription");
|
|
layout->addWidget(m_description, 1, QtProjectWizzardWindow::BACK_COL);
|
|
|
|
m_title = new QLabel("Source Group Types");
|
|
m_title->setObjectName("sourceGroupTitle");
|
|
|
|
layout->addWidget(m_title, 0, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
layout->setRowStretch(0, 0);
|
|
layout->setRowStretch(1, 1);
|
|
layout->setColumnStretch(QtProjectWizzardWindow::FRONT_COL, 0);
|
|
layout->setColumnStretch(QtProjectWizzardWindow::BACK_COL, 1);
|
|
layout->setHorizontalSpacing(0);
|
|
|
|
m_languages->buttons().constFirst()->click();
|
|
}
|
|
|
|
void QtProjectWizzardContentSelect::save()
|
|
{
|
|
SourceGroupType selectedType;
|
|
|
|
for (auto& it: m_buttons)
|
|
{
|
|
if (QAbstractButton* b = it.second->checkedButton())
|
|
{
|
|
bool ok = false;
|
|
int selectedTypeInt = b->property("source_group_type").toInt(&ok);
|
|
if (ok)
|
|
{
|
|
selectedType = SourceGroupType(selectedTypeInt);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
emit selected(selectedType);
|
|
}
|
|
|
|
bool QtProjectWizzardContentSelect::check()
|
|
{
|
|
bool sourceGroupChosen = false;
|
|
|
|
for (auto& it: m_buttons)
|
|
{
|
|
if (it.second->checkedId() != -1)
|
|
{
|
|
sourceGroupChosen = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!sourceGroupChosen)
|
|
{
|
|
QMessageBox msgBox;
|
|
msgBox.setText("Please choose a method of creating a new Source Group.");
|
|
msgBox.exec();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|