Skip to content

Commit

Permalink
[WIP] Start removing implicit ascii to qstring conversin
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasaglia committed Nov 27, 2023
1 parent c7a1300 commit 3342ed0
Show file tree
Hide file tree
Showing 98 changed files with 2,025 additions and 1,974 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings)

# TODO: The following definitons should be enabled
remove_definitions(
-DQT_NO_CAST_FROM_ASCII
)

if (NOT DEFINED KF_MAJOR)
set(KF_MAJOR ${QT_MAJOR_VERSION})
endif()
Expand Down
11 changes: 6 additions & 5 deletions external/QtAppSetup/src/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QIcon>

#include "app/log/log.hpp"
#include "app/utils/qstring_literal.hpp"


void app::Application::initialize()
Expand Down Expand Up @@ -69,13 +70,13 @@ QList<QDir> app::Application::data_roots() const
QDir binpath(QCoreApplication::applicationDirPath());
#ifdef Q_OS_WIN
// some Windows apps do not use a bin subfolder
search.push_back(binpath.filePath(QString("share/%1/%2").arg(organizationName()).arg(applicationName())));
search.push_back(binpath.filePath("share/%1/%2"_qs.arg(organizationName()).arg(applicationName())));
#endif
binpath.cdUp();
search.push_back(binpath.filePath(QString("share/%1/%2").arg(organizationName()).arg(applicationName())));
search.push_back(binpath.filePath("share/%1/%2"_qs.arg(organizationName()).arg(applicationName())));
#ifdef Q_OS_MAC
// some macOS app bundles use a Resources subfolder
search.push_back(binpath.filePath(QString("Resources/%1/%2").arg(organizationName()).arg(applicationName())));
search.push_back(binpath.filePath("Resources/%1/%2"_qs.arg(organizationName()).arg(applicationName())));
#endif

return search;
Expand All @@ -96,15 +97,15 @@ QString app::Application::data_file(const QString& name) const

QSettings app::Application::qsettings() const
{
return QSettings(writable_data_path("settings.ini"), QSettings::IniFormat);
return QSettings(writable_data_path("settings.ini"_qs), QSettings::IniFormat);
}

bool app::Application::notify(QObject* receiver, QEvent* e)
{
try {
return QApplication::notify(receiver, e);
} catch ( const std::exception& exc ) {
log::Log("Event", QMetaEnum::fromType<QEvent::Type>().valueToKey(e->type())).stream(log::Error) << "Exception:" << exc.what();
log::Log("Event"_qs, QString::fromUtf8(QMetaEnum::fromType<QEvent::Type>().valueToKey(e->type()))).stream(log::Error) << "Exception:" << exc.what();
return false;
}
}
Expand Down
40 changes: 20 additions & 20 deletions external/QtAppSetup/src/app/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ QString app::cli::Argument::get_slug(const QStringList& names)

for ( int i = 0; i < match.size(); i++ )
{
if ( match[i] != '-' )
if ( match[i] != '-'_qc )
return match.mid(i);
}

