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
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2013-03-02
 * Description : Table view: Tree view subelement
 *
 * SPDX-FileCopyrightText: 2017-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
 * SPDX-FileCopyrightText: 2013      by Michael G. Hansen <mike at mghansen dot de>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#include "tableview_treeview_delegate.h"

// Qt includes


// Local includes

#include "digikam_debug.h"
#include "contextmenuhelper.h"
#include "coredbfields.h"
#include "coredbwatch.h"
#include "fileactionmngr.h"
#include "iteminfo.h"
#include "itemmodel.h"
#include "itemposition.h"
#include "importfiltermodel.h"
#include "importimagemodel.h"
#include "importui.h"
#include "tableview_column_configuration_dialog.h"
#include "tableview_model.h"
#include "tableview_selection_model_syncer.h"

namespace Digikam
{

TableViewItemDelegate::TableViewItemDelegate(TableViewShared* const tableViewShared, QObject* const parent)
    : QItemDelegate(parent),
      s            (tableViewShared)
{
}

void TableViewItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& tableViewModelIndex) const
{
    const int columnIndex               = tableViewModelIndex.column();
    const int columnCount               = s->tableViewModel->columnCount(QModelIndex());

    if ((columnIndex < 0) || (columnIndex >= columnCount))
    {
        QItemDelegate::paint(painter, option, tableViewModelIndex);
        return;
    }

    TableViewColumn* const columnObject = s->tableViewModel->getColumnObject(columnIndex);<--- Variable 'columnObject' can be declared as pointer to const
    bool useDefaultPainter              = !columnObject->getColumnFlags().testFlag(TableViewColumn::ColumnCustomPainting);

    if (!useDefaultPainter)
    {
        TableViewModel::Item* const item = s->tableViewModel->itemFromIndex(tableViewModelIndex);
        useDefaultPainter                = !columnObject->paint(painter, option, item);
    }

    if (useDefaultPainter)
    {
        QItemDelegate::paint(painter, option, tableViewModelIndex);
    }
}

QSize TableViewItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& tableViewModelIndex) const
{
    const int columnIndex = tableViewModelIndex.column();

    /// we have to take the maximum of all columns for the height
    /// @todo somehow cache this calculation
    /// @todo check column flags

    const int columnCount            = s->tableViewModel->columnCount(QModelIndex());
    TableViewModel::Item* const item = s->tableViewModel->itemFromIndex(tableViewModelIndex);
    int maxHeight                    = 0;

    if ((columnIndex < 0) || (columnIndex >= columnCount))
    {
        return QItemDelegate::sizeHint(option, tableViewModelIndex);
    }

    for (int i = 0 ; i < columnCount ; ++i)
    {
        TableViewColumn* const iColumnObject = s->tableViewModel->getColumnObject(i);<--- Variable 'iColumnObject' can be declared as pointer to const

        if (iColumnObject && item)
        {
            const QSize iColumnSize = iColumnObject->sizeHint(option, item);

            if (iColumnSize.isValid())
            {
                maxHeight = qMax(maxHeight, iColumnSize.height());
            }
        }
    }

    QSize columnSize;
    TableViewColumn* const columnObject = s->tableViewModel->getColumnObject(columnIndex);<--- Variable 'columnObject' can be declared as pointer to const

    if (columnObject && item)
    {
        columnSize = columnObject->sizeHint(option, item);
    }

    if (!columnSize.isValid())
    {
        columnSize = QItemDelegate::sizeHint(option, tableViewModelIndex);

        /// @todo we have to incorporate the height given by QItemDelegate for the other columns, too

        maxHeight  = qMax(maxHeight, columnSize.height());
    }

    return QSize(columnSize.width(), maxHeight);
}

} // namespace Digikam

#include "moc_tableview_treeview_delegate.cpp"