File indexing completed on 2024-12-15 04:54:40
0001 /****************************************************************************** 0002 * 0003 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 * 0007 *******************************************************************************/ 0008 0009 #pragma once 0010 0011 #include <memory> 0012 #include <qglobal.h> // defines uint, at least. 0013 namespace MessageList 0014 { 0015 namespace Core 0016 { 0017 class ModelInvariantRowMapper; 0018 class ModelInvariantRowMapperPrivate; 0019 class RowShift; 0020 0021 /** 0022 * An invariant index that can be ALWAYS used to reference 0023 * an item inside a QAbstractItemModel. 0024 * 0025 * This class is meant to be used together with ModelInvariantRowMapper. 0026 */ 0027 class ModelInvariantIndex 0028 { 0029 friend class ModelInvariantRowMapper; 0030 friend class ModelInvariantRowMapperPrivate; 0031 friend class RowShift; 0032 0033 public: 0034 explicit ModelInvariantIndex(); 0035 virtual ~ModelInvariantIndex(); 0036 0037 public: 0038 /** 0039 * Returns true if this ModelInvariantIndex is valid, that is, it has been attached 0040 * to a ModelInvariantRowMapper. Returns false otherwise. 0041 * An invalid index will always map to the current row -1 (which is invalid as QModelIndex row). 0042 */ 0043 [[nodiscard]] bool isValid() const; 0044 0045 /** 0046 * Returns the current model index row for this invariant index. This function 0047 * calls the mapper and asks it to perform the persistent mapping. 0048 * If this index isn't valid then the returned value is -1. 0049 * 0050 * If you actually own the row mapper then you may save some clock cycles 0051 * by calling the modelInvariantIndexToModelIndexRow() by your own. If you don't 0052 * own the mapper then this function is the only way to go. 0053 */ 0054 [[nodiscard]] int currentModelIndexRow(); 0055 0056 private: 0057 class ModelInvariantIndexPrivate; 0058 std::unique_ptr<ModelInvariantIndexPrivate> const d; 0059 }; 0060 } // namespace Core 0061 } // namespace MessageList