inital commit
This commit is contained in:
59
src/items/itemstore.cpp
Normal file
59
src/items/itemstore.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "itemstore.h"
|
||||
#include <QJsonArray>
|
||||
|
||||
ItemStore::ItemStore(QObject *parent): QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ItemStore::addItem(std::shared_ptr<Item> item)
|
||||
{
|
||||
bool mached = false;
|
||||
for(unsigned i = 0; i < items_.size(); i++ ) if(*items_[i] == *item) mached = true;
|
||||
if(!mached)
|
||||
{
|
||||
items_.push_back(std::shared_ptr<Item>(item));
|
||||
itemAdded(std::weak_ptr<Item>(items_.back()));
|
||||
}
|
||||
}
|
||||
|
||||
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
|
||||
{
|
||||
for(unsigned j = 0; j < itemIn.size(); j++)
|
||||
addItem(itemIn[j]);
|
||||
|
||||
}
|
||||
|
||||
void ItemStore::removeItem(const ItemData& item)
|
||||
{
|
||||
for(unsigned j = 0; j < items_.size(); j++)
|
||||
{
|
||||
if(item == *items_[j])
|
||||
{
|
||||
items_.erase(items_.begin()+j);
|
||||
--j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ItemStore::clear()
|
||||
{
|
||||
for(size_t i = 0; i < items_.size(); ++i) itemDeleted(*items_[i]);
|
||||
items_.clear();
|
||||
}
|
||||
|
||||
|
||||
void ItemStore::itemStateChanged(const ItemData& item)
|
||||
{
|
||||
|
||||
for(unsigned i = 0; i < items_.size(); i++ )
|
||||
{
|
||||
if(items_[i]->operator==(item))
|
||||
{
|
||||
|
||||
if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user