summaryrefslogtreecommitdiff
path: root/src/pluginflagicondelegate.cpp
blob: a4f66c04a932c2919d6a257cb37cb91446743c46 (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
28
29
30
31
32
33
34
35
36
37
38
39
#include "pluginflagicondelegate.h"
#include "pluginlist.h"
#include <QList>


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<QIcon> GenericIconDelegate::getIcons(const QModelIndex &index) const
{
  QList<QIcon> result;
  if (index.isValid()) {
    foreach (const QVariant &var, index.data(m_Role).toList()) {
      QIcon icon = var.value<QIcon>();
      if (!m_Compact || !icon.isNull()) {
        result.append(icon);
      }
    }
  }
  return result;
}

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