Messagelib

modelinvariantindex.h
1/******************************************************************************
2 *
3 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 *
7 *******************************************************************************/
8
9#pragma once
10
11#include <memory>
12#include <qglobal.h> // defines uint, at least.
13namespace MessageList
14{
15namespace Core
16{
17class ModelInvariantRowMapper;
18class ModelInvariantRowMapperPrivate;
19class RowShift;
20
21/**
22 * An invariant index that can be ALWAYS used to reference
23 * an item inside a QAbstractItemModel.
24 *
25 * This class is meant to be used together with ModelInvariantRowMapper.
26 */
28{
29 friend class ModelInvariantRowMapper;
30 friend class ModelInvariantRowMapperPrivate;
31 friend class RowShift;
32
33public:
34 explicit ModelInvariantIndex();
35 virtual ~ModelInvariantIndex();
36
37public:
38 /**
39 * Returns true if this ModelInvariantIndex is valid, that is, it has been attached
40 * to a ModelInvariantRowMapper. Returns false otherwise.
41 * An invalid index will always map to the current row -1 (which is invalid as QModelIndex row).
42 */
43 [[nodiscard]] bool isValid() const;
44
45 /**
46 * Returns the current model index row for this invariant index. This function
47 * calls the mapper and asks it to perform the persistent mapping.
48 * If this index isn't valid then the returned value is -1.
49 *
50 * If you actually own the row mapper then you may save some clock cycles
51 * by calling the modelInvariantIndexToModelIndexRow() by your own. If you don't
52 * own the mapper then this function is the only way to go.
53 */
54 [[nodiscard]] int currentModelIndexRow();
55
56private:
57 class ModelInvariantIndexPrivate;
58 std::unique_ptr<ModelInvariantIndexPrivate> const d;
59};
60} // namespace Core
61} // namespace MessageList
An invariant index that can be ALWAYS used to reference an item inside a QAbstractItemModel.
bool isValid() const
Returns true if this ModelInvariantIndex is valid, that is, it has been attached to a ModelInvariantR...
int currentModelIndexRow()
Returns the current model index row for this invariant index.
This class is an optimizing helper for dealing with large flat QAbstractItemModel objects.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.