Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix crash when we create a new rc file (language is empty => assert) #203

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/API/knut/rcdocument.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Knut
|[ToolBar](../knut/toolbar.md) |**[action](#action)**(string id)|
|array<[Action](../knut/action.md)> |**[actionsFromMenu](#actionsFromMenu)**(string menuId)|
|array<[Action](../knut/action.md)> |**[actionsFromToolbar](#actionsFromToolbar)**(string toolBarId)|
|string |**[captionDialogForLanguage](#captionDialogForLanguage)**(string language, string dialogId)|
|void |**[convertActions](#convertActions)**(int flags)|
||**[convertAssets](#convertAssets)**(int flags)|
|string |**[convertLanguageToCode](#convertLanguageToCode)**(string language)|
Expand Down Expand Up @@ -126,6 +127,10 @@ Returns all actions used in the menu `menuId`.

Returns all actions used in the toolbar `toolBarId`.

#### <a name="captionDialogForLanguage"></a>string **captionDialogForLanguage**(string language, string dialogId)

Returns the string with `id` for the given `language`.

#### <a name="convertActions"></a>void **convertActions**(int flags)


Expand Down
18 changes: 18 additions & 0 deletions src/core/rcdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,24 @@ QString RcDocument::stringForDialogAndLanguage(const QString &language, const QS
}
}

/*!
* \qmlmethod string RcDocument::captionDialogForLanguage(string language, string dialogId)
* Returns the string with `id` for the given `language`.
*/
QString RcDocument::captionDialogForLanguage(const QString &language, const QString &dialogId) const
{
LOG(language, dialogId);

if (m_rcFile.isValid && m_rcFile.data.contains(language)) {
const RcCore::Data data = const_cast<RcCore::RcFile *>(&m_rcFile)->data[language];
const auto dialog = data.dialog(dialogId);
return dialog->caption;
} else {
spdlog::warn("{}: language {} does not exist in the rc file.", FUNCTION_NAME, language);
return {};
}
}

/*!
* \qmlmethod string RcDocument::stringForDialog(string dialogId, string id)
* Returns the string with `id` for the given `dialogid`.
Expand Down
2 changes: 2 additions & 0 deletions src/core/rcdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class RcDocument : public Document

const RcCore::RcFile &file() const;

Q_INVOKABLE QString captionDialogForLanguage(const QString &language, const QString &dialogId) const;

public slots:
void convertAssets(int flags = DEFAULT_VALUE(ConversionFlag, RcAssetFlags));
void convertActions(int flags = DEFAULT_VALUE(ConversionFlags, RcAssetFlags));
Expand Down
4 changes: 3 additions & 1 deletion src/rcui/datamodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ DataModel::DataModel(const RcCore::RcFile &rcFile, QString language, QObject *pa
, m_rcFile(rcFile)
, m_language(std::move(language))
{
Q_ASSERT(m_rcFile.data.contains(m_language));
if (!m_language.isEmpty()) {
Q_ASSERT(m_rcFile.data.contains(m_language));
}
}

QModelIndex DataModel::index(int row, int column, const QModelIndex &parent) const
Expand Down
Loading