Added ParameterAction class for QActions acting on files.

Reduce inconsistencies in tr()-Strings provided for
QActions that act on a current <something> (mostly files) by
introducing a ParameterAction class that takes the tr()-Strings
at construction time and provides a setParameter(QString) slot,
allows for setting that parameter or an empty string, which
will cause the displayed text to be updated.
This commit is contained in:
Friedemann Kleint
2009-05-15 15:41:00 +02:00
parent 9106c72116
commit 81d69641ab
11 changed files with 261 additions and 128 deletions

View File

@@ -0,0 +1,61 @@
#include "parameteraction.h"
namespace Core {
namespace Utils {
ParameterAction::ParameterAction(const QString &emptyText,
const QString &parameterText,
EnablingMode mode,
QObject* parent) :
QAction(emptyText, parent),
m_emptyText(emptyText),
m_parameterText(parameterText),
m_enablingMode(mode)
{
}
QString ParameterAction::emptyText() const
{
return m_emptyText;
}
void ParameterAction::setEmptyText(const QString &t)
{
m_emptyText = t;
}
QString ParameterAction::parameterText() const
{
return m_parameterText;
}
void ParameterAction::setParameterText(const QString &t)
{
m_parameterText = t;
}
ParameterAction::EnablingMode ParameterAction::enablingMode() const
{
return m_enablingMode;
}
void ParameterAction::setEnablingMode(EnablingMode m)
{
m_enablingMode = m;
}
void ParameterAction::setParameter(const QString &p)
{
const bool enabled = !p.isEmpty();
if (enabled) {
setText(m_parameterText.arg(p));
} else {
setText(m_emptyText);
}
if (m_enablingMode == EnabledWithParameter)
setEnabled(enabled);
}
}
}