MauiKit Controls

mauilist.cpp
1/*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2019 camilo <chiguitar@unal.edu.co>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "mauilist.h"
20#include <QDebug>
21
23 : QObject(parent)
24{
25}
26
27int MauiList::getCount() const
28{
29 return this->items().count();
30}
31
32QVariantMap MauiList::get(const int &index) const
33{
34 return FMH::toMap(this->getItem(index));
35}
36
37FMH::MODEL MauiList::getItem(const int &index) const
38{
39 if (index >= 0 && this->getCount() > 0 && index < this->getCount()) {
40 return this->items()[index];
41 }
42
43 return FMH::MODEL();
44}
45
46bool MauiList::exists(const FMH::MODEL_KEY &key, const QString &value) const
47{
48 return this->indexOf(key, value) >= 0;
49}
50
51int MauiList::indexOf(const FMH::MODEL_KEY &key, const QString &value) const
52{
53 const auto it = std::find_if(this->items().constBegin(), this->items().constEnd(), [&](const FMH::MODEL &item) -> bool {
54 return item[key] == value;
55 });
56
57 if (it != this->items().constEnd())
58 return (std::distance(this->items().constBegin(), it));
59 else
60 return -1;
61}
MauiList(QObject *parent=nullptr)
Default constructor.
Definition mauilist.cpp:22
FMH::MODEL getItem(const int &index) const
Request to get an item in the list, the item is represented as a FMH::MODEL key pair value.
Definition mauilist.cpp:37
virtual const FMH::MODEL_LIST & items() const =0
The modeled data represented by a FMH::MODEL_LIST.
QVariantMap get(const int &index) const
Request to get an item in the list, the item is represented as a QVariantMap for easy consumption wit...
Definition mauilist.cpp:32
int indexOf(const FMH::MODEL_KEY &key, const QString &value) const
The index number of an item in the list of a given key-par value.
Definition mauilist.cpp:51
bool exists(const FMH::MODEL_KEY &key, const QString &value) const
Whether an item with a given key-par value exists in the list.
Definition mauilist.cpp:46
QHash< MODEL_KEY, QString > MODEL
The key-value pair model structure, where the values are strings.
Definition fmh.h:532
MODEL_KEY
The MODEL_KEY enum values.
Definition fmh.h:64
const QVariantMap toMap(const FMH::MODEL &model)
Converts a FMH::MODEL object to a QVariantMap.
Definition fmh.cpp:22
qsizetype count() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.