Editor/CMakeLists: Add QT_NO_CAST_FROM/TO_ASCII

Prevents implicit conversions to QString, requiring the conversions to
be made explicitly. Prevents potentially incompatible encodings from
being intermixed with one another.
This commit is contained in:
Lioncash 2019-08-25 22:52:24 -04:00
parent 658c33eb0d
commit da54ade80b
7 changed files with 90 additions and 60 deletions

View File

@ -61,6 +61,10 @@ add_executable(amuse-gui WIN32 MACOSX_BUNDLE
) )
target_compile_definitions(amuse-gui PRIVATE target_compile_definitions(amuse-gui PRIVATE
# Disable implicit conversions from ASCII to QString.
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_CAST_TO_ASCII
# Allows for more efficient string concatenation, resulting in less temporaries. # Allows for more efficient string concatenation, resulting in less temporaries.
-DQT_USE_QSTRINGBUILDER -DQT_USE_QSTRINGBUILDER
) )

View File

@ -250,13 +250,12 @@ void MainWindow::updateWindowTitle() {
} }
void MainWindow::updateRecentFileActions() { void MainWindow::updateRecentFileActions() {
QSettings settings; const QSettings settings;
QStringList files = settings.value("recentFileList").toStringList(); const QStringList files = settings.value(QStringLiteral("recentFileList")).toStringList();
const int numRecentFiles = std::min(files.size(), int(MaxRecentFiles));
int numRecentFiles = std::min(files.size(), int(MaxRecentFiles));
for (int i = 0; i < numRecentFiles; ++i) { for (int i = 0; i < numRecentFiles; ++i) {
QString text = QStringLiteral("&%1 %2").arg(i + 1).arg(QDir(files[i]).dirName()); const QString text = QStringLiteral("&%1 %2").arg(i + 1).arg(QDir(files[i]).dirName());
m_recentFileActs[i]->setText(text); m_recentFileActs[i]->setText(text);
m_recentFileActs[i]->setData(files[i]); m_recentFileActs[i]->setData(files[i]);
m_recentFileActs[i]->setToolTip(files[i]); m_recentFileActs[i]->setToolTip(files[i]);
@ -321,13 +320,15 @@ bool MainWindow::setProjectPath(const QString& path) {
updateNavigationButtons(); updateNavigationButtons();
const QString key = QStringLiteral("recentFileList");
QSettings settings; QSettings settings;
QStringList files = settings.value("recentFileList").toStringList(); QStringList files = settings.value(key).toStringList();
files.removeAll(dir.path()); files.removeAll(dir.path());
files.prepend(dir.path()); files.prepend(dir.path());
while (files.size() > MaxRecentFiles) while (files.size() > MaxRecentFiles) {
files.removeLast(); files.removeLast();
settings.setValue("recentFileList", files); }
settings.setValue(key, files);
settings.sync(); settings.sync();
updateRecentFileActions(); updateRecentFileActions();
@ -801,16 +802,22 @@ void MainWindow::_openAction(const QString& path) {
} }
void MainWindow::openRecentFileAction() { void MainWindow::openRecentFileAction() {
if (!askAboutSave()) if (!askAboutSave()) {
return; return;
}
if (QAction* action = qobject_cast<QAction*>(sender())) if (const QAction* action = qobject_cast<QAction*>(sender())) {
if (!openProject(action->data().toString())) { const QString path = action->data().toString();
QString path = action->data().toString(); if (openProject(path)) {
return;
}
const QString key = QStringLiteral("recentFileList");
QSettings settings; QSettings settings;
QStringList files = settings.value("recentFileList").toStringList(); QStringList files = settings.value(key).toStringList();
files.removeAll(path); files.removeAll(path);
settings.setValue("recentFileList", files); settings.setValue(key, files);
settings.sync(); settings.sync();
updateRecentFileActions(); updateRecentFileActions();
} }
@ -818,7 +825,7 @@ void MainWindow::openRecentFileAction() {
void MainWindow::clearRecentFilesAction() { void MainWindow::clearRecentFilesAction() {
QSettings settings; QSettings settings;
settings.setValue("recentFileList", QStringList()); settings.setValue(QStringLiteral("recentFileList"), QStringList());
settings.sync(); settings.sync();
updateRecentFileActions(); updateRecentFileActions();
} }
@ -943,11 +950,10 @@ void MainWindow::_importAction(const QString& path) {
ProjectModel* model = m_projectModel; ProjectModel* model = m_projectModel;
startBackgroundTask( startBackgroundTask(
TaskImport, tr("Importing"), tr("Scanning Project"), [model, path, importMode](BackgroundTask& task) { TaskImport, tr("Importing"), tr("Scanning Project"), [model, path, importMode](BackgroundTask& task) {
QDir dir = QFileInfo(path).dir(); const QDir dir = QFileInfo(path).dir();
QStringList filters; const QStringList filters{QStringLiteral("*.proj"), QStringLiteral("*.pro")};
filters << "*.proj" const QStringList files = dir.entryList(filters, QDir::Files);
<< "*.pro";
QStringList files = dir.entryList(filters, QDir::Files);
for (const QString& fPath : files) { for (const QString& fPath : files) {
auto data = amuse::ContainerRegistry::LoadContainer(QStringToSysString(dir.filePath(fPath)).c_str()); auto data = amuse::ContainerRegistry::LoadContainer(QStringToSysString(dir.filePath(fPath)).c_str());
for (auto& p : data) { for (auto& p : data) {

View File

@ -492,9 +492,9 @@ ProjectModel::ProjectModel(const QString& path, QObject* parent)
: QAbstractItemModel(parent), m_dir(path), m_outlineProxy(this), m_nullProxy(this), m_pageObjectProxy(this) { : QAbstractItemModel(parent), m_dir(path), m_outlineProxy(this), m_nullProxy(this), m_pageObjectProxy(this) {
m_root = amuse::MakeObj<RootNode>(); m_root = amuse::MakeObj<RootNode>();
GroupNode::Icon = QIcon(":/icons/IconGroup.svg"); GroupNode::Icon = QIcon(QStringLiteral(":/icons/IconGroup.svg"));
SongGroupNode::Icon = QIcon(":/icons/IconSongGroup.svg"); SongGroupNode::Icon = QIcon(QStringLiteral(":/icons/IconSongGroup.svg"));
SoundGroupNode::Icon = QIcon(":/icons/IconSoundGroup.svg"); SoundGroupNode::Icon = QIcon(QStringLiteral(":/icons/IconSoundGroup.svg"));
} }
bool ProjectModel::clearProjectData() { bool ProjectModel::clearProjectData() {
@ -800,15 +800,15 @@ void ProjectModel::updateNodeNames() {
gn->oneLevelTraverse([](INode* n) { gn->oneLevelTraverse([](INode* n) {
if (n->type() == INode::Type::SongGroup) { if (n->type() == INode::Type::SongGroup) {
SongGroupNode* sgn = static_cast<SongGroupNode*>(n); SongGroupNode* sgn = static_cast<SongGroupNode*>(n);
sgn->m_name = amuse::GroupId::CurNameDB->resolveNameFromId(sgn->m_id).data(); sgn->m_name = QString::fromUtf8(amuse::GroupId::CurNameDB->resolveNameFromId(sgn->m_id).data());
} else if (n->type() == INode::Type::SoundGroup) { } else if (n->type() == INode::Type::SoundGroup) {
SoundGroupNode* sgn = static_cast<SoundGroupNode*>(n); SoundGroupNode* sgn = static_cast<SoundGroupNode*>(n);
sgn->m_name = amuse::GroupId::CurNameDB->resolveNameFromId(sgn->m_id).data(); sgn->m_name = QString::fromUtf8(amuse::GroupId::CurNameDB->resolveNameFromId(sgn->m_id).data());
} else if (n->type() == INode::Type::Collection) { } else if (n->type() == INode::Type::Collection) {
CollectionNode* cn = static_cast<CollectionNode*>(n); CollectionNode* cn = static_cast<CollectionNode*>(n);
cn->oneLevelTraverse([](INode* n) { cn->oneLevelTraverse([](INode* n) {
BasePoolObjectNode* on = static_cast<BasePoolObjectNode*>(n); BasePoolObjectNode* on = static_cast<BasePoolObjectNode*>(n);
on->m_name = on->getNameDb()->resolveNameFromId(on->m_id).data(); on->m_name = QString::fromUtf8(on->getNameDb()->resolveNameFromId(on->m_id).data());
return true; return true;
}); });
cn->_sortChildren(); cn->_sortChildren();
@ -824,12 +824,13 @@ void ProjectModel::updateNodeNames() {
void ProjectModel::_buildGroupNodeCollections(GroupNode& gn) { void ProjectModel::_buildGroupNodeCollections(GroupNode& gn) {
gn.reserve(6); gn.reserve(6);
gn._appendChild<CollectionNode>(tr("Sound Macros"), QIcon(":/icons/IconSoundMacro.svg"), INode::Type::SoundMacro); gn._appendChild<CollectionNode>(tr("Sound Macros"), QIcon(QStringLiteral(":/icons/IconSoundMacro.svg")),
gn._appendChild<CollectionNode>(tr("ADSRs"), QIcon(":/icons/IconADSR.svg"), INode::Type::ADSR); INode::Type::SoundMacro);
gn._appendChild<CollectionNode>(tr("Curves"), QIcon(":/icons/IconCurve.svg"), INode::Type::Curve); gn._appendChild<CollectionNode>(tr("ADSRs"), QIcon(QStringLiteral(":/icons/IconADSR.svg")), INode::Type::ADSR);
gn._appendChild<CollectionNode>(tr("Keymaps"), QIcon(":/icons/IconKeymap.svg"), INode::Type::Keymap); gn._appendChild<CollectionNode>(tr("Curves"), QIcon(QStringLiteral(":/icons/IconCurve.svg")), INode::Type::Curve);
gn._appendChild<CollectionNode>(tr("Layers"), QIcon(":/icons/IconLayers.svg"), INode::Type::Layer); gn._appendChild<CollectionNode>(tr("Keymaps"), QIcon(QStringLiteral(":/icons/IconKeymap.svg")), INode::Type::Keymap);
gn._appendChild<CollectionNode>(tr("Samples"), QIcon(":/icons/IconSample.svg"), INode::Type::Sample); gn._appendChild<CollectionNode>(tr("Layers"), QIcon(QStringLiteral(":/icons/IconLayers.svg")), INode::Type::Layer);
gn._appendChild<CollectionNode>(tr("Samples"), QIcon(QStringLiteral(":/icons/IconSample.svg")), INode::Type::Sample);
} }
void ProjectModel::_buildGroupNode(GroupNode& gn, amuse::AudioGroup& group) { void ProjectModel::_buildGroupNode(GroupNode& gn, amuse::AudioGroup& group) {
@ -1736,15 +1737,23 @@ QMimeData* ProjectModel::mimeData(const QModelIndexList& indexes) const {
bool ProjectModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, bool ProjectModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
const QModelIndex& parent) { const QModelIndex& parent) {
if (data->hasFormat(QStringLiteral("application/x-amuse-subprojectpath"))) { if (data->hasFormat(QStringLiteral("application/x-amuse-subprojectpath"))) {
auto path = data->data(QStringLiteral("application/x-amuse-subprojectpath")); const auto path = data->data(QStringLiteral("application/x-amuse-subprojectpath"));
QDir oldDir(path); const QDir oldDir(QString::fromUtf8(path));
QString newName = MakeDedupedSubprojectName(oldDir.dirName()); const QString newName = MakeDedupedSubprojectName(oldDir.dirName());
m_dir.mkdir(newName); m_dir.mkdir(newName);
QDir newDir(QFileInfo(m_dir, newName).filePath());
for (auto ent : oldDir.entryList({"*.wav", "*.dsp", "*.vadpcm", "!pool.yaml", "!project.yaml"}, QDir::Files)) const QDir newDir(QFileInfo(m_dir, newName).filePath());
const auto entryList =
oldDir.entryList({QStringLiteral("*.wav"), QStringLiteral("*.dsp"), QStringLiteral("*.vadpcm"),
QStringLiteral("!pool.yaml"), QStringLiteral("!project.yaml")},
QDir::Files);
for (const auto& ent : entryList) {
QFile::copy(QFileInfo(oldDir, ent).filePath(), QFileInfo(newDir, ent).filePath()); QFile::copy(QFileInfo(oldDir, ent).filePath(), QFileInfo(newDir, ent).filePath());
}
auto dataNode = std::make_unique<amuse::AudioGroupDatabase>(QStringToSysString(newDir.path())); auto dataNode = std::make_unique<amuse::AudioGroupDatabase>(QStringToSysString(newDir.path()));
auto node = amuse::MakeObj<GroupNode>(newName); const auto node = amuse::MakeObj<GroupNode>(newName);
_buildGroupNode(*node, *dataNode); _buildGroupNode(*node, *dataNode);
g_MainWindow->pushUndoCommand( g_MainWindow->pushUndoCommand(
new GroupNodeAddUndoCommand(tr("Add Subproject %1"), std::move(dataNode), node.get())); new GroupNodeAddUndoCommand(tr("Add Subproject %1"), std::move(dataNode), node.get()));
@ -1773,14 +1782,16 @@ bool ProjectModel::dropMimeData(const QMimeData* data, Qt::DropAction action, in
else if (data->hasFormat(QStringLiteral("application/x-amuse-layers"))) else if (data->hasFormat(QStringLiteral("application/x-amuse-layers")))
loadMimeData<LayersNode>(data, QStringLiteral("application/x-amuse-layers"), gn); loadMimeData<LayersNode>(data, QStringLiteral("application/x-amuse-layers"), gn);
else if (data->hasFormat(QStringLiteral("application/x-amuse-samplepath"))) { else if (data->hasFormat(QStringLiteral("application/x-amuse-samplepath"))) {
auto path = data->data(QStringLiteral("application/x-amuse-samplepath")); const auto path = data->data(QStringLiteral("application/x-amuse-samplepath"));
QString newName = MakeDedupedName(QFileInfo(path).completeBaseName(), amuse::SampleId::CurNameDB); const QString newName =
QString newBasePath = QFileInfo(QFileInfo(m_dir, gn->name()).filePath(), newName).filePath(); MakeDedupedName(QFileInfo(QString::fromUtf8(path)).completeBaseName(), amuse::SampleId::CurNameDB);
amuse::SystemString newBasePathStr = QStringToSysString(newBasePath); const QString newBasePath = QFileInfo(QFileInfo(m_dir, gn->name()).filePath(), newName).filePath();
const amuse::SystemString newBasePathStr = QStringToSysString(newBasePath);
gn->getAudioGroup()->copySampleInto(QStringToSysString(QString::fromUtf8(path)), newBasePathStr); gn->getAudioGroup()->copySampleInto(QStringToSysString(QString::fromUtf8(path)), newBasePathStr);
auto dataNode = amuse::MakeObj<amuse::SampleEntry>(); auto dataNode = amuse::MakeObj<amuse::SampleEntry>();
dataNode->loadLooseData(newBasePathStr); dataNode->loadLooseData(newBasePathStr);
auto node = amuse::MakeObj<SampleNode>(newName, dataNode); const auto node = amuse::MakeObj<SampleNode>(newName, dataNode);
NameUndoRegistry dummy; NameUndoRegistry dummy;
_addPoolNode(node.get(), gn, dummy, gn->getAudioGroup()->getSdir().sampleEntries()); _addPoolNode(node.get(), gn, dummy, gn->getAudioGroup()->getSdir().sampleEntries());
} else } else
@ -1860,13 +1871,21 @@ QModelIndex ProjectModel::duplicate(const QModelIndex& index) {
GroupNode* gn = getGroupNode(n); GroupNode* gn = getGroupNode(n);
switch (n->type()) { switch (n->type()) {
case INode::Type::Group: { case INode::Type::Group: {
GroupNode* cn = static_cast<GroupNode*>(n); auto* const cn = static_cast<GroupNode*>(n);
newName = MakeDedupedSubprojectName(n->name()); newName = MakeDedupedSubprojectName(n->name());
m_dir.mkdir(newName); m_dir.mkdir(newName);
QDir oldDir(QFileInfo(m_dir, n->name()).filePath());
QDir newDir(QFileInfo(m_dir, newName).filePath()); const QDir oldDir(QFileInfo(m_dir, n->name()).filePath());
for (auto ent : oldDir.entryList({"*.wav", "*.dsp", "*.vadpcm", "!pool.yaml"}, QDir::Files)) const QDir newDir(QFileInfo(m_dir, newName).filePath());
const auto entryList = oldDir.entryList(
{QStringLiteral("*.wav"), QStringLiteral("*.dsp"), QStringLiteral("*.vadpcm"), QStringLiteral("!pool.yaml")},
QDir::Files);
for (const auto& ent : entryList) {
QFile::copy(QFileInfo(oldDir, ent).filePath(), QFileInfo(newDir, ent).filePath()); QFile::copy(QFileInfo(oldDir, ent).filePath(), QFileInfo(newDir, ent).filePath());
}
auto data = std::make_unique<amuse::AudioGroupDatabase>(*cn->getAudioGroup(), QStringToSysString(newDir.path())); auto data = std::make_unique<amuse::AudioGroupDatabase>(*cn->getAudioGroup(), QStringToSysString(newDir.path()));
auto node = amuse::MakeObj<GroupNode>(newName); auto node = amuse::MakeObj<GroupNode>(newName);
_buildGroupNode(*node, *data); _buildGroupNode(*node, *data);

View File

@ -259,7 +259,7 @@ public:
amuse::ObjToken<amuse::SongGroupIndex> m_index; amuse::ObjToken<amuse::SongGroupIndex> m_index;
SongGroupNode(const QString& name, amuse::ObjToken<amuse::SongGroupIndex> index) : INode(name), m_index(index) {} SongGroupNode(const QString& name, amuse::ObjToken<amuse::SongGroupIndex> index) : INode(name), m_index(index) {}
SongGroupNode(amuse::GroupId id, amuse::ObjToken<amuse::SongGroupIndex> index) SongGroupNode(amuse::GroupId id, amuse::ObjToken<amuse::SongGroupIndex> index)
: INode(amuse::GroupId::CurNameDB->resolveNameFromId(id).data()), m_id(id), m_index(index) {} : INode(QString::fromUtf8(amuse::GroupId::CurNameDB->resolveNameFromId(id).data())), m_id(id), m_index(index) {}
static QIcon Icon; static QIcon Icon;
Type type() const override { return Type::SongGroup; } Type type() const override { return Type::SongGroup; }
@ -285,7 +285,7 @@ public:
amuse::ObjToken<amuse::SFXGroupIndex> m_index; amuse::ObjToken<amuse::SFXGroupIndex> m_index;
SoundGroupNode(const QString& name, amuse::ObjToken<amuse::SFXGroupIndex> index) : INode(name), m_index(index) {} SoundGroupNode(const QString& name, amuse::ObjToken<amuse::SFXGroupIndex> index) : INode(name), m_index(index) {}
SoundGroupNode(amuse::GroupId id, amuse::ObjToken<amuse::SFXGroupIndex> index) SoundGroupNode(amuse::GroupId id, amuse::ObjToken<amuse::SFXGroupIndex> index)
: INode(amuse::GroupId::CurNameDB->resolveNameFromId(id).data()), m_id(id), m_index(index) {} : INode(QString::fromUtf8(amuse::GroupId::CurNameDB->resolveNameFromId(id).data())), m_id(id), m_index(index) {}
static QIcon Icon; static QIcon Icon;
Type type() const override { return Type::SoundGroup; } Type type() const override { return Type::SoundGroup; }
@ -336,7 +336,7 @@ public:
amuse::ObjToken<T> m_obj; amuse::ObjToken<T> m_obj;
PoolObjectNode(const QString& name, amuse::ObjToken<T> obj) : BasePoolObjectNode(name), m_obj(obj) {} PoolObjectNode(const QString& name, amuse::ObjToken<T> obj) : BasePoolObjectNode(name), m_obj(obj) {}
PoolObjectNode(ID id, amuse::ObjToken<T> obj) PoolObjectNode(ID id, amuse::ObjToken<T> obj)
: BasePoolObjectNode(id, ID::CurNameDB->resolveNameFromId(id).data()), m_obj(obj) {} : BasePoolObjectNode(id, QString::fromUtf8(ID::CurNameDB->resolveNameFromId(id).data())), m_obj(obj) {}
Type type() const override { return TP; } Type type() const override { return TP; }
AmuseItemEditFlags editFlags() const override { return TP == INode::Type::Sample ? AmuseItemNoCut : AmuseItemAll; } AmuseItemEditFlags editFlags() const override { return TP == INode::Type::Sample ? AmuseItemNoCut : AmuseItemAll; }

View File

@ -839,7 +839,7 @@ QVariant SetupListModel::data(const QModelIndex& index, int role) const {
if (role == Qt::ForegroundRole) if (role == Qt::ForegroundRole)
return QVariant(); return QVariant();
g_MainWindow->projectModel()->setIdDatabases(m_node.get()); g_MainWindow->projectModel()->setIdDatabases(m_node.get());
return amuse::SongId::CurNameDB->resolveNameFromId(entry->first.id).data(); return QString::fromUtf8(amuse::SongId::CurNameDB->resolveNameFromId(entry->first.id).data());
} else if (index.column() == 1) { } else if (index.column() == 1) {
QString songPath = g_MainWindow->projectModel()->getMIDIPathOfSong(entry.m_it->first); QString songPath = g_MainWindow->projectModel()->getMIDIPathOfSong(entry.m_it->first);
if (songPath.isEmpty()) { if (songPath.isEmpty()) {

View File

@ -232,7 +232,7 @@ QVariant SFXModel::data(const QModelIndex& index, int role) const {
switch (index.column()) { switch (index.column()) {
case 0: { case 0: {
g_MainWindow->projectModel()->setIdDatabases(m_node.get()); g_MainWindow->projectModel()->setIdDatabases(m_node.get());
return amuse::SFXId::CurNameDB->resolveNameFromId(entry->first.id).data(); return QString::fromUtf8(amuse::SFXId::CurNameDB->resolveNameFromId(entry->first.id).data());
} }
case 1: { case 1: {
ProjectModel::GroupNode* group = g_MainWindow->projectModel()->getGroupNode(m_node.get()); ProjectModel::GroupNode* group = g_MainWindow->projectModel()->getGroupNode(m_node.get());

View File

@ -60,12 +60,12 @@ int main(int argc, char* argv[]) {
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif #endif
QApplication::setStyle(new ColoredTabBarStyle(QStyleFactory::create("Fusion"))); QApplication::setStyle(new ColoredTabBarStyle(QStyleFactory::create(QStringLiteral("Fusion"))));
QApplication a(argc, argv); QApplication a(argc, argv);
QApplication::setWindowIcon(MakeAppIcon()); QApplication::setWindowIcon(MakeAppIcon());
a.setOrganizationName("AxioDL"); a.setOrganizationName(QStringLiteral("AxioDL"));
a.setApplicationName("Amuse"); a.setApplicationName(QStringLiteral("Amuse"));
QPalette darkPalette; QPalette darkPalette;
darkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); darkPalette.setColor(QPalette::Window, QColor(53, 53, 53));
@ -102,8 +102,9 @@ int main(int argc, char* argv[]) {
Q_INIT_RESOURCE(translation_res); Q_INIT_RESOURCE(translation_res);
QTranslator translator; QTranslator translator;
if (translator.load(QLocale(), QLatin1String("lang"), QLatin1String("_"), QLatin1String(":/translations"))) if (translator.load(QLocale(), QStringLiteral("lang"), QStringLiteral("_"), QStringLiteral(":/translations"))) {
a.installTranslator(&translator); a.installTranslator(&translator);
}
MainWindow w; MainWindow w;
g_MainWindow = &w; g_MainWindow = &w;