Replace one-use methods with lambdas
This commit is contained in:
parent
1ba4f6be4d
commit
eff7552d07
@ -521,25 +521,27 @@ UserActions Model::userActions() const
|
|||||||
if (!root_)
|
if (!root_)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
UserActions result;
|
UserActions actions;
|
||||||
fillUserActions(result, *root_);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Model::fillUserActions(UserActions &actions, Component &component) const
|
const auto visitor = [&actions](const Component &component, auto v) -> void {
|
||||||
{
|
if (!component.files.empty()) {
|
||||||
if (!component.files.empty()) {
|
if (component.action == Action::NoAction)
|
||||||
if (component.action == Action::NoAction)
|
return;
|
||||||
|
|
||||||
|
for (auto &file : component.files)
|
||||||
|
actions.emplace(component.action, file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &file : component.files) actions.emplace(component.action, file);
|
if (!component.children.empty()) {
|
||||||
return;
|
for (auto &child : component.children) v(*child, v);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!component.children.empty()) {
|
visitor(*root_, visitor);
|
||||||
for (auto &child : component.children) fillUserActions(actions, *child);
|
|
||||||
return;
|
return actions;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::updateStates()
|
void Model::updateStates()
|
||||||
@ -548,14 +550,36 @@ void Model::updateStates()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
updateState(*root_);
|
updateState(*root_);
|
||||||
emitColumnsChanged(QModelIndex());
|
|
||||||
|
const auto visitor = [this](const QModelIndex &parent, auto v) -> void {
|
||||||
|
const auto count = rowCount(parent);
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
emit dataChanged(index(0, int(Column::State), parent),
|
||||||
|
index(count - 1, int(Column::Action), parent),
|
||||||
|
{Qt::DisplayRole, Qt::EditRole});
|
||||||
|
|
||||||
|
for (auto i = 0; i < count; ++i) v(index(0, 0, parent), v);
|
||||||
|
};
|
||||||
|
|
||||||
|
visitor(QModelIndex(), visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Model::hasUpdates() const
|
bool Model::hasUpdates() const
|
||||||
{
|
{
|
||||||
if (!root_)
|
if (!root_)
|
||||||
return false;
|
return false;
|
||||||
return hasUpdates(*root_);
|
|
||||||
|
const auto visitor = [](const Component &component, auto v) -> bool {
|
||||||
|
for (const auto &i : component.children) {
|
||||||
|
if (i->state == State::UpdateAvailable || v(*i, v))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
return visitor(*root_, visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::updateProgress(const QUrl &url, int progress)
|
void Model::updateProgress(const QUrl &url, int progress)
|
||||||
@ -614,15 +638,6 @@ void Model::resetActions()
|
|||||||
visitor(*root_, visitor);
|
visitor(*root_, visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Model::hasUpdates(const Model::Component &component) const
|
|
||||||
{
|
|
||||||
for (const auto &i : component.children) {
|
|
||||||
if (i->state == State::UpdateAvailable || hasUpdates(*i))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Model::updateState(Model::Component &component)
|
void Model::updateState(Model::Component &component)
|
||||||
{
|
{
|
||||||
if (!component.files.empty()) {
|
if (!component.files.empty()) {
|
||||||
@ -687,19 +702,6 @@ QString Model::expanded(const QString &source) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::emitColumnsChanged(const QModelIndex &parent)
|
|
||||||
{
|
|
||||||
const auto count = rowCount(parent);
|
|
||||||
if (count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
emit dataChanged(index(0, int(Column::State), parent),
|
|
||||||
index(count - 1, int(Column::Action), parent),
|
|
||||||
{Qt::DisplayRole, Qt::EditRole});
|
|
||||||
|
|
||||||
for (auto i = 0; i < count; ++i) emitColumnsChanged(index(0, 0, parent));
|
|
||||||
}
|
|
||||||
|
|
||||||
Model::Component *Model::toComponent(const QModelIndex &index) const
|
Model::Component *Model::toComponent(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
return static_cast<Component *>(index.internalPointer());
|
return static_cast<Component *>(index.internalPointer());
|
||||||
|
@ -93,11 +93,8 @@ private:
|
|||||||
std::unique_ptr<Component> parse(const QJsonObject& json) const;
|
std::unique_ptr<Component> parse(const QJsonObject& json) const;
|
||||||
void updateProgress(Component& component, const QUrl& url, int progress);
|
void updateProgress(Component& component, const QUrl& url, int progress);
|
||||||
void updateState(Component& component);
|
void updateState(Component& component);
|
||||||
bool hasUpdates(const Component& component) const;
|
|
||||||
void fillUserActions(UserActions& actions, Component& component) const;
|
|
||||||
State currentState(const File& file) const;
|
State currentState(const File& file) const;
|
||||||
QString expanded(const QString& source) const;
|
QString expanded(const QString& source) const;
|
||||||
void emitColumnsChanged(const QModelIndex& parent);
|
|
||||||
Component* toComponent(const QModelIndex& index) const;
|
Component* toComponent(const QModelIndex& index) const;
|
||||||
QModelIndex toIndex(const Component& component, int column) const;
|
QModelIndex toIndex(const Component& component, int column) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user