src: use wstring for showing text in QtTextEditDialog

This commit is contained in:
mlangkabel
2018-02-06 15:17:10 +01:00
parent adb9542c31
commit 5423d0b053
16 changed files with 107 additions and 85 deletions
@@ -385,17 +385,17 @@ void QtDirectoryListBox::showEditDialog()
m_editDialog = std::make_shared<QtTextEditDialog>(m_listName, "Edit the list in plain text. Each line is one item.");
m_editDialog->setup();
std::vector<std::string> list;
std::vector<std::wstring> list;
for (int i = 0; i < m_list->count(); ++i)
{
QtListItemWidget* widget = dynamic_cast<QtListItemWidget*>(m_list->itemWidget(m_list->item(i)));
if (!widget->readOnly())
{
list.push_back(widget->getText().toStdString());
list.push_back(widget->getText().toStdWString());
}
}
m_editDialog->setText(utility::join(list, "\n"));
m_editDialog->setText(utility::join(list, L"\n"));
connect(m_editDialog.get(), &QtTextEditDialog::canceled, this, &QtDirectoryListBox::canceledEditDialog);
connect(m_editDialog.get(), &QtTextEditDialog::finished, this, &QtDirectoryListBox::savedEditDialog);
@@ -425,12 +425,12 @@ void QtDirectoryListBox::savedEditDialog()
}
}
std::vector<std::string> lines = utility::splitToVector(m_editDialog->getText(), "\n");
std::vector<std::wstring> lines = utility::splitToVector(m_editDialog->getText(), L"\n");
for (size_t i = 0; i < lines.size(); i++)
{
lines[i] = utility::trim(lines[i]);
if (!lines[i].size())
if (lines[i].empty())
{
lines.erase(lines.begin() + i);
i--;
@@ -448,9 +448,9 @@ void QtDirectoryListBox::savedEditDialog()
itemWidget->setReadOnly(true);
}
for (const std::string& str : lines)
for (const std::wstring& line : lines)
{
QtListItemWidget* itemWidget = addListBoxItemWithText(QString::fromStdString(str));
QtListItemWidget* itemWidget = addListBoxItemWithText(QString::fromStdWString(line));
itemWidget->setReadOnly(false);
}
+2 -12
View File
@@ -15,22 +15,12 @@ QSize QtTextEditDialog::sizeHint() const
return QSize(550, 550);
}
void QtTextEditDialog::setText(const std::string& text)
{
m_text->setPlainText(QString::fromStdString(text));
}
std::string QtTextEditDialog::getText()
{
return m_text->toPlainText().toStdString();
}
void QtTextEditDialog::setWText(const std::wstring& text)
void QtTextEditDialog::setText(const std::wstring& text)
{
m_text->setPlainText(QString::fromStdWString(text));
}
std::wstring QtTextEditDialog::getWText()
std::wstring QtTextEditDialog::getText()
{
return m_text->toPlainText().toStdWString();
}
+2 -5
View File
@@ -15,11 +15,8 @@ public:
QSize sizeHint() const override;
void setText(const std::string& text);
std::string getText();
void setWText(const std::wstring& text);
std::wstring getWText();
void setText(const std::wstring& text);
std::wstring getText();
void setReadOnly(bool readOnly);
@@ -3,6 +3,7 @@
#include <thread>
#include "qt/window/QtTextEditDialog.h"
#include "utility/utility.h"
#include "utility/utilityString.h"
QtProjectWizzardContent::QtProjectWizzardContent(QtProjectWizzardWindow* window)
@@ -39,9 +40,9 @@ bool QtProjectWizzardContent::isScrollAble() const
return false;
}
std::vector<std::string> QtProjectWizzardContent::getFileNames() const
std::vector<FilePath> QtProjectWizzardContent::getFilePaths() const
{
return std::vector<std::string>();
return {};
}
QString QtProjectWizzardContent::getFileNamesTitle() const
@@ -132,20 +133,20 @@ void QtProjectWizzardContent::filesButtonClicked()
m_window->saveContent();
std::thread([&](){
std::vector<std::string> fileNames = getFileNames();
m_showFilesFunctor(fileNames);
const std::vector<FilePath> filePaths = getFilePaths();
m_showFilesFunctor(filePaths);
}).detach();
}
void QtProjectWizzardContent::showFilesDialog(const std::vector<std::string>& fileNames)
void QtProjectWizzardContent::showFilesDialog(const std::vector<FilePath>& filePaths)
{
if (!m_filesDialog)
{
m_filesDialog = std::make_shared<QtTextEditDialog>(
getFileNamesTitle(), QString::number(fileNames.size()) + " " + getFileNamesDescription());
getFileNamesTitle(), QString::number(filePaths.size()) + " " + getFileNamesDescription());
m_filesDialog->setup();
m_filesDialog->setText(utility::join(fileNames, "\n"));
m_filesDialog->setText(utility::join(utility::toWStrings(filePaths), L"\n"));
m_filesDialog->setCloseVisible(false);
m_filesDialog->setReadOnly(true);
@@ -9,6 +9,7 @@
#include "qt/element/QtHelpButton.h"
#include "qt/utility/QtThreadedFunctor.h"
#include "qt/window/project_wizzard/QtProjectWizzardWindow.h"
#include "utility/file/FilePath.h"
class QtTextEditDialog;
@@ -29,7 +30,7 @@ public:
virtual bool isScrollAble() const;
virtual std::vector<std::string> getFileNames() const;
virtual std::vector<FilePath> getFilePaths() const;
virtual QString getFileNamesTitle() const;
virtual QString getFileNamesDescription() const;
@@ -54,10 +55,10 @@ protected slots:
void closedFilesDialog();
private:
void showFilesDialog(const std::vector<std::string>& fileNames);
void showFilesDialog(const std::vector<FilePath>& filePaths);
bool m_isInForm;
QtThreadedFunctor<std::vector<std::string>> m_showFilesFunctor;
QtThreadedFunctor<const std::vector<FilePath>&> m_showFilesFunctor;
};
#endif // QT_PROJECT_WIZZARD_CONTENT_H
@@ -30,7 +30,7 @@ void QtProjectWizzardContentCDBSource::populate(QGridLayout* layout, int& row)
void QtProjectWizzardContentCDBSource::load()
{
m_fileNames.clear();
m_filePaths.clear();
const FilePath projectPath = m_settings->getProjectDirectoryPath();
std::vector<FilePath> excludePaths = m_settings->getExcludePathsExpandedAndAbsolute();
@@ -64,22 +64,22 @@ void QtProjectWizzardContentCDBSource::load()
path.makeRelativeTo(projectPath);
}
m_fileNames.push_back(path.str());
m_filePaths.push_back(path);
}
}
}
if (m_text)
{
m_text->setText("<b>" + QString::number(m_fileNames.size()) + "</b> source files were found in the compilation database.");
m_text->setText("<b>" + QString::number(m_filePaths.size()) + "</b> source files were found in the compilation database.");
}
}
std::vector<std::string> QtProjectWizzardContentCDBSource::getFileNames() const
std::vector<FilePath> QtProjectWizzardContentCDBSource::getFilePaths() const
{
const_cast<QtProjectWizzardContentCDBSource*>(this)->load();
return m_fileNames;
return m_filePaths;
}
QString QtProjectWizzardContentCDBSource::getFileNamesTitle() const
@@ -18,14 +18,14 @@ public:
virtual void load() override;
virtual std::vector<std::string> getFileNames() const override;
virtual std::vector<FilePath> getFilePaths() const override;
virtual QString getFileNamesTitle() const override;
virtual QString getFileNamesDescription() const override;
private:
std::shared_ptr<SourceGroupSettings> m_settings;
QLabel* m_text;
std::vector<std::string> m_fileNames;
std::vector<FilePath> m_filePaths;
};
#endif // QT_PROJECT_WIZZARD_CONTENT_CDB_SOURCE_H
@@ -221,14 +221,14 @@ void QtProjectWizzardContentPathSourceMaven::save()
}
}
std::vector<std::string> QtProjectWizzardContentPathSourceMaven::getFileNames() const
std::vector<FilePath> QtProjectWizzardContentPathSourceMaven::getFilePaths() const
{
std::shared_ptr<SourceGroupSettingsJavaMaven> settings = std::dynamic_pointer_cast<SourceGroupSettingsJavaMaven>(m_settings);
const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath();
const FilePath mavenProjectRoot = settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory();
std::vector<std::string> list;
std::vector<FilePath> list;
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
ScopedFunctor scopedFunctor([&dialogView](){
@@ -273,7 +273,7 @@ std::vector<std::string> QtProjectWizzardContentPathSourceMaven::getFileNames()
path.makeRelativeTo(projectPath);
}
list.push_back(path.str());
list.push_back(path);
}
}
@@ -366,13 +366,13 @@ void QtProjectWizzardContentPathSourceGradle::save()
}
}
std::vector<std::string> QtProjectWizzardContentPathSourceGradle::getFileNames() const
std::vector<FilePath> QtProjectWizzardContentPathSourceGradle::getFilePaths() const
{
std::shared_ptr<SourceGroupSettingsJavaGradle> settings = std::dynamic_pointer_cast<SourceGroupSettingsJavaGradle>(m_settings);
const FilePath gradleProjectRoot = settings->getGradleProjectFilePathExpandedAndAbsolute().getParentDirectory();
std::vector<std::string> list;
std::vector<FilePath> list;
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
@@ -404,7 +404,7 @@ std::vector<std::string> QtProjectWizzardContentPathSourceGradle::getFileNames()
path.makeRelativeTo(projectPath);
}
list.push_back(path.str());
list.push_back(path);
}
}
@@ -76,7 +76,7 @@ public:
virtual void load() override;
virtual void save() override;
virtual std::vector<std::string> getFileNames() const override;
virtual std::vector<FilePath> getFilePaths() const override;
private:
QCheckBox* m_shouldIndexTests;
@@ -109,7 +109,7 @@ public:
virtual void load() override;
virtual void save() override;
virtual std::vector<std::string> getFileNames() const override;
virtual std::vector<FilePath> getFilePaths() const override;
private:
QCheckBox* m_shouldIndexTests;
@@ -203,7 +203,7 @@ void QtProjectWizzardContentPathsSource::save()
m_settings->setSourcePaths(m_list->getList());
}
std::vector<std::string> QtProjectWizzardContentPathsSource::getFileNames() const
std::vector<FilePath> QtProjectWizzardContentPathsSource::getFilePaths() const
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
@@ -223,11 +223,7 @@ std::vector<std::string> QtProjectWizzardContentPathsSource::getFileNames() cons
const std::set<FilePath> filePaths = fileManager.getAllSourceFilePathsRelative(m_settings->getProjectDirectoryPath());
std::vector<std::string> list;
list.resize(filePaths.size());
std::transform(filePaths.begin(), filePaths.end(), list.begin(), [](const FilePath& p){ return p.str(); });
return list;
return utility::toVector(filePaths);
}
QString QtProjectWizzardContentPathsSource::getFileNamesTitle() const
@@ -648,7 +644,7 @@ void QtProjectWizzardContentPathsHeaderSearch::finishedSelectDetectIncludesRootP
void QtProjectWizzardContentPathsHeaderSearch::finishedAcceptDetectedIncludePathsDialog()
{
const std::vector<std::wstring> detectedPaths = utility::split<std::vector<std::wstring>>(m_filesDialog->getWText(), L"\n");
const std::vector<std::wstring> detectedPaths = utility::split<std::vector<std::wstring>>(m_filesDialog->getText(), L"\n");
closedFilesDialog();
std::vector<std::wstring> headerSearchPaths = m_list->getWStringList();
@@ -694,7 +690,7 @@ void QtProjectWizzardContentPathsHeaderSearch::showDetectedIncludesResult(const
}
else
{
std::string detailedText = "";
std::wstring detailedText = L"";
FilePath relativeRoot = m_list->getRelativeRootDirectory();
for (const FilePath& path : additionalHeaderSearchPaths)
{
@@ -703,12 +699,13 @@ void QtProjectWizzardContentPathsHeaderSearch::showDetectedIncludesResult(const
const FilePath relPath = path.getRelativeTo(relativeRoot);
if (relPath.str().size() < path.str().size())
{
detailedText += relPath.str() + "\n";
continue;
detailedText += relPath.wstr() + L"\n";
}
else
{
detailedText += path.wstr() + L"\n";
}
}
detailedText += path.str() + "\n";
}
m_filesDialog = std::make_shared<QtTextEditDialog>(
@@ -742,24 +739,24 @@ void QtProjectWizzardContentPathsHeaderSearch::showValidationResult(const std::v
}
else
{
std::map<std::string, std::map<size_t, std::string>> orderedIncludes;
std::map<std::wstring, std::map<size_t, std::wstring>> orderedIncludes;
for (const IncludeDirective& unresolvedInclude: unresolvedIncludes)
{
orderedIncludes[unresolvedInclude.getIncludingFile().str()].emplace(
orderedIncludes[unresolvedInclude.getIncludingFile().wstr()].emplace(
unresolvedInclude.getLineNumber(), unresolvedInclude.getDirective());
}
std::string detailedText = "";
std::wstring detailedText = L"";
for (const auto& p: orderedIncludes)
{
detailedText += p.first + "\n";
detailedText += p.first + L"\n";
for (const auto& p2: p.second)
{
detailedText += std::to_string(p2.first) + ":\t" + p2.second + "\n";
detailedText += std::to_wstring(p2.first) + L":\t" + p2.second + L"\n";
}
detailedText += "\n";
detailedText += L"\n";
}
m_filesDialog = std::make_shared<QtTextEditDialog>("Unresolved Include Directives",
@@ -68,7 +68,7 @@ public:
virtual void load() override;
virtual void save() override;
virtual std::vector<std::string> getFileNames() const override;
virtual std::vector<FilePath> getFilePaths() const override;
virtual QString getFileNamesTitle() const override;
virtual QString getFileNamesDescription() const override;
};