1 /** 2 * File name: RkModel.h 3 * Project: Redkite (A small GUI toolkit) 4 * 5 * Copyright (C) 2020 Iurie Nistor <http://iuriepage.wordpress.com> 6 * 7 * This file is part of Redkite. 8 * 9 * Redkite is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24 #ifndef RK_MODEL_H 25 #define RK_MODEL_H 26 27 #include "Rk.h" 28 #include "RkObject.h" 29 #include "RkVariant.h" 30 31 class RK_EXPORT RkModel; 32 33 class RK_EXPORT RkModelItem { 34 public: 35 enum class DataType : int { 36 String = 0, 37 Color = 1, 38 Size = 2, 39 Font = 4, 40 UserType = 5, 41 }; 42 RkModelItem(RkModel * model,size_t index)43 RkModelItem(RkModel *model, size_t index) 44 : itemModel{model} 45 , itemIndex{index} 46 { 47 } 48 49 RkVariant data(int dataType = static_cast<int>(RkModelItem::DataType::String)) const; getIndex()50 size_t getIndex() const { return itemIndex; } model()51 RkModel *model() const { return itemModel; } 52 53 private: 54 RkModel *itemModel; 55 size_t itemIndex; 56 }; 57 58 class RK_EXPORT RkModel: public RkObject { 59 public: 60 explicit RkModel(RkObject *parent); 61 virtual ~RkModel() = default; 62 RK_DECL_ACT(modelChanged, modelChanged(), RK_ARG_TYPE(), RK_ARG_VAL()); 63 RK_DECL_ACT(itemSelected, itemSelected(RkModelItem item), RK_ARG_TYPE(RkModelItem), RK_ARG_VAL(item)); 64 virtual RkVariant itemData(size_t index, int dataType = static_cast<int>(RkModelItem::DataType::String)) const = 0; 65 virtual size_t itemsNumber() const = 0; 66 virtual int itemSpan() const = 0; 67 void selectItem(size_t index); 68 bool isItemSelected(size_t index) const; 69 bool isValidIndex(size_t index) const; 70 71 protected: 72 RK_DELCATE_IMPL_PTR(RkModel); 73 74 private: 75 RK_DISABLE_COPY(RkModel); 76 RK_DISABLE_MOVE(RkModel); 77 }; 78 79 #endif // RK_MODEL_H 80