ui: Fixes in Source Group UI (issue #723) (#915)

* fixed Source Group setup from Visual Studio Extension
* fixed crashes in project setup due to use of std::shared_ptr
* fixed source file count not updated on 'show files' click
* fixed passing wheel events to parents when list boxes can't handle them
This commit is contained in:
Eberhard Gräther
2020-02-10 23:45:31 +01:00
committed by GitHub
parent 9c40d26002
commit 9fc0a05c3b
17 changed files with 124 additions and 116 deletions
-1
View File
@@ -645,7 +645,6 @@ if (BUILD_CXX_LANGUAGE_PACKAGE)
settings/source_group/type/SourceGroupSettingsCppEmpty.h
settings/source_group/type/SourceGroupSettingsCustomCommand.h
settings/source_group/type/SourceGroupSettingsCxxCdb.h
settings/source_group/type/SourceGroupSettingsCxxCdbVs.h
settings/source_group/type/SourceGroupSettingsCxxCodeblocks.h
)
endif()
@@ -1,11 +0,0 @@
#ifndef SOURCE_GROUP_SETTINGS_CXX_CDB_VS_H
#define SOURCE_GROUP_SETTINGS_CXX_CDB_VS_H
#include "SourceGroupSettingsCxxCdb.h"
class SourceGroupSettingsCxxCdbVs: public SourceGroupSettingsCxxCdb
{
using SourceGroupSettingsCxxCdb::SourceGroupSettingsCxxCdb;
};
#endif // SOURCE_GROUP_SETTINGS_CXX_CDB_VS_H
+23 -23
View File
@@ -11,6 +11,29 @@
#include "utilityQt.h"
#include "utilityString.h"
void QtListWidget::mouseDoubleClickEvent(QMouseEvent* event)
{
QModelIndex index;
emit doubleClicked(index);
}
void QtListWidget::wheelEvent(QWheelEvent* event)
{
QScrollBar* bar = verticalScrollBar();
bool down = event->angleDelta().y() < 0;
if (bar->minimum() == bar->maximum() ||
(down && bar->value() == bar->maximum()) ||
(!down && bar->value() == bar->minimum()))
{
event->ignore();
}
else
{
QListWidget::wheelEvent(event);
}
}
QtListBox::QtListBox(QWidget* parent, const QString& listName): QFrame(parent), m_listName(listName)
{
QBoxLayout* layout = new QVBoxLayout();
@@ -87,29 +110,6 @@ void QtListBox::addWidgetToBar(QWidget* widget)
}
}
bool QtListBox::event(QEvent* event)
{
// Prevent nested ScrollAreas from scrolling at the same time;
if (event->type() == QEvent::Wheel)
{
QRect rect = m_list->viewport()->rect();
QPoint pos = m_list->mapFromGlobal(dynamic_cast<QWheelEvent*>(event)->globalPos());
QScrollBar* bar = m_list->verticalScrollBar();
if (bar->minimum() != bar->maximum() && rect.contains(pos))
{
bool down = dynamic_cast<QWheelEvent*>(event)->angleDelta().y() < 0;
if ((down && bar->value() != bar->maximum()) || (!down && bar->value() != bar->minimum()))
{
return true;
}
}
}
return QFrame::event(event);
}
QtListBoxItem* QtListBox::addListBoxItemWithText(const QString& text)
{
QtListBoxItem* item = addListBoxItem();
+2 -7
View File
@@ -6,7 +6,6 @@
#include "FilePath.h"
class QEvent;
class QHBoxLayout;
class QListWidgetItem;
class QPushButton;
@@ -22,11 +21,8 @@ public:
QtListWidget(QWidget* parent = nullptr): QListWidget(parent) {}
protected:
void mouseDoubleClickEvent(QMouseEvent* event) override
{
QModelIndex index;
emit doubleClicked(index);
}
void mouseDoubleClickEvent(QMouseEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
};
class QtListBox: public QFrame
@@ -45,7 +41,6 @@ public:
protected:
void addWidgetToBar(QWidget* widget);
bool event(QEvent* event) override;
QtListWidget* m_list;
@@ -52,7 +52,6 @@
# include "SourceGroupSettingsCEmpty.h"
# include "SourceGroupSettingsCppEmpty.h"
# include "SourceGroupSettingsCxxCdb.h"
# include "SourceGroupSettingsCxxCdbVs.h"
# include "SourceGroupSettingsCxxCodeblocks.h"
#endif // BUILD_CXX_LANGUAGE_PACKAGE
@@ -237,32 +236,6 @@ void addSourceGroupContents<SourceGroupSettingsCxxCodeblocks>(
group->addContent(new QtProjectWizardContentFlags(settings, window, true));
}
template <>
void addSourceGroupContents<SourceGroupSettingsCxxCdbVs>(
QtProjectWizardContentGroup* group, std::shared_ptr<SourceGroupSettingsCxxCdbVs> settings, QtProjectWizardWindow* window)
{
group->addContent(new QtProjectWizardContentVS(window)); // TODO make separate window
group->addSpace();
group->addContent(new QtProjectWizardContentPathCDB(settings, window));
group->addContent(new QtProjectWizardContentPathsIndexedHeaders(settings, window, "Compilation Database"));
group->addContent(new QtProjectWizardContentPathsExclude(settings, window));
group->addSpace();
group->addContent(new QtProjectWizardContentPathsHeaderSearch(settings, window, true));
group->addContent(new QtProjectWizardContentPathsHeaderSearchGlobal(window));
group->addSpace();
if (utility::getOsType() == OS_MAC)
{
group->addContent(new QtProjectWizardContentPathsFrameworkSearch(settings, window, true));
group->addContent(new QtProjectWizardContentPathsFrameworkSearchGlobal(window));
group->addSpace();
}
group->addContent(new QtProjectWizardContentFlags(settings, window, true));
}
#endif // BUILD_CXX_LANGUAGE_PACKAGE
#if BUILD_JAVA_LANGUAGE_PACKAGE
@@ -391,8 +364,8 @@ void QtProjectWizard::newProjectFromCDB(const FilePath& filePath)
cancelSourceGroup();
std::shared_ptr<SourceGroupSettingsCxxCdbVs> sourceGroupSettings =
std::make_shared<SourceGroupSettingsCxxCdbVs>(
std::shared_ptr<SourceGroupSettingsCxxCdb> sourceGroupSettings =
std::make_shared<SourceGroupSettingsCxxCdb>(
utility::getUuidString(), m_projectSettings.get());
sourceGroupSettings->setCompilationDatabasePath(filePath);
@@ -718,12 +691,6 @@ void QtProjectWizard::selectedSourceGroupChanged(int index)
{
addSourceGroupContents(summary, settings, this);
}
else if (
std::shared_ptr<SourceGroupSettingsCxxCdbVs> settings =
std::dynamic_pointer_cast<SourceGroupSettingsCxxCdbVs>(group))
{
addSourceGroupContents(summary, settings, this);
}
#endif // BUILD_CXX_LANGUAGE_PACKAGE
#if BUILD_JAVA_LANGUAGE_PACKAGE
else if (
@@ -928,6 +895,28 @@ void QtProjectWizard::newSourceGroup()
window->updateSubTitle(QStringLiteral("Type Selection"));
}
void QtProjectWizard::newSourceGroupFromVS()
{
#if BUILD_CXX_LANGUAGE_PACKAGE
QtProjectWizardWindow* window = createWindowWithContent([](QtProjectWizardWindow* window) {
window->setPreferredSize(QSize(560, 320));
return new QtProjectWizardContentVS(window);
});
window->resize(QSize(560, 320));
connect(window, &QtProjectWizardWindow::next,
[this](){
selectedProjectType(SOURCE_GROUP_CXX_CDB);
}
);
window->show();
window->setNextEnabled(true);
window->setPreviousEnabled(true);
window->updateSubTitle(QStringLiteral("C/C++ from Visual Studio"));
#endif // BUILD_CXX_LANGUAGE_PACKAGE
}
void QtProjectWizard::selectedProjectType(SourceGroupType sourceGroupType)
{
const std::string sourceGroupId = utility::getUuidString();
@@ -964,8 +953,8 @@ void QtProjectWizard::selectedProjectType(SourceGroupType sourceGroupType)
}
break;
case SOURCE_GROUP_CXX_VS:
settings = std::make_shared<SourceGroupSettingsCxxCdbVs>(sourceGroupId, m_projectSettings.get());
break;
newSourceGroupFromVS();
return;
#endif // BUILD_CXX_LANGUAGE_PACKAGE
#if BUILD_JAVA_LANGUAGE_PACKAGE
@@ -1010,7 +999,7 @@ void QtProjectWizard::createSourceGroup(std::shared_ptr<SourceGroupSettings> set
m_previouslySelectedIndex = -1;
m_sourceGroupList->setCurrentRow(m_allSourceGroupSettings.size() - 1);
m_sourceGroupList->setCurrentRow(int(m_allSourceGroupSettings.size()) - 1);
}
void QtProjectWizard::createProject()
@@ -75,6 +75,7 @@ private slots:
void windowStackChanged();
void newSourceGroup();
void newSourceGroupFromVS();
void selectedProjectType(SourceGroupType sourceGroupType);
void createSourceGroup(std::shared_ptr<SourceGroupSettings> settings);
@@ -47,6 +47,11 @@ void QtProjectWizardWindow::loadContent()
m_content->load();
}
void QtProjectWizardWindow::refreshContent()
{
m_content->refresh();
}
void QtProjectWizardWindow::populateWindow(QWidget* widget)
{
QGridLayout* layout = new QGridLayout();
@@ -20,6 +20,7 @@ public:
void saveContent();
void loadContent();
void refreshContent();
static const int FRONT_COL = 0;
static const int HELP_COL = 1;
@@ -22,6 +22,8 @@ void QtProjectWizardContent::load() {}
void QtProjectWizardContent::save() {}
void QtProjectWizardContent::refresh() {}
bool QtProjectWizardContent::check()
{
return true;
@@ -131,6 +133,7 @@ QFrame* QtProjectWizardContent::addSeparator(QGridLayout* layout, int row) const
void QtProjectWizardContent::filesButtonClicked()
{
m_window->saveContent();
m_window->refreshContent();
std::thread([&]() {
const std::vector<FilePath> filePaths = getFilePaths();
@@ -142,8 +145,8 @@ void QtProjectWizardContent::showFilesDialog(const std::vector<FilePath>& filePa
{
if (!m_filesDialog)
{
m_filesDialog = std::make_shared<QtTextEditDialog>(
getFileNamesTitle(), QString::number(filePaths.size()) + " " + getFileNamesDescription());
m_filesDialog = new QtTextEditDialog(
getFileNamesTitle(), QString::number(filePaths.size()) + " " + getFileNamesDescription(), m_window);
m_filesDialog->setup();
m_filesDialog->setText(utility::join(utility::toWStrings(filePaths), L"\n"));
@@ -151,12 +154,12 @@ void QtProjectWizardContent::showFilesDialog(const std::vector<FilePath>& filePa
m_filesDialog->setReadOnly(true);
connect(
m_filesDialog.get(),
m_filesDialog,
&QtTextEditDialog::finished,
this,
&QtProjectWizardContent::closedFilesDialog);
connect(
m_filesDialog.get(),
m_filesDialog,
&QtTextEditDialog::canceled,
this,
&QtProjectWizardContent::closedFilesDialog);
@@ -169,7 +172,8 @@ void QtProjectWizardContent::showFilesDialog(const std::vector<FilePath>& filePa
void QtProjectWizardContent::closedFilesDialog()
{
m_filesDialog->hide();
m_filesDialog.reset();
m_filesDialog->deleteLater();
m_filesDialog = nullptr;
window()->raise();
}
@@ -25,6 +25,7 @@ public:
virtual void load();
virtual void save();
virtual void refresh();
virtual bool check();
virtual std::vector<FilePath> getFilePaths() const;
@@ -47,7 +48,7 @@ protected:
QtProjectWizardWindow* m_window;
std::shared_ptr<QtTextEditDialog> m_filesDialog;
QtTextEditDialog* m_filesDialog = nullptr;
protected slots:
void filesButtonClicked();
@@ -70,6 +70,17 @@ void QtProjectWizardContentGroup::save()
}
}
void QtProjectWizardContentGroup::refresh()
{
for (QtProjectWizardContent* content: m_contents)
{
if (content)
{
content->refresh();
}
}
}
bool QtProjectWizardContentGroup::check()
{
for (QtProjectWizardContent* content: m_contents)
@@ -23,6 +23,7 @@ protected:
virtual void load() override;
virtual void save() override;
virtual void refresh() override;
virtual bool check() override;
private:
@@ -9,21 +9,26 @@ QtProjectWizardContentVS::QtProjectWizardContentVS(QtProjectWizardWindow* window
void QtProjectWizardContentVS::populate(QGridLayout* layout, int& row)
{
layout->setRowMinimumHeight(row++, 10);
QLabel* nameLabel = createFormLabel("Create Compilation Database");
layout->addWidget(nameLabel, row, QtProjectWizardWindow::FRONT_COL);
addHelpButton(
"Create Compilation Database",
"To create a new Compilation Database from a Visual Studio Solution, this Solution has to be open in Visual Studio.\n\
Sourcetrail will call Visual Studio to open the 'Create Compilation Database' dialog.\
Please follow the instructions in Visual Studio to complete the process.\n\
Note: Sourcetrail's Visual Studio plugin has to be installed. Visual Studio has to be running with an eligible Solution, containing C/C++ projects, loaded.",
"To create a new Compilation Database from a Visual Studio Solution, a Solution has to be open in Visual "
"Studio.\n Sourcetrail will call Visual Studio to open the 'Create Compilation Database' dialog. Please follow "
"the instructions in Visual Studio to complete the process.\n Note: Sourcetrail's Visual Studio plugin has to "
"be installed. Visual Studio has to be running with an eligible Solution, containing C/C++ projects, loaded.",
layout,
row);
QLabel* descriptionLabel = createFormSubLabel(
"Call Visual Studio to create a Compilation Database from the loaded Solution.");
"Call Visual Studio to create a Compilation Database from the loaded Solution (requires installed "
"<a href=\"https://sourcetrail.com/documentation/index.html#VisualStudio\">Sourcetrail Visual Studio "
"Extension</a>).");
descriptionLabel->setObjectName("description");
descriptionLabel->setOpenExternalLinks(true);
descriptionLabel->setAlignment(Qt::AlignmentFlag::AlignLeft);
layout->addWidget(descriptionLabel, row, QtProjectWizardWindow::BACK_COL);
row++;
@@ -40,7 +45,8 @@ Note: Sourcetrail's Visual Studio plugin has to be installed. Visual Studio has
layout->addWidget(skipLabel, row, QtProjectWizardWindow::BACK_COL);
row++;
addSeparator(layout, row++);
layout->setRowMinimumHeight(row, 10);
layout->setRowStretch(row, 1);
connect(button, &QPushButton::clicked, this, &QtProjectWizardContentVS::handleVSCDBClicked);
}
@@ -68,6 +68,16 @@ void QtProjectWizardContentPathCDB::load()
{
m_picker->setText(QString::fromStdWString(m_settings->getCompilationDatabasePath().wstr()));
refresh();
}
void QtProjectWizardContentPathCDB::save()
{
m_settings->setCompilationDatabasePath(FilePath(m_picker->getText().toStdWString()));
}
void QtProjectWizardContentPathCDB::refresh()
{
m_filePaths.clear();
if (m_fileCountLabel)
@@ -78,11 +88,6 @@ void QtProjectWizardContentPathCDB::load()
}
}
void QtProjectWizardContentPathCDB::save()
{
m_settings->setCompilationDatabasePath(FilePath(m_picker->getText().toStdWString()));
}
std::vector<FilePath> QtProjectWizardContentPathCDB::getFilePaths() const
{
return m_filePaths.getValue();
@@ -19,6 +19,7 @@ public:
void load() override;
void save() override;
void refresh() override;
std::vector<FilePath> getFilePaths() const override;
QString getFileNamesTitle() const override;
@@ -357,12 +357,12 @@ void QtProjectWizardContentPathsHeaderSearch::showDetectedIncludesResult(
detailedText += path.wstr() + L"\n";
}
m_filesDialog = std::make_shared<QtTextEditDialog>(
m_filesDialog = new QtTextEditDialog(
"Detected Include Paths",
("<p>The following <b>" + std::to_string(additionalHeaderSearchPaths.size()) +
"</b> include paths have been "
"detected and will be added to the include paths of this Source Group.<b>")
.c_str());
.c_str(), m_window);
m_filesDialog->setup();
m_filesDialog->setReadOnly(true);
@@ -373,12 +373,12 @@ void QtProjectWizardContentPathsHeaderSearch::showDetectedIncludesResult(
m_filesDialog->showWindow();
connect(
m_filesDialog.get(),
m_filesDialog,
&QtTextEditDialog::finished,
this,
&QtProjectWizardContentPathsHeaderSearch::finishedAcceptDetectedIncludePathsDialog);
connect(
m_filesDialog.get(),
m_filesDialog,
&QtTextEditDialog::canceled,
this,
&QtProjectWizardContentPathsHeaderSearch::closedFilesDialog);
@@ -417,7 +417,7 @@ void QtProjectWizardContentPathsHeaderSearch::showValidationResult(
detailedText += L"\n";
}
m_filesDialog = std::make_shared<QtTextEditDialog>(
m_filesDialog = new QtTextEditDialog(
"Unresolved Include Directives",
("<p>The indexed files contain <b>" + std::to_string(unresolvedIncludes.size()) +
"</b> include directive" + (unresolvedIncludes.size() == 1 ? "" : "s") +
@@ -427,7 +427,7 @@ void QtProjectWizardContentPathsHeaderSearch::showValidationResult(
"conditional preprocessor "
"directives. This means that some of the unresolved includes may actually not be "
"required by the indexer.</p>")
.c_str());
.c_str(), m_window);
m_filesDialog->setup();
m_filesDialog->setCloseVisible(false);
@@ -437,12 +437,12 @@ void QtProjectWizardContentPathsHeaderSearch::showValidationResult(
m_filesDialog->showWindow();
connect(
m_filesDialog.get(),
m_filesDialog,
&QtTextEditDialog::finished,
this,
&QtProjectWizardContentPathsHeaderSearch::closedFilesDialog);
connect(
m_filesDialog.get(),
m_filesDialog,
&QtTextEditDialog::canceled,
this,
&QtProjectWizardContentPathsHeaderSearch::closedFilesDialog);
@@ -203,27 +203,27 @@ void QtProjectWizardContentPathsIndexedHeaders::buttonClicked()
return;
}
m_filesDialog = std::make_shared<QtSelectPathsDialog>(
m_filesDialog = new QtSelectPathsDialog(
"Select from Include Paths",
"The list contains all Include Paths found in the Code::Blocks project. Red paths "
"do not exist. Select the "
"paths containing the header files you want to index with Sourcetrail.");
"paths containing the header files you want to index with Sourcetrail.", m_window);
m_filesDialog->setup();
connect(
m_filesDialog.get(),
m_filesDialog,
&QtSelectPathsDialog::finished,
this,
&QtProjectWizardContentPathsIndexedHeaders::savedFilesDialog);
connect(
m_filesDialog.get(),
m_filesDialog,
&QtSelectPathsDialog::canceled,
this,
&QtProjectWizardContentPathsIndexedHeaders::closedFilesDialog);
const FilePath projectPath = codeblocksSettings->getProjectDirectoryPath();
dynamic_cast<QtSelectPathsDialog*>(m_filesDialog.get())
dynamic_cast<QtSelectPathsDialog*>(m_filesDialog)
->setPathsList(
utility::convert<FilePath, FilePath>(
getIndexedPathsDerivedFromCodeblocksProject(codeblocksSettings),
@@ -247,27 +247,27 @@ void QtProjectWizardContentPathsIndexedHeaders::buttonClicked()
return;
}
m_filesDialog = std::make_shared<QtSelectPathsDialog>(
m_filesDialog = new QtSelectPathsDialog(
"Select from Include Paths",
"The list contains all Include Paths found in the Compilation Database. Red paths "
"do not exist. Select the "
"paths containing the header files you want to index with Sourcetrail.");
"paths containing the header files you want to index with Sourcetrail.", m_window);
m_filesDialog->setup();
connect(
m_filesDialog.get(),
m_filesDialog,
&QtSelectPathsDialog::finished,
this,
&QtProjectWizardContentPathsIndexedHeaders::savedFilesDialog);
connect(
m_filesDialog.get(),
m_filesDialog,
&QtSelectPathsDialog::canceled,
this,
&QtProjectWizardContentPathsIndexedHeaders::closedFilesDialog);
const FilePath projectPath = cdbSettings->getProjectDirectoryPath();
dynamic_cast<QtSelectPathsDialog*>(m_filesDialog.get())
dynamic_cast<QtSelectPathsDialog*>(m_filesDialog)
->setPathsList(
utility::convert<FilePath, FilePath>(
getIndexedPathsDerivedFromCDB(cdbSettings),
@@ -288,6 +288,6 @@ void QtProjectWizardContentPathsIndexedHeaders::buttonClicked()
void QtProjectWizardContentPathsIndexedHeaders::savedFilesDialog()
{
m_list->setPaths(dynamic_cast<QtSelectPathsDialog*>(m_filesDialog.get())->getPathsList());
m_list->setPaths(dynamic_cast<QtSelectPathsDialog*>(m_filesDialog)->getPathsList());
closedFilesDialog();
}