23 #include "filealias.h" 27 FileAlias::FileAlias()
29 d.matchType = FileAlias::LeftToRight;
32 FileAlias::FileAlias(
const QString &name)
34 d.matchType = FileAlias::LeftToRight;
40 if (!d.aliases.contains(val, Qt::CaseInsensitive))
48 for (
const QString &element : val)
54 const QStringList &FileAlias::aliases()
const 59 void FileAlias::setAliases(
const QStringList &val)
64 FileAlias FileAlias::deserializeQVariant(
const QVariant &var)
66 QVariantMap m = var.toMap();
68 result.setAliases(m[
"aliases"].toStringList());
69 result.setMatchType(deserializeMatchType(m[
"matchType"]));
70 result.setName(m[
"name"].toString());
74 QVariant FileAlias::serializeQVariant()
const 77 m[
"aliases"] = aliases();
78 m[
"matchType"] = serializeMatchType(matchType());
83 FileAlias::MatchType FileAlias::deserializeMatchType(
const QVariant &variant)
85 QString val = variant.toString();
86 if (val ==
"LeftToRight")
88 else if (val ==
"AllEqual")
94 QVariant FileAlias::serializeMatchType(MatchType matchType)
99 assert(
false &&
"don't know how to serialize this FileAlias::MatchType");
101 return "LeftToRight";
110 result.setName(
"doom.wad");
112 aliases <<
"freedomu.wad" <<
"freedoom1.wad";
113 result.setAliases(aliases);
114 result.setMatchType(LeftToRight);
118 QList<FileAlias> FileAlias::freeDoom2Aliases()
124 bases <<
"doom2.wad" <<
"tnt.wad" <<
"plutonia.wad";
125 QList<FileAlias> result;
126 for (
const QString &base : bases)
130 alias.setMatchType(LeftToRight);
132 aliases <<
"freedoom.wad" <<
"freedoom2.wad";
133 alias.setAliases(aliases);
141 return d.name.compare(otherName, Qt::CaseInsensitive) == 0;
146 return !name().isEmpty() && !aliases().isEmpty();
149 FileAlias::MatchType FileAlias::matchType()
const 154 void FileAlias::setMatchType(MatchType matchType)
156 d.matchType = matchType;
159 const QString &FileAlias::name()
const 164 void FileAlias::setName(
const QString &val)
171 QList<FileAlias> result;
172 result << freeDoom1Aliases();
173 for (
const FileAlias &alias : freeDoom2Aliases())
182 QStringList allAliases;
183 for (
const FileAlias &candidate : candidates)
185 switch (candidate.matchType())
187 case FileAlias::LeftToRight:
188 if (candidate.name().compare(name, Qt::CaseInsensitive) == 0)
189 allAliases << candidate.aliases();
191 case FileAlias::AllEqual:
193 QStringList allValidNames;
194 allValidNames << candidate.name();
195 allValidNames << candidate.aliases();
196 if (allValidNames.contains(name, Qt::CaseInsensitive))
197 allAliases << allValidNames;
201 assert(
false &&
"unknown FileAlias::MatchType");
206 allAliases.removeDuplicates();
207 allAliases.removeAll(name);
211 QList<FileAlias> FileAliasList::mergeDuplicates(
const QList<FileAlias> &input)
213 QList<FileAlias> result;
217 for (
auto &aliasOnList : result)
219 if (aliasOnList.isSameName(alias.name()) && aliasOnList.matchType() == alias.matchType())
221 aliasOnList.addAliases(alias.aliases());
bool isValid() const
Valid FileAlias has a name and at least one alias.
void addAliases(const QStringList &val)
Will ensure unique values.
static QList< FileAlias > standardWadAliases()
Standard/default aliases for configuration init.
bool isSameName(const QString &otherName) const
Compares passed string to local name and checks if they're same.
void addAlias(const QString &val)
Will ensure unique values.
static QStringList aliases(const QList< FileAlias > &candidates, const QString &name)