refactoring ui models, temp

This commit is contained in:
Blue 2019-04-03 18:09:29 +03:00
parent 4a4ba47968
commit 2bcee521c5
7 changed files with 246 additions and 143 deletions

View file

@ -20,7 +20,7 @@ void Models::Roster::addAccount(const QMap<QString, QVariant>& data)
Account* acc = new Account(data, root);
beginInsertRows(QModelIndex(), root->childCount(), root->childCount());
root->appendChild(acc);
accounts.insert(std::make_pair(acc->name(), acc));
accounts.insert(std::make_pair(acc->getName(), acc));
endInsertRows();
}
@ -67,11 +67,6 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
return result;
}
void Models::Roster::Item::setName(const QString& name)
{
itemData[0] = name;
}
int Models::Roster::columnCount (const QModelIndex& parent) const
{
if (parent.isValid()) {
@ -175,76 +170,7 @@ QModelIndex Models::Roster::index (int row, int column, const QModelIndex& paren
}
Models::Roster::Item::Item(Type p_type, const QMap<QString, QVariant> &p_data, Item *p_parent):
type(p_type),
childItems(),
itemData(),
parent(p_parent)
{
itemData.push_back(p_data.value("name"));
}
Models::Roster::Item::~Item()
{
std::deque<Item*>::const_iterator itr = childItems.begin();
std::deque<Item*>::const_iterator end = childItems.end();
for (;itr != end; ++itr) {
delete (*itr);
}
}
void Models::Roster::Item::appendChild(Models::Roster::Item* child)
{
childItems.push_back(child);
}
Models::Roster::Item * Models::Roster::Item::child(int row)
{
return childItems[row];
}
int Models::Roster::Item::childCount() const
{
return childItems.size();
}
int Models::Roster::Item::row() const
{
if (parent != 0) {
std::deque<Item*>::const_iterator itr = parent->childItems.begin();
std::deque<Item*>::const_iterator end = parent->childItems.end();
for (int i = 0; itr != end; ++itr, ++i) {
if (*itr == this) {
return i;
}
}
}
return 0; //TODO not sure how it helps, i copy-pasted it from the example
}
Models::Roster::Item * Models::Roster::Item::parentItem()
{
return parent;
}
int Models::Roster::Item::columnCount() const
{
return itemData.size();
}
QString Models::Roster::Item::name() const
{
return itemData[0].toString();
}
QVariant Models::Roster::Item::data(int column) const
{
return itemData[column];
}
Models::Roster::ElId::ElId(const QString& p_account, const QString& p_name):
account(p_account),
@ -262,19 +188,4 @@ bool Models::Roster::ElId::operator <(const Models::Roster::ElId& other) const
}
}
Models::Roster::Account::Account(const QMap<QString, QVariant>& data, Models::Roster::Item* parentItem):
Item(account, data, parentItem)
{
itemData.push_back(data.value("state"));
}
Models::Roster::Account::~Account()
{
}
void Models::Roster::Account::setState(int state)
{
itemData[1] = state;
}