squawk/ui/models/item.h

104 lines
3.0 KiB
C
Raw Normal View History

/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2019-04-03 15:09:29 +00:00
#ifndef MODELS_ITEM_H
#define MODELS_ITEM_H
#include <QMap>
#include <QString>
#include <QVariant>
#include <deque>
#include "shared/enums.h"
2019-04-03 15:09:29 +00:00
namespace Models {
2019-04-03 18:15:36 +00:00
class Item : public QObject{
Q_OBJECT
2019-04-03 15:09:29 +00:00
public:
enum Type {
account,
group,
2019-04-03 21:23:51 +00:00
contact,
room,
2019-04-07 14:02:41 +00:00
presence,
participant,
2019-04-03 15:09:29 +00:00
root
};
explicit Item(Type p_type, const QMap<QString, QVariant> &data, Item *parentItem = 0);
Item(const Item& other);
2019-04-03 15:09:29 +00:00
~Item();
2019-04-03 18:15:36 +00:00
signals:
2019-04-09 15:04:08 +00:00
void childChanged(Models::Item* item, int row, int col);
2019-04-07 14:02:41 +00:00
void childIsAboutToBeInserted(Item* parent, int first, int last);
void childInserted();
void childIsAboutToBeRemoved(Item* parent, int first, int last);
void childRemoved();
void childIsAboutToBeMoved(Item* source, int first, int last, Item* destination, int newIndex);
void childMoved();
2019-04-03 18:15:36 +00:00
public:
2019-04-07 14:02:41 +00:00
virtual void appendChild(Item *child);
virtual void removeChild(int index);
2019-09-24 09:21:29 +00:00
virtual QString getDisplayedName() const;
2019-04-03 15:09:29 +00:00
QString getName() const;
void setName(const QString& name);
Item *child(int row);
int childCount() const;
virtual int columnCount() const;
virtual QVariant data(int column) const;
int row() const;
Item *parentItem();
2019-04-09 15:04:08 +00:00
const Item *parentItemConst() const;
2019-04-03 15:09:29 +00:00
2019-08-28 11:40:55 +00:00
QString getAccountName() const;
QString getAccountJid() const;
QString getAccountResource() const;
Shared::ConnectionState getAccountConnectionState() const;
Shared::Availability getAccountAvailability() const;
2019-08-28 11:40:55 +00:00
2019-04-03 15:09:29 +00:00
const Type type;
2019-04-07 14:02:41 +00:00
protected:
virtual void changed(int col);
virtual void _removeChild(int index);
2019-09-24 09:21:29 +00:00
virtual bool columnInvolvedInDisplay(int col);
2019-08-28 11:40:55 +00:00
const Item* getParentAccount() const;
2019-04-07 14:02:41 +00:00
2019-09-24 09:21:29 +00:00
protected slots:
void onChildChanged(Models::Item* item, int row, int col);
2019-04-03 15:09:29 +00:00
protected:
QString name;
std::deque<Item*> childItems;
Item* parent;
2019-04-07 14:02:41 +00:00
protected slots:
virtual void toOfflineState();
2019-04-03 15:09:29 +00:00
};
}
#endif // MODELS_ITEM_H