Messagelib

modelinvariantindex.h
1 /******************************************************************************
2  *
3  * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <[email protected]>
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.
13 namespace MessageList
14 {
15 namespace Core
16 {
17 class ModelInvariantRowMapper;
18 class ModelInvariantRowMapperPrivate;
19 class 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  */
27 class ModelInvariantIndex
28 {
29  friend class ModelInvariantRowMapper;
30  friend class ModelInvariantRowMapperPrivate;
31  friend class RowShift;
32 
33 public:
34  explicit ModelInvariantIndex();
35  virtual ~ModelInvariantIndex();
36 
37 public:
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 
56 private:
57  class ModelInvariantIndexPrivate;
58  std::unique_ptr<ModelInvariantIndexPrivate> const d;
59 };
60 } // namespace Core
61 } // namespace MessageList
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 file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Nov 30 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.