NOISSUE implement recommended versions using the new JSON format
This commit is contained in:
parent
f565798650
commit
643d74f66c
@ -30,7 +30,7 @@ BaseVersionPtr BaseVersionList::findVersion(const QString &descriptor)
|
||||
return BaseVersionPtr();
|
||||
}
|
||||
|
||||
BaseVersionPtr BaseVersionList::getLatestStable() const
|
||||
BaseVersionPtr BaseVersionList::getRecommended() const
|
||||
{
|
||||
if (count() <= 0)
|
||||
return BaseVersionPtr();
|
||||
@ -38,11 +38,6 @@ BaseVersionPtr BaseVersionList::getLatestStable() const
|
||||
return at(0);
|
||||
}
|
||||
|
||||
BaseVersionPtr BaseVersionList::getRecommended() const
|
||||
{
|
||||
return getLatestStable();
|
||||
}
|
||||
|
||||
QVariant BaseVersionList::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
|
@ -93,11 +93,6 @@ public:
|
||||
*/
|
||||
virtual BaseVersionPtr findVersion(const QString &descriptor);
|
||||
|
||||
/*!
|
||||
* \brief Gets the latest stable version from this list
|
||||
*/
|
||||
virtual BaseVersionPtr getLatestStable() const;
|
||||
|
||||
/*!
|
||||
* \brief Gets the recommended version from this list
|
||||
* If the list doesn't support recommended versions, this works exactly as getLatestStable
|
||||
|
@ -52,6 +52,7 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
|
||||
version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000);
|
||||
version->setType(ensureString(obj, "type", QString()));
|
||||
version->setParentUid(ensureString(obj, "parentUid", QString()));
|
||||
version->setRecommended(ensureBoolean(obj, "recommended", false));
|
||||
if(obj.contains("requires"))
|
||||
{
|
||||
QHash<QString, QString> requires;
|
||||
@ -87,7 +88,9 @@ static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj)
|
||||
versions.reserve(versionsRaw.size());
|
||||
std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [uid](const QJsonObject &vObj)
|
||||
{
|
||||
return parseCommonVersion(uid, vObj);
|
||||
auto version = parseCommonVersion(uid, vObj);
|
||||
version->setProvidesRecommendations();
|
||||
return version;
|
||||
});
|
||||
|
||||
VersionListPtr list = std::make_shared<VersionList>(uid);
|
||||
|
@ -53,6 +53,13 @@ void Meta::Version::parse(const QJsonObject& obj)
|
||||
void Meta::Version::merge(const std::shared_ptr<BaseEntity> &other)
|
||||
{
|
||||
VersionPtr version = std::dynamic_pointer_cast<Version>(other);
|
||||
if(version->m_providesRecommendations)
|
||||
{
|
||||
if(m_recommended != version->m_recommended)
|
||||
{
|
||||
setRecommended(version->m_recommended);
|
||||
}
|
||||
}
|
||||
if (m_type != version->m_type)
|
||||
{
|
||||
setType(version->m_type);
|
||||
@ -107,3 +114,12 @@ void Meta::Version::setData(const VersionFilePtr &data)
|
||||
m_data = data;
|
||||
}
|
||||
|
||||
void Meta::Version::setProvidesRecommendations()
|
||||
{
|
||||
m_providesRecommendations = true;
|
||||
}
|
||||
|
||||
void Meta::Version::setRecommended(bool recommended)
|
||||
{
|
||||
m_recommended = recommended;
|
||||
}
|
||||
|
@ -72,6 +72,10 @@ public: /* con/des */
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
bool isRecommended() const
|
||||
{
|
||||
return m_recommended;
|
||||
}
|
||||
|
||||
void merge(const std::shared_ptr<BaseEntity> &other) override;
|
||||
void parse(const QJsonObject &obj) override;
|
||||
@ -83,6 +87,8 @@ public: // for usage by format parsers only
|
||||
void setType(const QString &type);
|
||||
void setTime(const qint64 time);
|
||||
void setRequires(const QHash<QString, QString> &requires);
|
||||
void setRecommended(bool recommended);
|
||||
void setProvidesRecommendations();
|
||||
void setData(const VersionFilePtr &data);
|
||||
|
||||
signals:
|
||||
@ -91,6 +97,8 @@ signals:
|
||||
void requiresChanged();
|
||||
|
||||
private:
|
||||
bool m_providesRecommendations = false;
|
||||
bool m_recommended = false;
|
||||
QString m_name;
|
||||
QString m_uid;
|
||||
QString m_parentUid;
|
||||
|
@ -94,8 +94,9 @@ QVariant VersionList::data(const QModelIndex &index, int role) const
|
||||
case RequiresRole: return QVariant::fromValue(version->requires());
|
||||
case SortRole: return version->rawTime();
|
||||
case VersionPtrRole: return QVariant::fromValue(version);
|
||||
case RecommendedRole: return version == getRecommended();
|
||||
case LatestRole: return version == getLatestStable();
|
||||
case RecommendedRole: return version->isRecommended();
|
||||
// FIXME: this should be determined in whatever view/proxy is used...
|
||||
// case LatestRole: return version == getLatestStable();
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
@ -158,7 +159,6 @@ void VersionList::setVersions(const QVector<VersionPtr> &versions)
|
||||
setupAddedVersion(i, m_versions.at(i));
|
||||
}
|
||||
|
||||
m_latest = m_versions.isEmpty() ? nullptr : m_versions.first();
|
||||
auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const VersionPtr &ptr) { return ptr->type() == "release"; });
|
||||
m_recommended = recommendedIt == m_versions.constEnd() ? nullptr : *recommendedIt;
|
||||
endResetModel();
|
||||
@ -202,11 +202,6 @@ void VersionList::merge(const BaseEntity::Ptr &other)
|
||||
m_lookup.insert(version->uid(), version);
|
||||
endInsertRows();
|
||||
|
||||
if (!m_latest || version->rawTime() > m_latest->rawTime())
|
||||
{
|
||||
m_latest = version;
|
||||
emit dataChanged(index(0), index(m_versions.size() - 1), QVector<int>() << LatestRole);
|
||||
}
|
||||
if (!m_recommended || (version->type() == "release" && version->rawTime() > m_recommended->rawTime()))
|
||||
{
|
||||
m_recommended = version;
|
||||
@ -224,10 +219,6 @@ void VersionList::setupAddedVersion(const int row, const VersionPtr &version)
|
||||
connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TypeRole); });
|
||||
}
|
||||
|
||||
BaseVersionPtr VersionList::getLatestStable() const
|
||||
{
|
||||
return m_latest;
|
||||
}
|
||||
BaseVersionPtr VersionList::getRecommended() const
|
||||
{
|
||||
return m_recommended;
|
||||
|
@ -47,7 +47,6 @@ public:
|
||||
int count() const override;
|
||||
void sortVersions() override;
|
||||
|
||||
BaseVersionPtr getLatestStable() const override;
|
||||
BaseVersionPtr getRecommended() const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
@ -100,7 +99,6 @@ private:
|
||||
QString m_name;
|
||||
|
||||
VersionPtr m_recommended;
|
||||
VersionPtr m_latest;
|
||||
|
||||
void setupAddedVersion(const int row, const VersionPtr &version);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user