data:extend generictable functionality

--provide different insert methods in order
to insert elements based on name or id sorting
criteria
pull/19/head
Michail Vourlakos 5 years ago
parent 7a3d68ed61
commit a36b49de77

@ -23,6 +23,7 @@
//! local
#include "genericdata.h"
#include "generictable.h"
//! Qt
#include <QMetaType>
@ -39,8 +40,6 @@ public:
Applet(const Applet &o);
//! Layout data
QString id;
QString name;
QString description;
QString icon;
@ -49,6 +48,8 @@ public:
Applet &operator=(Applet &&rhs);
};
typedef GenericTable<Applet> AppletTable;
}
}

@ -19,6 +19,7 @@
*/
#include "generictable.h"
#include "appletdata.h"
#include "layoutdata.h"
#include <QDebug>
@ -71,6 +72,13 @@ GenericTable<T> &GenericTable<T>::operator<<(const T &rhs)
return (*this);
}
template <class T>
GenericTable<T> &GenericTable<T>::operator<<(const GenericTable<T> &rhs)
{
m_list << rhs.m_list;
return (*this);
}
template <class T>
GenericTable<T> &GenericTable<T>::insert(const int &pos, const T &rhs)
{
@ -78,6 +86,18 @@ GenericTable<T> &GenericTable<T>::insert(const int &pos, const T &rhs)
return (*this);
}
template <class T>
GenericTable<T> &GenericTable<T>::insertBasedOnName(const T &rhs)
{
return insert(sortedPosForName(rhs.name), rhs);
}
template <class T>
GenericTable<T> &GenericTable<T>::insertBasedOnId(const T &rhs)
{
return insert(sortedPosForId(rhs.id), rhs);
}
template <class T>
bool GenericTable<T>::operator==(const GenericTable<T> &rhs) const
{
@ -196,6 +216,22 @@ int GenericTable<T>::rowCount() const
return m_list.count();
}
template <class T>
int GenericTable<T>::sortedPosForId(const QString &id) const
{
int pos{0};
for(int i=0; i<m_list.count(); ++i) {
if (QString::compare(m_list[i].id, id, Qt::CaseInsensitive) <= 0) {
pos++;
} else {
break;
}
}
return pos;
}
template <class T>
int GenericTable<T>::sortedPosForName(const QString &name) const
{
@ -251,7 +287,8 @@ void GenericTable<T>::remove(const int &row)
//! Make linker happy and provide which table instances will be used.
//! The alternative would be to move functions definitions in the header file
//! but that would drop readability
template class GenericTable<Layout>;
template class GenericTable<Data::Applet>;
template class GenericTable<Data::Layout>;
}
}

@ -43,7 +43,11 @@ public:
GenericTable<T> &operator=(const GenericTable<T> &rhs);
GenericTable<T> &operator=(GenericTable<T> &&rhs);
GenericTable<T> &operator<<(const T &rhs);
GenericTable<T> &operator<<(const GenericTable<T> &rhs);
GenericTable<T> &insert(const int &pos, const T &rhs);
GenericTable<T> &insertBasedOnName(const T &rhs);
GenericTable<T> &insertBasedOnId(const T &rhs);
bool operator==(const GenericTable<T> &rhs) const;
bool operator!=(const GenericTable<T> &rhs) const;
T &operator[](const QString &id);
@ -58,6 +62,7 @@ public:
int indexOf(const QString &id) const;
int rowCount() const;
int sortedPosForName(const QString &name) const;
int sortedPosForId(const QString &id) const;
QString idForName(const QString &name) const;

Loading…
Cancel
Save