35 #include <QDataStream>
40 : QAbstractTableModel(parent)
43 _headerStrings <<
"Name"
52 if (index.isValid() && role == Qt::DisplayRole) {
54 emit dataChanged(index, index);
58 if (index.isValid() && role == Qt::EditRole) {
64 _list.at(index.row())->setLifetime(value.toInt());
67 _list.at(index.row())->setMute(value.toBool());
70 emit dataChanged(index, index);
78 if (!index.isValid()) {
79 qWarning() <<
"NotifyTableModel::data - index.isValid()";
83 if (index.row() >= _list.size())
86 if (role == Qt::DisplayRole || role == Qt::EditRole) {
87 switch (index.column()) {
89 return _list.at(index.row())->toString();
95 return _list.at(index.row())->lifetime();
98 return _list.at(index.row())->mute();
104 if (Qt::SizeHintRole == role) {
113 if (role != Qt::DisplayRole)
116 if (orientation == Qt::Horizontal)
117 return _headerStrings.at(section);
118 else if (orientation == Qt::Vertical)
119 return QString(
"%1").arg(section);
128 if (-1 == position || -1 == rows)
131 beginInsertRows(QModelIndex(), position, position + rows - 1);
133 for (
int i = 0;
i < rows; ++
i) {
145 if ((-1 == position) || (-1 == rows))
148 beginRemoveRows(QModelIndex(), position, position + rows - 1);
150 for (
int row = 0; row < rows; ++row) {
151 _list.removeAt(position);
160 QModelIndex
idx = index(offset, 0);
161 emit dataChanged(idx, idx);
168 _list.replace(
rowCount() - 1, item);
175 return Qt::MoveAction;
186 int column,
const QModelIndex &parent)
189 if (action == Qt::IgnoreAction)
200 if (parent.isValid())
201 beginRow = parent.row();
210 QDataStream stream(&encodedData, QIODevice::ReadOnly);
213 while (!stream.atEnd()) {
217 int dragged = _list.indexOf(item);
220 enum { UP_DIRECTION, DOWN_DIRECTION };
221 int direction = (dragged < rows) ? DOWN_DIRECTION : (dragged += 1, UP_DIRECTION);
223 if (dragged < 0 || ((dragged + 1) >= _list.size() && direction == DOWN_DIRECTION)
224 || dragged == rows) {
229 if (rows + direction > _list.size())
232 insertRows(rows + direction, 1, QModelIndex());
233 _list.replace(rows + direction, item);
235 if (direction == UP_DIRECTION)
239 QModelIndex idxTopLeft = index(beginRow, 0, QModelIndex());
240 QModelIndex idxBotRight = index(beginRow,
columnCount(QModelIndex()), QModelIndex());
241 emit dataChanged(idxTopLeft, idxBotRight);
247 QMimeData *
mimeData =
new QMimeData();
248 QByteArray encodedData;
250 QDataStream stream(&encodedData, QIODevice::WriteOnly);
252 foreach (
const QModelIndex &index, indexes) {
253 if (!index.column()) {
254 quintptr item =
reinterpret_cast<quintptr
>(_list.at(index.row()));
263 void NotifyTableModel::dropRows(
int position,
int count)
const
265 for (
int row = 0; row < count; ++row) {
266 _list.removeAt(position);
Uses to logging only inside notify plugin, can be convinient turned on/off.
NotifyTableModel(QList< NotificationItem * > &parentList, QObject *parent=nullptr)
int columnCount(const QModelIndex &) const
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
QStringList mimeTypes() const
int rowCount(const QModelIndex &parent=QModelIndex()) const
void entryAdded(NotificationItem *item)
QMimeData * mimeData(const QModelIndexList &indexes) const
const char * mime_type_notify_table
static QStringList retryValues
bool removeRows(int position, int rows, const QModelIndex &index)
bool setData(const QModelIndex &index, const QVariant &value, int role)
bool insertRows(int position, int rows, const QModelIndex &index)
QVariant data(const QModelIndex &index, int role) const
Qt::DropActions supportedDropActions() const
void dragRows(int position, int count)
void entryUpdated(int offset)
QVariant headerData(int section, Qt::Orientation orientation, int role) const