diff --git a/src/lib/component/controller/ErrorController.cpp b/src/lib/component/controller/ErrorController.cpp index 311ddfec..c70c47fe 100644 --- a/src/lib/component/controller/ErrorController.cpp +++ b/src/lib/component/controller/ErrorController.cpp @@ -4,6 +4,7 @@ #include "ApplicationSettings.h" #include "DialogView.h" #include "Project.h" +#include "QtHelpButtonInfo.h" #include "StorageAccess.h" #include "TabId.h" @@ -140,7 +141,7 @@ void ErrorController::handleMessage(MessageErrorsHelpMessage* message) appSettings->setSeenErrorHelpMessage(true); appSettings->save(); - getView()->showErrorHelpMessage(); + m_onQtThread([=]() { createErrorHelpButtonInfo().displayMessage(); }); } void ErrorController::handleMessage(MessageIndexingFinished* message) diff --git a/src/lib/component/controller/ErrorController.h b/src/lib/component/controller/ErrorController.h index 1cc29fa7..34b86d8f 100644 --- a/src/lib/component/controller/ErrorController.h +++ b/src/lib/component/controller/ErrorController.h @@ -11,6 +11,7 @@ #include "MessageIndexingStarted.h" #include "MessageListener.h" #include "MessageShowError.h" +#include "QtThreadedFunctor.h" #include "Controller.h" #include "ErrorView.h" @@ -62,6 +63,7 @@ private: std::map m_tabShowsErrors; std::map m_tabActiveFilePath; + QtThreadedLambdaFunctor m_onQtThread; bool m_newErrorsAdded = false; }; diff --git a/src/lib/component/view/ErrorView.h b/src/lib/component/view/ErrorView.h index 4d8ec31a..e95dc508 100644 --- a/src/lib/component/view/ErrorView.h +++ b/src/lib/component/view/ErrorView.h @@ -22,8 +22,6 @@ public: const std::vector& errors, const ErrorCountInfo& errorCount, bool scrollTo) = 0; virtual void setErrorId(Id errorId) = 0; - virtual void showErrorHelpMessage() = 0; - virtual ErrorFilter getErrorFilter() const = 0; virtual void setErrorFilter(const ErrorFilter& filter) = 0; }; diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index 0cabfae2..d19388af 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -192,6 +192,8 @@ add_files( qt/utility/QtFilesAndDirectoriesDialog.h qt/utility/QtFlowLayout.cpp qt/utility/QtFlowLayout.h + qt/utility/QtHelpButtonInfo.cpp + qt/utility/QtHelpButtonInfo.h qt/utility/QtHighlighter.cpp qt/utility/QtHighlighter.h qt/utility/QtScrollSpeedChangeListener.cpp diff --git a/src/lib_gui/qt/element/button/QtHelpButton.cpp b/src/lib_gui/qt/element/button/QtHelpButton.cpp index d239610b..d7304540 100644 --- a/src/lib_gui/qt/element/button/QtHelpButton.cpp +++ b/src/lib_gui/qt/element/button/QtHelpButton.cpp @@ -1,16 +1,13 @@ #include "QtHelpButton.h" -#include - #include "ResourcePaths.h" -QtHelpButton::QtHelpButton(const QString& helpTitle, const QString& helpText, QWidget* parent) +QtHelpButton::QtHelpButton(const QtHelpButtonInfo& info, QWidget* parent) : QtIconButton( ResourcePaths::getGuiPath().concatenate(L"window/help.png"), ResourcePaths::getGuiPath().concatenate(L"window/help_hover.png"), parent) - , m_helpTitle(helpTitle) - , m_helpText(helpText) + , m_info(info) { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac @@ -27,12 +24,5 @@ QtHelpButton::QtHelpButton(const QString& helpTitle, const QString& helpText, QW void QtHelpButton::handleHelpPress() { - QMessageBox msgBox; - msgBox.setWindowTitle(QStringLiteral("Sourcetrail")); - msgBox.setIcon(QMessageBox::Information); - msgBox.setText("" + m_helpTitle + ""); - msgBox.setInformativeText(m_helpText); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); + m_info.displayMessage(); } diff --git a/src/lib_gui/qt/element/button/QtHelpButton.h b/src/lib_gui/qt/element/button/QtHelpButton.h index 3b321986..2d81af2d 100644 --- a/src/lib_gui/qt/element/button/QtHelpButton.h +++ b/src/lib_gui/qt/element/button/QtHelpButton.h @@ -1,6 +1,7 @@ #ifndef QT_HELP_BUTTON_H #define QT_HELP_BUTTON_H +#include "QtHelpButtonInfo.h" #include "QtIconButton.h" class QtHelpButton: public QtIconButton @@ -8,14 +9,13 @@ class QtHelpButton: public QtIconButton Q_OBJECT public: - QtHelpButton(const QString& helpTitle, const QString& helpText, QWidget* parent = nullptr); + QtHelpButton(const QtHelpButtonInfo& info, QWidget* parent = nullptr); private slots: void handleHelpPress(); private: - QString m_helpTitle; - QString m_helpText; + QtHelpButtonInfo m_info; }; #endif // QT_HELP_BUTTON_H diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContent.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContent.cpp index 9d082f81..ea7e7311 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContent.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContent.cpp @@ -90,7 +90,7 @@ QToolButton* QtProjectWizardContent::createSourceGroupButton(QString name, QStri QtHelpButton* QtProjectWizardContent::addHelpButton( const QString& helpTitle, const QString& helpText, QGridLayout* layout, int row) const { - QtHelpButton* button = new QtHelpButton(helpTitle, helpText); + QtHelpButton* button = new QtHelpButton(QtHelpButtonInfo(helpTitle, helpText)); layout->addWidget(button, row, QtProjectWizardWindow::HELP_COL, Qt::AlignTop); return button; } diff --git a/src/lib_gui/qt/utility/QtHelpButtonInfo.cpp b/src/lib_gui/qt/utility/QtHelpButtonInfo.cpp new file mode 100644 index 00000000..d582ec44 --- /dev/null +++ b/src/lib_gui/qt/utility/QtHelpButtonInfo.cpp @@ -0,0 +1,58 @@ +#include "QtHelpButtonInfo.h" + +#include + +QtHelpButtonInfo::QtHelpButtonInfo(const QString& title, const QString& text) + : m_title(title), m_text(text) +{ +} + +void QtHelpButtonInfo::displayMessage() +{ + QMessageBox msgBox; + msgBox.setWindowTitle(QStringLiteral("Sourcetrail")); + msgBox.setIcon(QMessageBox::Information); + msgBox.setText("" + m_title + ""); + msgBox.setInformativeText(m_text); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.exec(); +} + +QtHelpButtonInfo createErrorHelpButtonInfo() +{ + return QtHelpButtonInfo( + QStringLiteral("Fixing Errors"), + QStringLiteral( + "Please read this if your project is showing errors after indexing.
" + "There are different types of errors:" + "
    " + "
  • Fatals cause the indexer to stop. All or big parts of indexed " + "information " + "for the involved " + "source file is missing. Make sure to fix all fatals.
  • " + "
  • Errors are issues that the indexer considers as wrong code. Usually " + "the " + "indexer is able to " + "recover from these errors. The indexed information of the involved source file " + "may " + "not be complete, but " + "it is still useful.
  • " + "
