summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_count.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-01-07 17:56:30 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-01-07 17:56:30 +0100
commit35a3afc591c85999de856c21dbb493e341951d91 (patch)
treef46b6a8c22e5bdb283148e48e0391c2691bcc343 /sinksh/syntax_modules/sink_count.cpp
parent470203f1c09fa1811ae2859520c168901d5fa6cd (diff)
downloadsink-35a3afc591c85999de856c21dbb493e341951d91.tar.gz
sink-35a3afc591c85999de856c21dbb493e341951d91.zip
Share query syntax
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())));