summaryrefslogtreecommitdiff
path: root/src/genericicondelegate.cpp
blob: 98917c335210709587df9c07fe2663299ffed7ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "genericicondelegate.h"
#include "pluginlist.h"
#include <QList>
#include <QPixmapCache>

GenericIconDelegate::GenericIconDelegate(QObject* parent, int role, int logicalIndex, int compactSize)
    : IconDelegate(parent), m_Role(role), m_LogicalIndex(logicalIndex), m_CompactSize(compactSize), m_Compact(false) {}

void GenericIconDelegate::columnResized(int logicalIndex, int, int newSize) {
    if (logicalIndex == m_LogicalIndex) {
        m_Compact = newSize < m_CompactSize;
    }
}

QList<QString> GenericIconDelegate::getIcons(const QModelIndex& index) const {
    QList<QString> result;
    if (index.isValid()) {
        for (const QVariant& var : index.data(m_Role).toList()) {
            if (!m_Compact || !var.toString().isEmpty()) {
                result.append(var.toString());
            }
        }
    }
    return result;
}

size_t GenericIconDelegate::getNumIcons(const QModelIndex& index) const { return index.data(m_Role).toList().count(); }