" + "You need to edit your Sourcetrail project and reindex it to fix errors. The " + "displayed " + "error messages are " + "generated by Sourcetrail's language specific indexers:" + "
    " + "
  • C/C++ error messages are generated by the clang compiler " + "frontend.
  • " + "
  • Java error messages are generated by the Eclipse JDT " + "library.
  • " + "
  • Python error messages are generated by the Jedi static analysis " + "library.
  • " + "
" + "You should be able to find information about errors you are not familiar with " + "online. " + "Double click " + "an error message in the table to select it for copying.
")); +} diff --git a/src/lib_gui/qt/utility/QtHelpButtonInfo.h b/src/lib_gui/qt/utility/QtHelpButtonInfo.h new file mode 100644 index 00000000..e81426b2 --- /dev/null +++ b/src/lib_gui/qt/utility/QtHelpButtonInfo.h @@ -0,0 +1,20 @@ +#ifndef QT_HELP_BUTTON_INFO_H +#define QT_HELP_BUTTON_INFO_H + +#include + +class QtHelpButtonInfo +{ +public: + QtHelpButtonInfo(const QString& helpTitle, const QString& helpText); + + void displayMessage(); + +private: + QString m_title; + QString m_text; +}; + +QtHelpButtonInfo createErrorHelpButtonInfo(); + +#endif // QT_HELP_BUTTON_INFO_H diff --git a/src/lib_gui/qt/view/QtErrorView.cpp b/src/lib_gui/qt/view/QtErrorView.cpp index 94578961..cdd26f02 100644 --- a/src/lib_gui/qt/view/QtErrorView.cpp +++ b/src/lib_gui/qt/view/QtErrorView.cpp @@ -57,12 +57,8 @@ QtErrorView::QtErrorView(ViewLayout* viewLayout) m_table->setColumnHidden(Column::ID, true); QStringList headers; - headers << QStringLiteral("ID") - << QStringLiteral("Type") - << QStringLiteral("Message") - << QStringLiteral("File") - << QStringLiteral("Line") - << QStringLiteral("Indexed") + headers << QStringLiteral("ID") << QStringLiteral("Type") << QStringLiteral("Message") + << QStringLiteral("File") << QStringLiteral("Line") << QStringLiteral("Indexed") << QStringLiteral("Translation Unit"); m_model->setHorizontalHeaderLabels(headers); @@ -88,40 +84,16 @@ QtErrorView::QtErrorView(ViewLayout* viewLayout) checkboxes->setSpacing(0); { - m_showFatals = createFilterCheckbox(QStringLiteral("Fatals"), m_errorFilter.fatal, checkboxes); - m_showErrors = createFilterCheckbox(QStringLiteral("Errors"), m_errorFilter.error, checkboxes); + m_showFatals = createFilterCheckbox( + QStringLiteral("Fatals"), m_errorFilter.fatal, checkboxes); + m_showErrors = createFilterCheckbox( + QStringLiteral("Errors"), m_errorFilter.error, checkboxes); m_showNonIndexedFatals = createFilterCheckbox( QStringLiteral("Fatals in non-indexed files"), m_errorFilter.unindexedFatal, checkboxes); m_showNonIndexedErrors = createFilterCheckbox( QStringLiteral("Errors in non-indexed files"), m_errorFilter.unindexedError, checkboxes); - m_helpButton = new QtHelpButton( - QStringLiteral("Fixing Errors"), - QStringLiteral("Please read this if your project is showing errors after indexing.
" - "There are different types of errors:" - "
    " - "
  • Fatals cause the indexer to stop. All or big parts of indexed information " - "for the involved " - "source file is missing. Make sure to fix all fatals.
  • " - "
  • Errors are issues that the indexer considers as wrong code. Usually the " - "indexer is able to " - "recover from these errors. The indexed information of the involved source file may " - "not be complete, but " - "it is still useful.
  • " - "
