File indexing completed on 2023-09-24 12:27:42

0001 /***************************************************************************
0002  *   Copyright (C) 2019 by Emmanuel Lepage Vallee                          *
0003  *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@kde.org>             *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 3 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0017 **************************************************************************/
0018 #include "freefloatingmodel.h"
0019 
0020 struct FreeFloatingNode {
0021     QRectF  pos;
0022     QString name;
0023 };
0024 
0025 static FreeFloatingNode ffn[3] = {
0026     {{10.0,10.0 ,10.0 ,10.0 }, "one"  },
0027     {{50.0,50.0 ,50.0 ,50.0 }, "two"  },
0028     {{0.0 ,200.0,100.0,100.0}, "three"},
0029 };
0030 
0031 bool FreeFloatingModel::setData( const QModelIndex& index, const QVariant &value, int role)
0032 {
0033     if (!index.isValid())
0034         return false;
0035 
0036     if (role == Qt::SizeHintRole) {
0037         ffn[index.row()].pos = value.toRectF();
0038         emit dataChanged(index, index);
0039         return true;
0040     }
0041 
0042     return false;
0043 }
0044 
0045 QVariant FreeFloatingModel::data( const QModelIndex& index, int role) const
0046 {
0047     if (!index.isValid())
0048         return {};
0049 
0050     if (role == Qt::DisplayRole)
0051         return ffn[index.row()].name;
0052     else if (role == Qt::SizeHintRole)
0053         return ffn[index.row()].pos;
0054 
0055     return {};
0056 }
0057 
0058 int FreeFloatingModel::rowCount( const QModelIndex& parent) const
0059 {
0060     return parent.isValid() ? 0 : 3;
0061 }