mirror of
https://github.com/tnodir/fort
synced 2024-11-15 01:47:47 +00:00
UI: Zones: Translate Sources
This commit is contained in:
parent
20ede18068
commit
bed8556894
@ -35,11 +35,12 @@ void ZoneEditDialog::initialize(const ZoneRow &zoneRow)
|
||||
|
||||
retranslateUi();
|
||||
|
||||
const QString sourceCode = isEmpty() ? ZoneSourceWrapper::textSourceCode() : zoneRow.sourceCode;
|
||||
const QString sourceCode =
|
||||
isEmpty() ? ZoneSourceWrapper::defaultSourceCode() : zoneRow.sourceCode;
|
||||
const ZoneSourceWrapper zoneSource(zoneListModel()->zoneSourceByCode(sourceCode));
|
||||
|
||||
m_editName->setStartText(zoneRow.zoneName);
|
||||
m_comboSources->setCurrentIndex(zoneSource.index());
|
||||
m_comboSources->setCurrentIndex(zoneSource.id());
|
||||
m_cbEnabled->setChecked(zoneRow.enabled);
|
||||
|
||||
m_cbCustomUrl->setChecked(zoneRow.customUrl);
|
||||
|
@ -114,7 +114,7 @@ QVariant ZoneListModel::dataDisplay(const QModelIndex &index) const
|
||||
return QString("%1) %2").arg(QString::number(m_zoneRow.zoneId), zoneRow.zoneName);
|
||||
case 1: {
|
||||
const auto zoneSource = ZoneSourceWrapper(zoneSourceByCode(zoneRow.sourceCode));
|
||||
return zoneSource.title();
|
||||
return zoneSourceTitleById(zoneSource.id());
|
||||
}
|
||||
case 2:
|
||||
return zoneRow.addressCount;
|
||||
@ -263,8 +263,25 @@ void ZoneListModel::setupZoneSources()
|
||||
int index = 0;
|
||||
for (const auto &sourceVar : zoneSources) {
|
||||
ZoneSourceWrapper zoneSource(sourceVar);
|
||||
zoneSource.setIndex(index++);
|
||||
zoneSource.setId(index++);
|
||||
m_zoneSourcesMap.insert(zoneSource.code(), zoneSource.map());
|
||||
m_zoneSources.append(zoneSource.map());
|
||||
}
|
||||
}
|
||||
|
||||
QString ZoneListModel::zoneSourceTitleById(const int sourceId)
|
||||
{
|
||||
static const char *const sourceTitles[] = {
|
||||
QT_TR_NOOP("Addresses from Inline Text"),
|
||||
QT_TR_NOOP("Addresses from Local File"),
|
||||
QT_TR_NOOP("WindowsSpyBlocker"),
|
||||
QT_TR_NOOP("FireHOL Level-1"),
|
||||
QT_TR_NOOP("TAS-IX Addresses"),
|
||||
};
|
||||
|
||||
if (sourceId >= 0 && sourceId < std::size(sourceTitles)) {
|
||||
return tr(sourceTitles[sourceId]);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -44,6 +44,8 @@ public:
|
||||
QVariant zoneSourceByCode(const QString &sourceCode) const;
|
||||
const QVariantList &zoneSources() const { return m_zoneSources; }
|
||||
|
||||
static QString zoneSourceTitleById(const int sourceId);
|
||||
|
||||
protected:
|
||||
Qt::ItemFlags flagIsUserCheckable(const QModelIndex &index) const override;
|
||||
|
||||
|
@ -1,15 +1,17 @@
|
||||
#include "zonesourcewrapper.h"
|
||||
|
||||
#include <QHash>
|
||||
|
||||
ZoneSourceWrapper::ZoneSourceWrapper(const QVariant &var) : MapWrapper(var) { }
|
||||
|
||||
int ZoneSourceWrapper::index() const
|
||||
int ZoneSourceWrapper::id() const
|
||||
{
|
||||
return valueInt("index");
|
||||
return valueInt("id");
|
||||
}
|
||||
|
||||
void ZoneSourceWrapper::setIndex(int index)
|
||||
void ZoneSourceWrapper::setId(int id)
|
||||
{
|
||||
setValue("index", index);
|
||||
setValue("id", id);
|
||||
}
|
||||
|
||||
QString ZoneSourceWrapper::code() const
|
||||
@ -39,10 +41,10 @@ QString ZoneSourceWrapper::formData() const
|
||||
|
||||
bool ZoneSourceWrapper::isTextInline() const
|
||||
{
|
||||
return code() == textSourceCode();
|
||||
return code() == defaultSourceCode();
|
||||
}
|
||||
|
||||
QString ZoneSourceWrapper::textSourceCode()
|
||||
QString ZoneSourceWrapper::defaultSourceCode()
|
||||
{
|
||||
return "text";
|
||||
}
|
||||
|
@ -6,10 +6,18 @@
|
||||
class ZoneSourceWrapper : public MapWrapper
|
||||
{
|
||||
public:
|
||||
enum SourceId {
|
||||
SourceText = 0,
|
||||
SourceFile,
|
||||
SourceWinSpyBlock,
|
||||
SourceFireHolLevel1,
|
||||
SourceTasix,
|
||||
};
|
||||
|
||||
explicit ZoneSourceWrapper(const QVariant &var = QVariant());
|
||||
|
||||
int index() const;
|
||||
void setIndex(int index);
|
||||
int id() const;
|
||||
void setId(int id);
|
||||
|
||||
QString code() const;
|
||||
QString title() const;
|
||||
@ -19,7 +27,7 @@ public:
|
||||
|
||||
bool isTextInline() const;
|
||||
|
||||
static QString textSourceCode();
|
||||
static QString defaultSourceCode();
|
||||
};
|
||||
|
||||
#endif // ZONESOURCEWRAPPER_H
|
||||
|
Loading…
Reference in New Issue
Block a user