" - "You need to edit your Sourcetrail project and reindex it to fix errors. The displayed " - "error messages are " - "generated by Sourcetrail's language specific indexers:" - "
    " - "
  • C/C++ error messages are generated by the clang compiler " - "frontend.
  • " - "
  • Java error messages are generated by the Eclipse JDT library.
  • " - "
  • Python error messages are generated by the Jedi static analysis " - "library.
  • " - "
" - "You should be able to find information about errors you are not familiar with online. " - "Double click " - "an error message in the table to select it for copying.
")); + m_helpButton = new QtHelpButton(createErrorHelpButtonInfo()); m_helpButton->setObjectName(QStringLiteral("help_button")); checkboxes->addWidget(m_helpButton); } @@ -222,7 +194,8 @@ void QtErrorView::addErrors( m_errorLabel->setText( "displaying " + QString::number(errorCount.total) + " error" + (errorCount.total != 1 ? "s" : "") + - (errorCount.fatal > 0 ? " (" + QString::number(errorCount.fatal) + " fatal)" : QLatin1String("")) + + (errorCount.fatal > 0 ? " (" + QString::number(errorCount.fatal) + " fatal)" + : QLatin1String("")) + ""); }); } @@ -240,11 +213,6 @@ void QtErrorView::setErrorId(Id errorId) }); } -void QtErrorView::showErrorHelpMessage() -{ - m_onQtThread([=]() { m_helpButton->click(); }); -} - ErrorFilter QtErrorView::getErrorFilter() const { return m_errorFilter; @@ -328,8 +296,10 @@ void QtErrorView::addErrorToTable(const ErrorInfo& error) item->setData(QVariant(qlonglong(error.id)), Qt::DisplayRole); m_model->setItem(rowNumber, Column::ID, item); - m_model->setItem(rowNumber, Column::TYPE, new QStandardItem(error.fatal ? - QStringLiteral("FATAL") : QStringLiteral("ERROR"))); + m_model->setItem( + rowNumber, + Column::TYPE, + new QStandardItem(error.fatal ? QStringLiteral("FATAL") : QStringLiteral("ERROR"))); if (error.fatal) { m_model->item(rowNumber, Column::TYPE)->setForeground(QBrush(Qt::red)); @@ -347,8 +317,10 @@ void QtErrorView::addErrorToTable(const ErrorInfo& error) item->setData(QVariant(qlonglong(error.lineNumber)), Qt::DisplayRole); m_model->setItem(rowNumber, Column::LINE, item); - m_model->setItem(rowNumber, Column::INDEXED, new QStandardItem(error.indexed ? - QStringLiteral("yes") : QStringLiteral("no"))); + m_model->setItem( + rowNumber, + Column::INDEXED, + new QStandardItem(error.indexed ? QStringLiteral("yes") : QStringLiteral("no"))); m_model->setItem( rowNumber, diff --git a/src/lib_gui/qt/view/QtErrorView.h b/src/lib_gui/qt/view/QtErrorView.h index 065ac902..88dcb806 100644 --- a/src/lib_gui/qt/view/QtErrorView.h +++ b/src/lib_gui/qt/view/QtErrorView.h @@ -39,8 +39,6 @@ public: const std::vector& errors, const ErrorCountInfo& errorCount, bool scrollTo) override; void setErrorId(Id errorId) override; - void showErrorHelpMessage() override; - ErrorFilter getErrorFilter() const override; void setErrorFilter(const ErrorFilter& filter) override; diff --git a/src/lib_gui/qt/window/QtIndexingDialog.cpp b/src/lib_gui/qt/window/QtIndexingDialog.cpp index 1ab79f9c..448e75fe 100644 --- a/src/lib_gui/qt/window/QtIndexingDialog.cpp +++ b/src/lib_gui/qt/window/QtIndexingDialog.cpp @@ -9,7 +9,7 @@ #include "ResourcePaths.h" #include "utilityQt.h" -QLabel* QtIndexingDialog::createTitleLabel(const QString &title, QBoxLayout* layout) +QLabel* QtIndexingDialog::createTitleLabel(const QString& title, QBoxLayout* layout) { QLabel* label = new QLabel(title); label->setObjectName(QStringLiteral("title")); @@ -48,12 +48,8 @@ QWidget* QtIndexingDialog::createErrorWidget(QBoxLayout* layout) ResourcePaths::getGuiPath().concatenate(L"indexing_dialog/error.png").wstr()))); errorLayout->addWidget(errorCount); - QtHelpButton* helpButton = new QtHelpButton(QStringLiteral("aaa"), QStringLiteral("bbb")); + QtHelpButton* helpButton = new QtHelpButton(QtHelpButtonInfo(createErrorHelpButtonInfo())); helpButton->setColor(Qt::white); - - helpButton->disconnect(); - connect(helpButton, &QtHelpButton::clicked, []() { MessageErrorsHelpMessage(true).dispatch(); }); - errorLayout->addWidget(helpButton); layout->addWidget(errorWidget, 0, Qt::AlignRight); @@ -83,9 +79,9 @@ QtIndexingDialog::QtIndexingDialog(bool isSubWindow, QWidget* parent) m_window->setStyleSheet( m_window->styleSheet() + QStringLiteral("#window { " - "background: #2E3C86;" - "border: none;" - "}")); + "background: #2E3C86;" + "border: none;" + "}")); setStyleSheet( (utility::getStyleSheet(ResourcePaths::getGuiPath().concatenate(L"window/window.css")) + diff --git a/src/lib_gui/qt/window/QtIndexingStartDialog.cpp b/src/lib_gui/qt/window/QtIndexingStartDialog.cpp index 56fc5ddf..e1723681 100644 --- a/src/lib_gui/qt/window/QtIndexingStartDialog.cpp +++ b/src/lib_gui/qt/window/QtIndexingStartDialog.cpp @@ -41,7 +41,7 @@ QtIndexingStartDialog::QtIndexingStartDialog( modeLabel->setText(QStringLiteral("Mode:")); modeLabel->setAlignment(Qt::AlignLeft); - QtHelpButton* helpButton = new QtHelpButton( + QtHelpButton* helpButton = new QtHelpButton(QtHelpButtonInfo( QStringLiteral("Indexing Modes"), QString("Updated files: Reindexes all files that were modified since the last " "indexing, all new files and all files depending " @@ -58,7 +58,7 @@ QtIndexingStartDialog::QtIndexingStartDialog( "Hint: Use this option for a quick first indexing pass and start browsing " "the code base " "while running a second pass for in-depth indexing.

