Changeset 67:578192d6fe64 in SMSSender for src/ui/models/accounttreemodel.cpp


Ignore:
Timestamp:
Feb 7, 2010 4:11:28 PM (12 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
3.0
Convert:
svn:3639001d-8e34-449c-bb86-3782b86c4877/branches/3.0@66
Message:
  • added synchttp
  • backup before removing these diamond interfaces...
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ui/models/accounttreemodel.cpp

    r56 r67  
    77{
    88    connect(BCAccountManager::instance(), SIGNAL(accountAdded(IAccount*)),
    9             this, SLOT(accountUpdated(IAccount*)));
     9            this, SLOT(listAltered()));
    1010    connect(BCAccountManager::instance(), SIGNAL(accountUpdated(IAccount*)),
    1111            this, SLOT(accountUpdated(IAccount*)));
    1212    connect(BCAccountManager::instance(), SIGNAL(accountRemoved(IAccount*)),
    13             this, SLOT(accountUpdated(IAccount*)));
     13            this, SLOT(listAltered()));
     14
     15    reloadList();
    1416}
    1517AccountTreeModel::~AccountTreeModel() {
    1618    disconnect(BCAccountManager::instance(), SIGNAL(accountAdded(IAccount*)),
    17                this, SLOT(accountUpdated(IAccount*)));
     19               this, SLOT(listAltered()));
    1820    disconnect(BCAccountManager::instance(), SIGNAL(accountUpdated(IAccount*)),
    1921               this, SLOT(accountUpdated(IAccount*)));
    2022    disconnect(BCAccountManager::instance(), SIGNAL(accountRemoved(IAccount*)),
    21                this, SLOT(accountUpdated(IAccount*)));
     23               this, SLOT(listAltered()));
     24}
     25
     26void AccountTreeModel::listAltered() {
     27    reloadList();
    2228}
    2329
    2430void AccountTreeModel::accountUpdated(IAccount* account) {
    25     int row = BCAccountManager::instance()->getAccountList().values().indexOf(account);
     31    int row = items_.indexOf(account);
    2632
    2733    QModelIndex idx_start = index(row, 0);
    28     QModelIndex idx_end   = index(row, MaxCol);
     34    QModelIndex idx_end   = index(row, columnCount());
    2935
    3036    if (idx_start.isValid() && idx_end.isValid()) {
    3137        emit dataChanged(idx_start, idx_end);
    32     } else {
    33         reset();
    3438    }
     39}
     40
     41void AccountTreeModel::reloadList() {
     42    items_.clear();
     43    foreach(IAccount* account, BCAccountManager::instance()->getAccountList()) {
     44        items_.append(account);
     45    }
     46    reset();
    3547}
    3648
     
    5264
    5365IAccount* AccountTreeModel::dataObject(const QModelIndex& index) const {
    54     return BCAccountManager::instance()->getAccountList().values().at(index.row());
     66    return items_.at(index.row());
    5567}
    5668
    5769QVariant AccountTreeModel::data(const QModelIndex& index, int role) const {
    58     QList<IAccount*> accounts = BCAccountManager::instance()->getAccountList().values();
    59     if (!index.isValid() || index.row() < 0 || index.row() >= accounts.size())
     70    if (!index.isValid() || index.row() < 0 || index.row() >= items_.size())
    6071        return QVariant();
    6172
    62     const IAccount* account = accounts.at(index.row());
     73    const IAccount* account = items_.at(index.row());
    6374
    6475    if (role == Qt::DisplayRole) {
     
    132143
    133144int AccountTreeModel::rowCount(const QModelIndex& parent) const {
    134     return (parent.isValid()) ? 0 : BCAccountManager::instance()->getAccountList().count();
     145    return (parent.isValid()) ? 0 : items_.count();
    135146}
    136147
     
    141152    int lastRow = row + count - 1;
    142153    beginRemoveRows(parent, row, lastRow);
    143     QList<IAccount*> accounts = BCAccountManager::instance()->getAccountList().values();
    144154    for (int i = lastRow; i >= row; --i) {
    145         BCAccountManager::instance()->removeAccount(accounts.at(i)->id());
     155        BCAccountManager::instance()->removeAccount(items_.at(i)->id());
    146156    }
    147157    endRemoveRows();
Note: See TracChangeset for help on using the changeset viewer.