make layoutstable generic table dependent

pull/19/head
Michail Vourlakos 5 years ago
parent 3c92b04cbc
commit 5cb0277682

@ -19,6 +19,7 @@
*/
#include "generictable.h"
#include "layoutdata.h"
#include <QDebug>
@ -140,24 +141,6 @@ const T GenericTable<T>::operator[](const uint &index) const
return m_list[index];
}
template <class T>
GenericTable<T> GenericTable<T>::subtracted(const GenericTable<T> &rhs) const
{
GenericTable<T> subtract;
if ((*this) == rhs) {
return subtract;
}
for(int i=0; i<m_list.count(); ++i) {
if (!rhs.containsId(m_list[i].id)) {
subtract << m_list[i];
}
}
return subtract;
}
template <class T>
bool GenericTable<T>::containsId(const QString &id) const
{
@ -242,5 +225,10 @@ 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>;
}
}

@ -50,8 +50,6 @@ public:
T &operator[](const uint &index);
const T operator[](const uint &index) const;
GenericTable<T> subtracted(const GenericTable<T> &rhs) const;
bool containsId(const QString &id) const;
bool containsName(const QString &name) const;
bool rowExists(const int &row) const;

@ -26,17 +26,18 @@ namespace Latte {
namespace Data {
LayoutsTable::LayoutsTable()
: GenericTable<Layout>()
{
}
LayoutsTable::LayoutsTable(LayoutsTable &&o)
: m_layouts(o.m_layouts)
: GenericTable<Layout>(o)
{
}
LayoutsTable::LayoutsTable(const LayoutsTable &o)
: m_layouts(o.m_layouts)
: GenericTable<Layout>(o)
{
}
@ -44,98 +45,41 @@ LayoutsTable::LayoutsTable(const LayoutsTable &o)
//! Operators
LayoutsTable &LayoutsTable::operator=(const LayoutsTable &rhs)
{
m_layouts = rhs.m_layouts;
m_list = rhs.m_list;
return (*this);
}
LayoutsTable &LayoutsTable::operator=(LayoutsTable &&rhs)
{
m_layouts = rhs.m_layouts;
return (*this);
}
LayoutsTable &LayoutsTable::operator<<(const Layout &rhs)
{
if (!rhs.id.isEmpty()) {
m_layouts << rhs;
}
m_list = rhs.m_list;
return (*this);
}
bool LayoutsTable::operator==(const LayoutsTable &rhs) const
{
if (m_layouts.count() == 0 && rhs.m_layouts.count() == 0) {
return true;
}
if (m_layouts.count() != rhs.m_layouts.count()) {
return false;
}
for(int i=0; i<m_layouts.count(); ++i) {
QString id = m_layouts[i].id;
if (!rhs.containsId(id) || (*this)[id] != rhs[id]){
return false;
}
}
return true;
}
bool LayoutsTable::operator!=(const LayoutsTable &rhs) const
{
return !(*this == rhs);
}
Layout &LayoutsTable::operator[](const QString &id)
LayoutsTable LayoutsTable::subtracted(const LayoutsTable &rhs) const
{
int pos{-1};
LayoutsTable subtract;
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].id == id){
pos = i;
break;
}
if ((*this) == rhs) {
return subtract;
}
return m_layouts[pos];
}
const Layout LayoutsTable::operator[](const QString &id) const
{
int pos{-1};
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].id == id){
pos = i;
break;
for(int i=0; i<m_list.count(); ++i) {
if (!rhs.containsId(m_list[i].id)) {
subtract << m_list[i];
}
}
return m_layouts[pos];
}
Layout &LayoutsTable::operator[](const uint &index)
{
return m_layouts[index];
}
const Layout LayoutsTable::operator[](const uint &index) const
{
return m_layouts[index];
return subtract;
}
QStringList LayoutsTable::allSharesIds() const
{
QStringList sharesIds;
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].isShared()) {
for(int j=0; j<m_layouts[i].shares.count(); ++j) {
sharesIds << m_layouts[i].shares[j];
for(int i=0; i<m_list.count(); ++i) {
if (m_list[i].isShared()) {
for(int j=0; j<m_list[i].shares.count(); ++j) {
sharesIds << m_list[i].shares[j];
}
}
}
@ -147,12 +91,12 @@ QStringList LayoutsTable::allSharesNames() const
{
QStringList sharesNames;
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].isShared()) {
for(int j=0; j<m_layouts[i].shares.count(); ++j) {
QString shareId = m_layouts[i].shares[j];
for(int i=0; i<m_list.count(); ++i) {
if (m_list[i].isShared()) {
for(int j=0; j<m_list[i].shares.count(); ++j) {
QString shareId = m_list[i].shares[j];
int sid = indexOf(shareId);
sharesNames << m_layouts[sid].name;
sharesNames << m_list[sid].name;
}
}
}
@ -160,119 +104,27 @@ QStringList LayoutsTable::allSharesNames() const
return sharesNames;
}
LayoutsTable LayoutsTable::subtracted(const LayoutsTable &rhs) const
{
LayoutsTable subtract;
if ((*this) == rhs) {
return subtract;
}
for(int i=0; i<m_layouts.count(); ++i) {
if (!rhs.containsId(m_layouts[i].id)) {
subtract << m_layouts[i];
}
}
return subtract;
}
Latte::Layouts::SharesMap LayoutsTable::sharesMap() const
{
Latte::Layouts::SharesMap map;
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].isShared()) {
for(int i=0; i<m_list.count(); ++i) {
if (m_list[i].isShared()) {
QStringList sharesNames;
for(int j=0; j<m_layouts[i].shares.count(); ++j) {
QString shareId = m_layouts[i].shares[j];
for(int j=0; j<m_list[i].shares.count(); ++j) {
QString shareId = m_list[i].shares[j];
int sid = indexOf(shareId);
sharesNames << m_layouts[sid].name;
sharesNames << m_list[sid].name;
}
map[m_layouts[i].name] = sharesNames;
map[m_list[i].name] = sharesNames;
}
}
return map;
}
bool LayoutsTable::containsId(const QString &id) const
{
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].id == id){
return true;
}
}
return false;
}
bool LayoutsTable::containsName(const QString &name) const
{
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].name == name){
return true;
}
}
return false;
}
bool LayoutsTable::rowExists(const int &row) const
{
return (m_layouts.count()>=0 && row>=0 && row<rowCount());
}
int LayoutsTable::indexOf(const QString &id) const
{
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].id == id){
return i;
}
}
return -1;
}
int LayoutsTable::rowCount() const
{
return m_layouts.count();
}
QString LayoutsTable::idForName(const QString &name) const
{
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].name == name) {
return m_layouts[i].id;
}
}
return QString();
}
void LayoutsTable::clear()
{
m_layouts.clear();
}
void LayoutsTable::remove(const QString &id)
{
const int pos = indexOf(id);
if (pos >= 0) {
m_layouts.removeAt(pos);
}
}
void LayoutsTable::remove(const int &row)
{
if (rowExists(row)) {
m_layouts.removeAt(row);
}
}
void LayoutsTable::setLayoutForFreeActivities(const QString &id)
{
int row = indexOf(id);
@ -280,9 +132,9 @@ void LayoutsTable::setLayoutForFreeActivities(const QString &id)
if (row>=0) {
for(int i=0; i<rowCount(); ++i) {
if (i == row) {
m_layouts[row].activities = QStringList(Data::Layout::FREEACTIVITIESID);
} else if (m_layouts[i].activities.contains(Data::Layout::FREEACTIVITIESID)) {
m_layouts[i].activities.removeAll(Data::Layout::FREEACTIVITIESID);
m_list[row].activities = QStringList(Data::Layout::FREEACTIVITIESID);
} else if (m_list[i].activities.contains(Data::Layout::FREEACTIVITIESID)) {
m_list[i].activities.removeAll(Data::Layout::FREEACTIVITIESID);
}
}
}

@ -22,6 +22,7 @@
#define LAYOUTSTABLEDATA_H
// local
#include "generictable.h"
#include "layoutdata.h"
#include "../layouts/synchronizer.h"
@ -31,7 +32,7 @@
namespace Latte {
namespace Data {
class LayoutsTable
class LayoutsTable : public GenericTable<Layout>
{
public:
@ -42,38 +43,13 @@ public:
//! Operators
LayoutsTable &operator=(const LayoutsTable &rhs);
LayoutsTable &operator=(LayoutsTable &&rhs);
LayoutsTable &operator<<(const Layout &rhs);
bool operator==(const LayoutsTable &rhs) const;
bool operator!=(const LayoutsTable &rhs) const;
Layout &operator[](const QString &id);
const Layout operator[](const QString &id) const;
Layout &operator[](const uint &index);
const Layout operator[](const uint &index) const;
LayoutsTable subtracted(const LayoutsTable &rhs) const;
QStringList allSharesIds() const;
QStringList allSharesNames() const;
Latte::Layouts::SharesMap sharesMap() const;
bool containsId(const QString &id) const;
bool containsName(const QString &name) const;
bool rowExists(const int &row) const;
int indexOf(const QString &id) const;
int rowCount() const;
QString idForName(const QString &name) const;
void clear();
void remove(const int &row);
void remove(const QString &id);
void setLayoutForFreeActivities(const QString &id);
protected:
//! #id, layout_record
QList<Layout> m_layouts;
};
}

Loading…
Cancel
Save