" - : "")); + : ""))); helpButton->setColor(Qt::white); modeTitleLayout->addWidget(helpButton); @@ -67,9 +67,11 @@ QtIndexingStartDialog::QtIndexingStartDialog( modeLayout->addLayout(modeTitleLayout); modeLayout->addSpacing(5); - m_refreshModeButtons.emplace(REFRESH_UPDATED_FILES, new QRadioButton(QStringLiteral("Updated files"))); m_refreshModeButtons.emplace( - REFRESH_UPDATED_AND_INCOMPLETE_FILES, new QRadioButton(QStringLiteral("Incomplete && updated files"))); + REFRESH_UPDATED_FILES, new QRadioButton(QStringLiteral("Updated files"))); + m_refreshModeButtons.emplace( + REFRESH_UPDATED_AND_INCOMPLETE_FILES, + new QRadioButton(QStringLiteral("Incomplete && updated files"))); m_refreshModeButtons.emplace(REFRESH_ALL_FILES, new QRadioButton(QStringLiteral("All files"))); std::function func = [=](bool checked) { @@ -108,7 +110,8 @@ QtIndexingStartDialog::QtIndexingStartDialog( if (enabledShallowOption) { - QCheckBox* shallowIndexingCheckBox = new QCheckBox(QStringLiteral("Shallow Python Indexing")); + QCheckBox* shallowIndexingCheckBox = new QCheckBox( + QStringLiteral("Shallow Python Indexing")); connect(shallowIndexingCheckBox, &QCheckBox::toggled, [=]() { emit setShallowIndexing(shallowIndexingCheckBox->isChecked()); });