ui: prefill headers from compilation database

dialog for selecting header paths from compilation database
This commit is contained in:
Andreas Stallinger
2016-08-31 14:37:28 +02:00
parent d2de395ed5
commit 251eab6e9e
19 changed files with 337 additions and 27 deletions
+2
View File
@@ -149,6 +149,8 @@ add_files(
qt/window/QtLicense.h
qt/window/QtMainWindow.cpp
qt/window/QtMainWindow.h
qt/window/QtSelectPathsDialog.cpp
qt/window/QtSelectPathsDialog.h
qt/window/QtSplashScreen.cpp
qt/window/QtSplashScreen.h
qt/window/QtStartScreen.cpp
@@ -0,0 +1,83 @@
#include "qt/window/QtSelectPathsDialog.h"
#include <QLabel>
#include <QListWidget>
QtSelectPathsDialog::QtSelectPathsDialog(const QString& title, const QString& description, QWidget* parent)
: QtTextEditDialog(title, description, parent)
{
}
std::vector<FilePath> QtSelectPathsDialog::getPathsList() const
{
std::vector<FilePath> checkedPaths;
for (int i = 0; i < m_list->count(); i++)
{
if (m_list->item(i)->checkState() == Qt::Checked)
{
checkedPaths.push_back(m_list->item(i)->text().toStdString());
}
}
return checkedPaths;
}
void QtSelectPathsDialog::setPathsList(const std::vector<FilePath>& paths, const std::vector<FilePath>& checkedPaths)
{
for (FilePath s : paths)
{
QListWidgetItem* item = new QListWidgetItem(s.str().c_str(), m_list);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag
if (std::find(checkedPaths.begin(), checkedPaths.end(), s) == checkedPaths.end())
{
item->setCheckState(Qt::Unchecked); // AND initialize check state
}
else
{
item->setCheckState(Qt::Checked);
}
if (!s.exists())
{
item->setTextColor(Qt::red);
item->setToolTip("Path does not exist");
item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
}
else
{
item->setTextColor(Qt::black);
}
}
}
void QtSelectPathsDialog::populateWindow(QWidget* widget)
{
QVBoxLayout* layout = new QVBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
QLabel* description = new QLabel(m_description);
description->setObjectName("description");
description->setWordWrap(true);
layout->addWidget(description);
m_list = new QListWidget();
m_list->setObjectName("pathList");
m_list->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_list->setSelectionMode(QAbstractItemView::NoSelection);
m_list->setAttribute(Qt::WA_MacShowFocusRect, 0);
layout->addWidget(m_list);
widget->setLayout(layout);
}
void QtSelectPathsDialog::windowReady()
{
updateNextButton("Save");
updateCloseButton("Cancel");
setPreviousVisible(false);
updateTitle(m_title);
}
@@ -0,0 +1,25 @@
#ifndef QT_SELECT_PATHS_DIALOG_H
#define QT_SELECT_PATHS_DIALOG_H
#include "qt/window/QtTextEditDialog.h"
#include "utility/file/FilePath.h"
class QListWidget;
class QtSelectPathsDialog
: public QtTextEditDialog
{
public:
QtSelectPathsDialog(const QString& title, const QString& description, QWidget* parent = 0);
std::vector<FilePath> getPathsList() const;
void setPathsList(const std::vector<FilePath>& paths, const std::vector<FilePath>& checkedPaths);
virtual void populateWindow(QWidget* widget) override;
virtual void windowReady() override;
private:
QListWidget* m_list;
};
#endif // QT_SELECT_PATHS_DIALOG_H
+2 -1
View File
@@ -24,10 +24,11 @@ protected:
void populateWindow(QWidget* widget) override;
void windowReady() override;
private:
QString m_title;
QString m_description;
private:
QPlainTextEdit* m_text;
};
@@ -505,9 +505,7 @@ void QtProjectWizzard::showSummary()
else
{
summary->addContent(new QtProjectWizzardContentDataCDB(m_settings, window), false, false);
QtProjectWizzardContent* headers = new QtProjectWizzardContentPathsCDBHeader(m_settings, window);
summary->addContent(headers, false, true);
summary->addContent(new QtProjectWizzardContentPathsCDBHeader(m_settings, window), false, true);
summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(m_settings, window, true), false, true);
summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(m_settings, window), false, false);
@@ -63,13 +63,13 @@ protected:
std::shared_ptr<ProjectSettings> m_settings;
QtProjectWizzardWindow* m_window;
private slots:
std::shared_ptr<QtTextEditDialog> m_filesDialog;
protected slots:
void filesButtonClicked();
void closedFilesDialog();
private:
std::shared_ptr<QtTextEditDialog> m_filesDialog;
bool m_isInForm;
};
@@ -3,11 +3,14 @@
#include <QLabel>
#include <QMessageBox>
#include <QVBoxLayout>
#include <QComboBox>
#include "qt/element/QtDirectoryListBox.h"
#include "qt/window/QtSelectPathsDialog.h"
#include "settings/ApplicationSettings.h"
#include "settings/CxxProjectSettings.h"
#include "settings/JavaProjectSettings.h"
#include "utility/CompilationDatabase.h"
#include "utility/file/FileManager.h"
#include "utility/file/FileSystem.h"
#include "utility/path_detector/cxx_header/CxxFrameworkPathDetector.h"
@@ -235,6 +238,56 @@ QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader(
);
}
void QtProjectWizzardContentPathsCDBHeader::populate( QGridLayout* layout, int& row)
{
QtProjectWizzardContentPaths::populate(layout, row);
QPushButton* button = new QPushButton("Select from Include Paths");
button->setObjectName("windowButton");
connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
layout->addWidget(button, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignRight | Qt::AlignTop);
row++;
}
void QtProjectWizzardContentPathsCDBHeader::buttonClicked()
{
save();
if (!m_filesDialog)
{
std::vector<std::string> fileNames = getFileNames();
m_filesDialog = std::make_shared<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 Coati.");
m_filesDialog->setup();
utility::CompilationDatabase cdb(dynamic_cast<CxxProjectSettings*>(m_settings.get())->getCompilationDatabasePath().str());
std::vector<FilePath> cdbHeaderPaths = cdb.getAllHeaderPaths();
std::vector<FilePath> sourcePaths = m_settings->getSourcePaths();
cdbHeaderPaths = utility::unique(utility::concat(sourcePaths, cdbHeaderPaths));
dynamic_cast<QtSelectPathsDialog*>(m_filesDialog.get())->setPathsList(cdbHeaderPaths, sourcePaths);
connect(m_filesDialog.get(), SIGNAL(finished()), this, SLOT(savedFilesDialog()));
connect(m_filesDialog.get(), SIGNAL(canceled()), this, SLOT(closedFilesDialog()));
}
m_filesDialog->showWindow();
m_filesDialog->raise();
}
void QtProjectWizzardContentPathsCDBHeader::savedFilesDialog()
{
// TODO: extend instead of replace
m_list->setList(dynamic_cast<QtSelectPathsDialog*>(m_filesDialog.get())->getPathsList());
closedFilesDialog();
}
QtProjectWizzardContentPathsExclude::QtProjectWizzardContentPathsExclude(
std::shared_ptr<ProjectSettings> settings, QtProjectWizzardWindow* window
@@ -1,13 +1,12 @@
#ifndef QT_PROJECT_WIZZARD_CONTENT_PATHS_H
#define QT_PROJECT_WIZZARD_CONTENT_PATHS_H
#include <QComboBox>
#include <QPushButton>
#include "qt/window/project_wizzard/QtProjectWizzardContent.h"
#include "utility/path_detector/CombinedPathDetector.h"
class QtDirectoryListBox;
class QPushButton;
class QComboBox;
class QtProjectWizzardContentPaths
: public QtProjectWizzardContent
@@ -72,8 +71,16 @@ public:
class QtProjectWizzardContentPathsCDBHeader
: public QtProjectWizzardContentPathsSource
{
Q_OBJECT
public:
QtProjectWizzardContentPathsCDBHeader(std::shared_ptr<ProjectSettings> settings, QtProjectWizzardWindow* window);
virtual void populate(QGridLayout* layout, int& row) override;
private slots:
void buttonClicked();
void savedFilesDialog();
};