Expand All @@ -46,13 +46,13 @@ QVariant app::cli::Argument::arg_to_value(const QString& v, bool* ok) const
return v.toInt(ok);
case Size:
{
if ( !v.contains('x') )
if ( !v.contains('x'_qc) )
{
*ok = false;
return {};
}

auto vec = utils::split_ref(v, 'x');
auto vec = utils::split_ref(v, 'x'_qc);
if ( vec.size() != 2 )
{
*ok = false;
Expand Down Expand Up @@ -119,23 +119,23 @@ QString app::cli::Argument::help_text_name() const
{
QString option_names;
for ( const auto& name : names )
option_names += name + ", ";
option_names += name + ", "_qs;
if ( !names.isEmpty() )
option_names.chop(2);

if ( !arg_name.isEmpty() )
option_names += " <" + arg_name + ">";
option_names += " <"_qs + arg_name + ">"_qs;

if ( nargs > 1 )
option_names += "...";
option_names += "..."_qs;

return option_names;
}


bool app::cli::Argument::is_positional() const
{
return names.size() == 1 && !names[0].startsWith('-') && nargs > 0;
return names.size() == 1 && !names[0].startsWith('-'_qc) && nargs > 0;
}


Expand Down Expand Up @@ -195,7 +195,7 @@ app::cli::ParsedArguments app::cli::Parser::parse(const QStringList& args, int o

for ( int index = offset; index < args.size(); )
{
if ( args[index].startsWith('-') )
if ( args[index].startsWith('-'_qc) )
{
if ( auto opt = option_from_arg(args[index]) )
{
Expand Down Expand Up @@ -252,12 +252,12 @@ app::cli::ParsedArguments app::cli::Parser::parse(const QStringList& args, int o

QString app::cli::Parser::version_text() const
{
return QCoreApplication::applicationName() + " " + QCoreApplication::applicationVersion() + "\n";
return QCoreApplication::applicationName() + " "_qs + QCoreApplication::applicationVersion() + "\n"_qs;
}

void app::cli::show_message(const QString& msg, bool error)
{
std::fputs(qUtf8Printable(msg + '\n'), error ? stderr : stdout);
std::fputs(qUtf8Printable(msg + '\n'_qc), error ? stderr : stdout);
}


Expand All @@ -283,7 +283,7 @@ QString app::cli::Parser::help_text() const

for ( const auto& pos : positional )
{
usage += " " + pos.arg_name;
usage += " "_qs + pos.arg_name;
QString name = pos.help_text_name();
if ( longest_name < name.size() )
longest_name = name.size();
Expand All @@ -292,24 +292,24 @@ QString app::cli::Parser::help_text() const

QString text;
text += QApplication::tr("Usage: %1").arg(usage);
text += '\n';
text += '\n';
text += '\n'_qc;
text += '\n'_qc;
text += description;
text += '\n';
text += '\n'_qc;

for ( const auto& grp : groups )
{
text += '\n';
text += '\n'_qc;
text += grp.name;
text += ":\n";
text += ":\n"_qs;
for ( const auto& p : grp.args )
{
text += wrap_text(
(p.first == Positional ? pos_names : opt_names)[p.second],
longest_name,
(p.first == Positional ? positional : options)[p.second].description
);
text += '\n';
text += '\n'_qc;
}
}

Expand Down Expand Up @@ -352,7 +352,7 @@ QString app::cli::Parser::wrap_text(const QString& names, int name_max, const QS
// time to break but found nowhere [-> break here], or end of last line
breakAt = i + 1;
nextLineStart = breakAt;
} else if (c == '\n') {
} else if (c == '\n'_qc) {
// forced break
breakAt = i;
nextLineStart = i + 1;
Expand All @@ -362,7 +362,7 @@ QString app::cli::Parser::wrap_text(const QString& names, int name_max, const QS
const int numChars = breakAt - lineStart;
text += indentation + nextNameSection().leftJustified(name_max) + QLatin1Char(' ');
text += utils::mid_ref(description, lineStart, numChars);
text += '\n';
text += '\n'_qc;
x = 0;
lastBreakable = -1;
lineStart = nextLineStart;
Expand All @@ -373,7 +373,7 @@ QString app::cli::Parser::wrap_text(const QString& names, int name_max, const QS
}

while (nameIndex < names.size()) {
text += indentation + nextNameSection() + '\n';
text += indentation + nextNameSection() + '\n'_qc;
}

return text;
Expand Down
6 changes: 4 additions & 2 deletions external/QtAppSetup/src/app/cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <QString>
#include <QSet>

#include "app/utils/qstring_literal.hpp"

namespace app::cli {


Expand All @@ -23,7 +25,7 @@ class ArgumentError : public std::invalid_argument

QString message() const
{
return QString(what());
return QString::fromUtf8(what());
}
};

Expand Down Expand Up @@ -81,7 +83,7 @@ struct Argument
this->dest = get_slug(names);

// positional
if ( names.size() == 1 && !names[0].startsWith('-') )
if ( names.size() == 1 && !names[0].startsWith('-'_qc) )
{
type = String;
nargs = 1;
Expand Down
4 changes: 2 additions & 2 deletions external/QtAppSetup/src/app/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <QStringList>

#ifdef Q_OS_WIN
# define ENV_SEPARATOR ";"
# define ENV_SEPARATOR QStringLiteral(";")
#else
# define ENV_SEPARATOR ":"
# define ENV_SEPARATOR QStringLiteral(":")
#endif

namespace app {
Expand Down
4 changes: 2 additions & 2 deletions external/QtAppSetup/src/app/log/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace app::log {
class LogStream
{
public:
LogStream(const QString& source, const QString& detail = "", Severity severity = Warning)
LogStream(const QString& source, const QString& detail = {}, Severity severity = Warning)
: source(source), detail(detail), severity(severity)
{}

Expand Down Expand Up @@ -45,7 +45,7 @@ class LogStream
class Log
{
public:
Log(const QString& source, const QString& detail="")
Log(const QString& source, const QString& detail = {})
: source(source), detail(detail)
{}

Expand Down
7 changes: 4 additions & 3 deletions external/QtAppSetup/src/app/log/log_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "log_model.hpp"
#include "app/utils/qstring_literal.hpp"

namespace {
enum Columns
Expand Down Expand Up @@ -58,9 +59,9 @@ QVariant app::log::LogModel::headerData(int section, Qt::Orientation orientation
{
switch ( lines[section].severity )
{
case Info: return QIcon::fromTheme("emblem-information");
case Warning: return QIcon::fromTheme("emblem-warning");
case Error: return QIcon::fromTheme("emblem-error");
case Info: return QIcon::fromTheme("emblem-information"_qs);
case Warning: return QIcon::fromTheme("emblem-warning"_qs);
case Error: return QIcon::fromTheme("emblem-error"_qs);
}
}
else if ( role == Qt::ToolTipRole )
Expand Down
8 changes: 4 additions & 4 deletions external/QtAppSetup/src/app/log/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class Logger : public QObject
switch ( s )
{
case Info:
return "Info";
return QStringLiteral("Info");
case Warning:
return "Warning";
return QStringLiteral("Warning");
case Error:
return "Error";
return QStringLiteral("Error");
default:
return "?";
return QStringLiteral("?");
}
}

Expand Down
18 changes: 9 additions & 9 deletions external/QtAppSetup/src/app/scripting/python/python_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "app/scripting/python/register_machinery.hpp"
#include "app/log/log.hpp"
#include "app/env.hpp"

#include "app/utils/qstring_literal.hpp"

app::scripting::ScriptEngine::Autoregister<app::scripting::python::PythonEngine> app::scripting::python::PythonEngine::autoreg;

Expand Down Expand Up @@ -45,7 +45,7 @@ class PY_HIDDEN CaptureStream
this->owner = owner;
this->signal = signal;
} catch ( const py::error_already_set& pyexc ) {
app::log::Log("Python").stream(app::log::Error)
app::log::Log("Python"_qs).stream(app::log::Error)
<< "Could not initialize stream capture:" << pyexc.what();
}
}
Expand All @@ -56,7 +56,7 @@ class PY_HIDDEN CaptureStream
return;

int from = 0;
int to = data.indexOf('\n');
int to = data.indexOf('\n'_qc);
while ( to != -1 )
{
QString txt;
Expand All @@ -68,7 +68,7 @@ class PY_HIDDEN CaptureStream
txt += data.mid(from, to-from);
(owner->*signal)(txt);
from = to+1;
to = data.indexOf('\n', from);
to = data.indexOf('\n'_qc, from);
}
buf += data.mid(from);
}
Expand Down Expand Up @@ -145,7 +145,7 @@ void app::scripting::python::PythonContext::expose(const QString& name, const QV
try {
d->globals[name.toStdString().c_str()] = obj;
} catch ( const py::error_already_set& pyexc ) {
throw ScriptError(pyexc.what());
throw ScriptError(QString::fromUtf8(pyexc.what()));
}
}

Expand All @@ -165,9 +165,9 @@ QString app::scripting::python::PythonContext::eval_to_string(const QString& cod
py::exec(std_code);
return {};
} catch ( const py::error_already_set& pyexc ) {
throw ScriptError(pyexc.what());
throw ScriptError(QString::fromUtf8(pyexc.what()));
} catch ( const py::builtin_exception& pyexc ) {
throw ScriptError(pyexc.what());
throw ScriptError(QString::fromUtf8(pyexc.what()));
}
}

Expand Down Expand Up @@ -204,7 +204,7 @@ void app::scripting::python::PythonContext::app_module ( const QString& name )
d->my_modules.push_back(py::module::import(cname));
d->globals[cname] = d->my_modules.back();
} catch ( const py::error_already_set& pyexc ) {
log::Log("Python", name).log(pyexc.what(), log::Error);
log::Log("Python"_qs, name).log(QString::fromUtf8(pyexc.what()), log::Error);
}
}

Expand Down Expand Up @@ -250,7 +250,7 @@ bool app::scripting::python::PythonContext::run_from_module (
py_args[i++] = arg;
exec_module.attr(std_func.c_str())(*py_args);
} catch ( const py::error_already_set& pyexc ) {
throw ScriptError(pyexc.what());
throw ScriptError(QString::fromUtf8(pyexc.what()));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class PythonEngine : public ScriptEngine
public:
static void add_module_search_paths(const QStringList& paths);

QString slug() const override { return "python"; }
QString label() const override { return "Python"; }
QString slug() const override { return QStringLiteral("python"); }
QString label() const override { return QStringLiteral("Python"); }

ScriptContext create_context() const override;

Expand Down
Loading

0 comments on commit 3342ed0

Please sign in to comment.