Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Fixing Qt 5.15 deprecations - part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisStAmour committed Apr 12, 2020
1 parent 75f13a3 commit 092b8d7
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/lib_gui/qt/element/QtStatusBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void QtStatusBar::setErrorCount(ErrorCountInfo errorCount)
: QLatin1String("")));

m_errorButton.setMinimumWidth(
m_errorButton.fontMetrics().width(QString(m_errorButton.text().size(), 'a')));
m_errorButton.fontMetrics().boundingRect(QString(m_errorButton.text().size(), 'a')).width());

if (errorCount.fatal > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib_gui/qt/element/code/QtCodeArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool MouseWheelOverScrollbarFilter::eventFilter(QObject* obj, QEvent* event)
if (event->type() == QEvent::Wheel && scrollbar)
{
QRect scrollbarArea(scrollbar->pos(), scrollbar->size());
QPoint globalMousePos = dynamic_cast<QWheelEvent*>(event)->globalPosition();
QPoint globalMousePos = dynamic_cast<QWheelEvent*>(event)->globalPosition().toPoint();
QPoint localMousePos = scrollbar->mapFromGlobal(globalMousePos);

// instead of "scrollbar->underMouse()" we need this check implemented here because
Expand Down
2 changes: 1 addition & 1 deletion src/lib_gui/qt/element/dialog/QtNewsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ QtNewsWidget::QtNewsWidget(QWidget* parent): QWidget(parent)
m_text = new QtTextEdit();
m_text->setObjectName(QStringLiteral("textField"));
m_text->setReadOnly(true);
m_text->setTabStopWidth(8 * m_text->fontMetrics().width('9'));
m_text->setTabStopDistance(8 * m_text->fontMetrics().boundingRect('9').width());
m_text->setViewportMargins(6, 4, 16, 4);
m_text->setOpenExternalLinks(true);
layout->addWidget(m_text);
Expand Down
4 changes: 2 additions & 2 deletions src/lib_gui/qt/element/search/QtSmartSearchBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ void QtSmartSearchBox::layoutElements()
if (!hasSelected && i == m_cursorIndex)
{
editX = x - 5;
x += fontMetrics().width(text());
x += fontMetrics().horizontalAdvance(text());
}

if (i < m_elements.size())
Expand All @@ -923,7 +923,7 @@ void QtSmartSearchBox::layoutElements()
}
}

int cursorX = fontMetrics().width(text().left(cursorPosition()));
int cursorX = fontMetrics().horizontalAdvance(text().left(cursorPosition()));
int offsetX = m_oldLayoutOffset;

if (x < width())
Expand Down
2 changes: 1 addition & 1 deletion src/lib_gui/qt/graphics/base/QtCountCircleItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ QtCountCircleItem::~QtCountCircleItem() {}

