forked from blue/squawk
some sorting in roster
This commit is contained in:
parent
100b2e8943
commit
e4d1e21ea0
@ -313,3 +313,13 @@ void Models::Contact::toOfflineState()
|
||||
emit childRemoved();
|
||||
refresh();
|
||||
}
|
||||
|
||||
QString Models::Contact::getDisplayedName() const
|
||||
{
|
||||
return getContactName();
|
||||
}
|
||||
|
||||
bool Models::Contact::columnInvolvedInDisplay(int col)
|
||||
{
|
||||
return Item::columnInvolvedInDisplay(col) && col == 1;
|
||||
}
|
||||
|
@ -57,9 +57,11 @@ public:
|
||||
unsigned int getMessagesCount() const;
|
||||
void dropMessages();
|
||||
void getMessages(Messages& container) const;
|
||||
QString getDisplayedName() const override;
|
||||
|
||||
protected:
|
||||
void _removeChild(int index) override;
|
||||
bool columnInvolvedInDisplay(int col) override;
|
||||
|
||||
protected slots:
|
||||
void refresh();
|
||||
|
@ -55,16 +55,28 @@ void Models::Item::setName(const QString& p_name)
|
||||
void Models::Item::appendChild(Models::Item* child)
|
||||
{
|
||||
bool moving = false;
|
||||
int oldRow = child->row();
|
||||
int newRow = this->childCount();
|
||||
int newRow = 0;
|
||||
std::deque<Item*>::const_iterator before = childItems.begin();
|
||||
while (before != childItems.end()) {
|
||||
Item* bfr = *before;
|
||||
if (bfr->type > child->type) {
|
||||
break;
|
||||
} else if (bfr->type == child->type && bfr->getDisplayedName() > child->getDisplayedName()) {
|
||||
break;
|
||||
}
|
||||
newRow++;
|
||||
before++;
|
||||
}
|
||||
|
||||
if (child->parent != 0) {
|
||||
int oldRow = child->row();
|
||||
moving = true;
|
||||
emit childIsAboutToBeMoved(child->parent, oldRow, oldRow, this, newRow);
|
||||
child->parent->_removeChild(oldRow);
|
||||
} else {
|
||||
emit childIsAboutToBeInserted(this, newRow, newRow);
|
||||
}
|
||||
childItems.push_back(child);
|
||||
childItems.insert(before, child);
|
||||
child->parent = this;
|
||||
|
||||
QObject::connect(child, SIGNAL(childChanged(Models::Item*, int, int)), this, SIGNAL(childChanged(Models::Item*, int, int)));
|
||||
@ -147,7 +159,7 @@ void Models::Item::_removeChild(int index)
|
||||
{
|
||||
Item* child = childItems[index];
|
||||
|
||||
QObject::disconnect(child, SIGNAL(childChanged(Models::Item*, int, int)), this, SIGNAL(childChanged(Models::Item*, int, int)));
|
||||
QObject::disconnect(child, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onChildChanged(Models::Item*, int, int)));
|
||||
QObject::disconnect(child, SIGNAL(childIsAboutToBeInserted(Item*, int, int)), this, SIGNAL(childIsAboutToBeInserted(Item*, int, int)));
|
||||
QObject::disconnect(child, SIGNAL(childInserted()), this, SIGNAL(childInserted()));
|
||||
QObject::disconnect(child, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)), this, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)));
|
||||
@ -212,3 +224,44 @@ QString Models::Item::getAccountName() const
|
||||
}
|
||||
return acc->getName();
|
||||
}
|
||||
|
||||
QString Models::Item::getDisplayedName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
void Models::Item::onChildChanged(Models::Item* item, int row, int col)
|
||||
{
|
||||
Item* parent = item->parentItem();
|
||||
if (parent != 0 && parent == this) {
|
||||
if (item->columnInvolvedInDisplay(col)) {
|
||||
int newRow = 0;
|
||||
std::deque<Item*>::const_iterator before = childItems.begin();
|
||||
while (before != childItems.end()) {
|
||||
Item* bfr = *before;
|
||||
if (bfr->type > item->type) {
|
||||
break;
|
||||
} else if (bfr->type == item->type && bfr->getDisplayedName() > item->getDisplayedName()) {
|
||||
break;
|
||||
}
|
||||
newRow++;
|
||||
before++;
|
||||
}
|
||||
|
||||
if (newRow != row || (before != childItems.end() && *before != item)) {
|
||||
emit childIsAboutToBeMoved(this, row, row, this, newRow);
|
||||
std::deque<Item*>::const_iterator old = childItems.begin();
|
||||
old += row;
|
||||
childItems.erase(old);
|
||||
childItems.insert(before, item);
|
||||
emit childMoved();
|
||||
}
|
||||
}
|
||||
}
|
||||
emit childChanged(item, row, col);
|
||||
}
|
||||
|
||||
bool Models::Item::columnInvolvedInDisplay(int col)
|
||||
{
|
||||
return col == 0;
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ class Item : public QObject{
|
||||
public:
|
||||
virtual void appendChild(Item *child);
|
||||
virtual void removeChild(int index);
|
||||
virtual QString getDisplayedName() const;
|
||||
QString getName() const;
|
||||
void setName(const QString& name);
|
||||
|
||||
@ -76,8 +77,12 @@ class Item : public QObject{
|
||||
protected:
|
||||
virtual void changed(int col);
|
||||
virtual void _removeChild(int index);
|
||||
virtual bool columnInvolvedInDisplay(int col);
|
||||
const Item* getParentAccount() const;
|
||||
|
||||
protected slots:
|
||||
void onChildChanged(Models::Item* item, int row, int col);
|
||||
|
||||
protected:
|
||||
QString name;
|
||||
std::deque<Item*> childItems;
|
||||
|
@ -309,3 +309,13 @@ void Models::Room::setSubject(const QString& sub)
|
||||
changed(6);
|
||||
}
|
||||
}
|
||||
|
||||
QString Models::Room::getDisplayedName() const
|
||||
{
|
||||
return getRoomName();
|
||||
}
|
||||
|
||||
bool Models::Room::columnInvolvedInDisplay(int col)
|
||||
{
|
||||
return Item::columnInvolvedInDisplay(col) && col == 1;
|
||||
}
|
||||
|
@ -68,10 +68,14 @@ public:
|
||||
void removeParticipant(const QString& name);
|
||||
|
||||
void toOfflineState() override;
|
||||
QString getDisplayedName() const override;
|
||||
|
||||
private:
|
||||
void handleParticipantUpdate(std::map<QString, Participant*>::const_iterator itr, const QMap<QString, QVariant>& data);
|
||||
|
||||
protected:
|
||||
bool columnInvolvedInDisplay(int col) override;
|
||||
|
||||
private:
|
||||
bool autoJoin;
|
||||
bool joined;
|
||||
|
@ -738,7 +738,7 @@ QString Models::Roster::getContactName(const QString& account, const QString& ji
|
||||
if (rItr == rooms.end()) {
|
||||
qDebug() << "An attempt to get a name of non existing contact/room " << account << ":" << jid << ", skipping";
|
||||
} else {
|
||||
name = rItr->second->getName();
|
||||
name = rItr->second->getRoomName();
|
||||
}
|
||||
} else {
|
||||
name = cItr->second->getContactName();
|
||||
|
Loading…
Reference in New Issue
Block a user