graphic_breakpoints: Correct translation of strings in BreakpointModel's data() function

tr() will not function properly on static/global data like this, as the
object is only ever constructed once, so the strings won't translate if
the language is changed without restarting the program, which is
undesirable. Instead we can just turn the map into a plain old function
that maps the values to their equivalent strings. This is also lessens
the memory allocated, since it's only allocating memory for the strings
themselves, and not an encompassing map as well.
This commit is contained in:
fearlessTobi 2018-10-27 00:33:31 +02:00
parent f3ee5feb02
commit 494d86d083
2 changed files with 27 additions and 16 deletions

View file

@ -30,23 +30,8 @@ QVariant BreakPointModel::data(const QModelIndex& index, int role) const {
switch (role) { switch (role) {
case Qt::DisplayRole: { case Qt::DisplayRole: {
if (index.column() == 0) { if (index.column() == 0) {
static const std::map<Pica::DebugContext::Event, QString> map = { return DebugContextEventToString(event);
{Pica::DebugContext::Event::PicaCommandLoaded, tr("Pica command loaded")},
{Pica::DebugContext::Event::PicaCommandProcessed, tr("Pica command processed")},
{Pica::DebugContext::Event::IncomingPrimitiveBatch, tr("Incoming primitive batch")},
{Pica::DebugContext::Event::FinishedPrimitiveBatch, tr("Finished primitive batch")},
{Pica::DebugContext::Event::VertexShaderInvocation, tr("Vertex shader invocation")},
{Pica::DebugContext::Event::IncomingDisplayTransfer,
tr("Incoming display transfer")},
{Pica::DebugContext::Event::GSPCommandProcessed, tr("GSP command processed")},
{Pica::DebugContext::Event::BufferSwapped, tr("Buffers swapped")},
};
DEBUG_ASSERT(map.size() ==
static_cast<std::size_t>(Pica::DebugContext::Event::NumEvents));
return (map.find(event) != map.end()) ? map.at(event) : QString();
} }
break; break;
} }
@ -128,6 +113,30 @@ void BreakPointModel::OnResumed() {
active_breakpoint = context->active_breakpoint; active_breakpoint = context->active_breakpoint;
} }
QString BreakPointModel::DebugContextEventToString(Pica::DebugContext::Event event) {
switch (event) {
case Pica::DebugContext::Event::PicaCommandLoaded:
return tr("Pica command loaded");
case Pica::DebugContext::Event::PicaCommandProcessed:
return tr("Pica command processed");
case Pica::DebugContext::Event::IncomingPrimitiveBatch:
return tr("Incoming primitive batch");
case Pica::DebugContext::Event::FinishedPrimitiveBatch:
return tr("Finished primitive batch");
case Pica::DebugContext::Event::VertexShaderInvocation:
return tr("Vertex shader invocation");
case Pica::DebugContext::Event::IncomingDisplayTransfer:
return tr("Incoming display transfer");
case Pica::DebugContext::Event::GSPCommandProcessed:
return tr("GSP command processed");
case Pica::DebugContext::Event::BufferSwapped:
return tr("Buffers swapped");
case Pica::DebugContext::Event::NumEvents:
break;
}
return tr("Unknown debug context event");
}
GraphicsBreakPointsWidget::GraphicsBreakPointsWidget( GraphicsBreakPointsWidget::GraphicsBreakPointsWidget(
std::shared_ptr<Pica::DebugContext> debug_context, QWidget* parent) std::shared_ptr<Pica::DebugContext> debug_context, QWidget* parent)
: QDockWidget(tr("Pica Breakpoints"), parent), Pica::DebugContext::BreakPointObserver( : QDockWidget(tr("Pica Breakpoints"), parent), Pica::DebugContext::BreakPointObserver(

View file

@ -29,6 +29,8 @@ public:
void OnResumed(); void OnResumed();
private: private:
static QString DebugContextEventToString(Pica::DebugContext::Event event);
std::weak_ptr<Pica::DebugContext> context_weak; std::weak_ptr<Pica::DebugContext> context_weak;
bool at_breakpoint; bool at_breakpoint;
Pica::DebugContext::Event active_breakpoint; Pica::DebugContext::Event active_breakpoint;