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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2010-10-23
 * Description : Graph data class for item history
 *
 * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#ifndef DIGIKAM_ITEM_HISTORY_GRAPH_DATA_H
#define DIGIKAM_ITEM_HISTORY_GRAPH_DATA_H

// Qt includes

#include <QSharedData>

// Local includes

#include "filteraction.h"
#include "historyimageid.h"
#include "itemhistorygraph_boost.h"

namespace Digikam
{

class ItemInfo;

/**
 * Every vertex has one associated object of this class
 *
 * All entries in a vertex refer to _identical_ images.
 * There can be multiple referred images in a history entry.
 * Each single HistoryImageId can resolve into none, one,
 * or multiple ItemInfos.
 * So there is no mapping between the two fields here.
 *
 * If an image is created from multiple source images (panorama etc.),
 * there will be one vertex per source image!
 */
class DIGIKAM_DATABASE_EXPORT HistoryVertexProperties
{
public:

    ItemInfo firstItemInfo()                    const;

    bool markedAs(HistoryImageId::Type)         const;
    bool alwaysMarkedAs(HistoryImageId::Type)   const;

    bool operator==(const QString& uuid)        const;
    bool operator==(const ItemInfo& info)       const;
    bool operator==(qlonglong id)               const;
    bool operator==(const HistoryImageId& info) const;

    HistoryVertexProperties& operator+=(const QString& uuid);
    HistoryVertexProperties& operator+=(const ItemInfo& info);
    HistoryVertexProperties& operator+=(const HistoryImageId& info);

public:

    QString               uuid;
    QList<HistoryImageId> referredImages;
    QList<ItemInfo>       infos;
};

QDebug operator<<(QDebug dbg, const HistoryVertexProperties& props);
QDebug operator<<(QDebug dbg, const HistoryImageId& id);

// ------------------------------------------------------------------------------

/**
 * Every edge has one associated object of this class.
 *
 * For two vertices v1, v2 with and edge e, v1 -> v2,
 * describes the actions necessary to create v2 from v2:
 * v1 -> actions[0] -> ... -> actions[n] = v2.
 */
class DIGIKAM_DATABASE_EXPORT HistoryEdgeProperties
{
public:

    QList<FilterAction> actions;

    HistoryEdgeProperties& operator+=(const FilterAction& action);
};

typedef Graph<HistoryVertexProperties, HistoryEdgeProperties> HistoryGraph;

// ------------------------------------------------------------------------------

class DIGIKAM_DATABASE_EXPORT ItemHistoryGraphData : public HistoryGraph,       // clazy:exclude=copyable-polymorphic
                                                     public QSharedData
{
public:

    ItemHistoryGraphData()
        : HistoryGraph(ChildToParent)
    {
    }

    explicit ItemHistoryGraphData(const HistoryGraph& g)
        : HistoryGraph(g)
    {
    }

    ItemHistoryGraphData& operator=(const HistoryGraph& g)<--- Derived function 'ItemHistoryGraphData::operator='
    {
        HistoryGraph::operator=(g);

        return *this;
    }

    Vertex addVertex(const HistoryImageId& id);
    Vertex addVertex(const QList<HistoryImageId>& imageIds);
    Vertex addVertex(qlonglong id);
    Vertex addVertexScanned(qlonglong id);
    Vertex addVertex(const ItemInfo& info);

    void addHistory(const DImageHistory& givenHistory, qlonglong extraCurrent = 0);

    int removeNextUnresolvedVertex(int begin);

    inline QList<ItemInfo> toInfoList(const QList<Vertex>& vertices) const
    {
        QList<ItemInfo> infos;

        Q_FOREACH (const HistoryGraph::Vertex& v, vertices)
        {
            infos << properties(v).infos;
        }

        return infos;
    }

    QHash<Vertex, HistoryImageId::Types> categorize() const;

protected:

    void applyProperties(Vertex& v, const QList<ItemInfo>& infos, const QList<HistoryImageId>& ids);
};

} // namespace Digikam

#endif // DIGIKAM_ITEM_HISTORY_GRAPH_DATA_H