File indexing completed on 2024-04-28 04:41:48

0001 /***************************************************************************
0002  *   Copyright (C) 2017 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 "scrollbaradapter.h"
0019 
0020 // Qt
0021 #include <QtCore/QAbstractItemModel>
0022 #include <QtQuick/QQuickItem>
0023 
0024 class ScrollBarAdapterPrivate
0025 {
0026 public:
0027     QSharedPointer<QAbstractItemModel> m_pModel;
0028     QQuickItem* m_pItem;
0029 };
0030 
0031 ScrollBarAdapter::ScrollBarAdapter(QObject* parent) : QObject(parent),
0032     d_ptr(new ScrollBarAdapterPrivate)
0033 {}
0034 
0035 ScrollBarAdapter::~ScrollBarAdapter()
0036 {
0037     delete d_ptr;
0038 }
0039 
0040 QSharedPointer<QAbstractItemModel> ScrollBarAdapter::model() const
0041 {
0042     return d_ptr->m_pModel;
0043 }
0044 
0045 void ScrollBarAdapter::setModel(QSharedPointer<QAbstractItemModel> m)
0046 {
0047     if (d_ptr->m_pModel)
0048         disconnect(d_ptr->m_pModel.data(), &QAbstractItemModel::rowsInserted,
0049             this, &ScrollBarAdapter::rowsInserted);
0050 
0051     d_ptr->m_pModel = m;
0052 
0053     connect(d_ptr->m_pModel.data(), &QAbstractItemModel::rowsInserted,
0054         this, &ScrollBarAdapter::rowsInserted);
0055 }
0056 
0057 QQuickItem* ScrollBarAdapter::target() const
0058 {
0059     return d_ptr->m_pItem;
0060 }
0061 
0062 void ScrollBarAdapter::setTarget(QQuickItem* item)
0063 {
0064     d_ptr->m_pItem = item;
0065     rowsInserted();
0066 }
0067 
0068 void ScrollBarAdapter::rowsInserted()
0069 {
0070     if (!d_ptr->m_pItem)
0071         return;
0072 
0073     //QMetaObject::invokeMethod(d_ptr->m_pItem, "positionViewAtEnd");
0074 }