summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_count.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sinksh/syntax_modules/sink_count.cpp')
-rw-r--r--sinksh/syntax_modules/sink_count.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/sinksh/syntax_modules/sink_count.cpp b/sinksh/syntax_modules/sink_count.cpp
index 84bbabd..5ab9ca5 100644
--- a/sinksh/syntax_modules/sink_count.cpp
+++ b/sinksh/syntax_modules/sink_count.cpp
@@ -41,20 +41,14 @@ namespace SinkCount
41 41
42bool count(const QStringList &args, State &state) 42bool count(const QStringList &args, State &state)
43{ 43{
44 auto resources = args;
45 auto type = !resources.isEmpty() ? resources.takeFirst() : QString();
46
47 if (!type.isEmpty() && !SinkshUtils::isValidStoreType(type)) {
48 state.printError(QObject::tr("Unknown type: %1").arg(type));
49 return false;
50 }
51
52 Sink::Query query; 44 Sink::Query query;
53 for (const auto &res : resources) { 45 query.setId("count");
54 query.resourceFilter(res.toLatin1()); 46 if (!SinkshUtils::applyFilter(query, args)) {
47 state.printError(QObject::tr("Options: $type $filter"));
48 return false;
55 } 49 }
56 50
57 auto model = SinkshUtils::loadModel(type, query); 51 auto model = SinkshUtils::loadModel(query.type(), query);
58 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { 52 QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, state](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) {
59 if (roles.contains(Sink::Store::ChildrenFetchedRole)) { 53 if (roles.contains(Sink::Store::ChildrenFetchedRole)) {
60 state.printLine(QObject::tr("Counted results %1").arg(model->rowCount(QModelIndex()))); 54 state.printLine(QObject::tr("Counted results %1").arg(model->rowCount(QModelIndex())));