void QtCountCircleItem::setPosition(const Vec2f& pos)
{
qreal width = QFontMetrics(m_number->font()).width(m_number->text());
qreal width = QFontMetrics(m_number->font()).boundingRect(m_number->text()).width();
qreal height = QFontMetrics(m_number->font()).height();

this->setRadius(height / 2 + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void QtProjectWizardContentSelect::populate(QGridLayout* layout, int& row)
std::string pythonIndexerVersion = " ";
{
std::string str = utility::executeProcess(
"\"" + ResourcePaths::getPythonPath().str() +
"SourcetrailPythonIndexer\" --version",
ResourcePaths::getPythonPath().wstr().append(L"SourcetrailPythonIndexer"),
std::vector<std::wstring>{L"--version"},
FilePath(),
5000)
.second;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ std::vector<FilePath> CxxVs15HeaderPathDetector::doGetPaths() const
.expandEnvironmentVariables();
if (!expandedPaths.empty())
{
const std::string command = "\"" + expandedPaths[0].str() +
"\" -latest -property installationPath";
const std::string command2 =
"\"C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe\"";
const std::string output = utility::executeProcess(command, FilePath(), 10000).second;
const std::string output =
utility::executeProcess(
expandedPaths[0].wstr(), std::vector<std::wstring> {L"-latest", L"-property installationPath"}, FilePath(), 10000)
.second;

const FilePath vsInstallPath(output);
if (vsInstallPath.exists())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ namespace utility
std::vector<std::string> getCxxHeaderPaths(const std::string& compilerName)
{
std::string command = compilerName + " -x c++ -v -E /dev/null";
std::string clangOutput = utility::executeProcess(command.c_str()).second;
std::string clangOutput = utility::executeProcess(
utility::decodeFromUtf8(compilerName),
std::vector<std::wstring> {L"-x c++", L"-v", L"-E /dev/null"})
.second;
std::string standardHeaders = utility::substrBetween<std::string>(
clangOutput, "#include <...> search starts here:\n", "\nEnd of search list");
std::vector<std::string> paths;
Expand Down
65 changes: 29 additions & 36 deletions src/lib_gui/utility/utilityApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ std::set<QProcess*> s_runningProcesses;
} // namespace utility

std::pair<int, std::string> utility::executeProcess(
const std::string& command, const FilePath& workingDirectory, const int timeout)
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
const FilePath& workingDirectory,
const int timeout)
{
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
Expand All @@ -67,6 +70,13 @@ std::pair<int, std::string> utility::executeProcess(
process.setWorkingDirectory(QString::fromStdWString(workingDirectory.wstr()));
}

QString command = QString::fromStdWString(commandPath);
QStringList arguments;
for (auto commandArgument: commandArguments)
{
arguments << QString::fromStdWString(commandArgument);
}

QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QStringList envlist = env.toStringList();
envlist.replaceInStrings(
Expand All @@ -76,7 +86,7 @@ std::pair<int, std::string> utility::executeProcess(

{
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
process.start(command.c_str());
process.start(command, arguments);
s_runningProcesses.insert(&process);
}

Expand All @@ -96,7 +106,10 @@ std::pair<int, std::string> utility::executeProcess(
}

std::string utility::executeProcessUntilNoOutput(
const std::string& command, const FilePath& workingDirectory, const int waitTime)
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
const FilePath& workingDirectory,
const int waitTime)
{
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
Expand All @@ -106,6 +119,13 @@ std::string utility::executeProcessUntilNoOutput(
process.setWorkingDirectory(QString::fromStdWString(workingDirectory.wstr()));
}

QString command = QString::fromStdWString(commandPath);
QStringList arguments;
for (auto commandArgument: commandArguments)
{
arguments << QString::fromStdWString(commandArgument);
}

QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QStringList envlist = env.toStringList();
envlist.replaceInStrings(
Expand All @@ -115,7 +135,7 @@ std::string utility::executeProcessUntilNoOutput(

{
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
process.start(command.c_str());
process.start(command, arguments);
s_runningProcesses.insert(&process);
}

Expand Down Expand Up @@ -203,9 +223,10 @@ int utility::executeProcessAndGetExitCode(
}

QString command = QString::fromStdWString(commandPath);
for (const std::wstring& commandArgument: commandArguments)
QStringList arguments;
for (auto commandArgument: commandArguments)
{
command += " " + QString::fromStdWString(commandArgument);
arguments << QString::fromStdWString(commandArgument);
}

QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
Expand All @@ -217,7 +238,7 @@ int utility::executeProcessAndGetExitCode(

{
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
process.start(command);
process.start(command, arguments);
s_runningProcesses.insert(&process);
}

Expand Down Expand Up @@ -276,23 +297,6 @@ int utility::getIdealThreadCount()
return std::max(1, threadCount);
}

OsType utility::getOsType()
{
if (QSysInfo::windowsVersion() != QSysInfo::WV_None)
{
return OS_WINDOWS;
}
else if (QSysInfo::macVersion() != QSysInfo::MV_None)
{
return OS_MAC;
}
else
{
return OS_LINUX;
}
return OS_UNKNOWN;
}

std::string utility::getOsTypeString()
{
// WARNING: Don't change these string. The server API relies on them.
Expand All @@ -308,15 +312,4 @@ std::string utility::getOsTypeString()
break;
}
return "unknown";
}

ApplicationArchitectureType utility::getApplicationArchitectureType()
{
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) || \
defined(WIN64)
return APPLICATION_ARCHITECTURE_X86_64;
#else
return APPLICATION_ARCHITECTURE_X86_32;
#endif
return APPLICATION_ARCHITECTURE_UNKNOWN;
}
}
34 changes: 30 additions & 4 deletions src/lib_gui/utility/utilityApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
namespace utility
{
std::pair<int, std::string> executeProcess(
const std::string& command,
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
const FilePath& workingDirectory = FilePath(),
const int timeout = 30000);
std::string executeProcessUntilNoOutput(
const std::string& command, const FilePath& workingDirectory, int waitTime = 10000);
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
const FilePath& workingDirectory,
int waitTime = 10000);
int executeProcessAndGetExitCode(
const std::wstring& commandPath,
const std::vector<std::wstring>& commandArguments,
Expand All @@ -26,9 +30,31 @@ int executeProcessAndGetExitCode(
void killRunningProcesses();
int getIdealThreadCount();

OsType getOsType();
constexpr OsType getOsType()
{
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
return OS_WINDOWS;
#elif defined(__APPLE__)
return OS_MAC;
#elif defined(__linux) || defined(__linux__) || defined(linux)
return OS_LINUX;
#else
return OS_UNKNOWN;
#endif
}

std::string getOsTypeString();
ApplicationArchitectureType getApplicationArchitectureType();

constexpr ApplicationArchitectureType getApplicationArchitectureType()
{
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) || \
defined(WIN64)
return APPLICATION_ARCHITECTURE_X86_64;
#else
return APPLICATION_ARCHITECTURE_X86_32;
#endif
return APPLICATION_ARCHITECTURE_UNKNOWN;
}
} // namespace utility

#endif // UTILITY_APP_H

0 comments on commit 092b8d7

Please sign in to comment.