File indexing completed on 2024-05-12 16:39:55
0001 /* This file is part of the KDE project 0002 Copyright (C) 2011 Jarosław Staniek <staniek@kde.org> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this program; see the file COPYING. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KexiCategorizedView.h" 0021 0022 KexiCategoryDrawer::KexiCategoryDrawer(KCategorizedView *view) 0023 : KexiCategoryDrawerBase(view) 0024 { 0025 } 0026 0027 // ---- 0028 0029 KexiCategorySingleSelectionModel::KexiCategorySingleSelectionModel(QAbstractItemModel* model) 0030 : QItemSelectionModel(model) 0031 { 0032 } 0033 0034 void KexiCategorySingleSelectionModel::select(const QItemSelection& selection, 0035 QItemSelectionModel::SelectionFlags command) 0036 { 0037 // qDebug() << selection.indexes().count() << command; 0038 if ((command & QItemSelectionModel::Select) && 0039 !(command & QItemSelectionModel::Clear) && 0040 (selection.indexes().count() > 1 || !this->selection().indexes().isEmpty())) 0041 { 0042 return; 0043 } 0044 QItemSelectionModel::select(selection, command); 0045 } 0046 0047 // ---- 0048 0049 KexiCategorizedView::KexiCategorizedView(QWidget *parent) 0050 : KCategorizedView(parent) 0051 { 0052 setSelectionMode(QAbstractItemView::SingleSelection); 0053 setMouseTracking(true); 0054 setViewMode(QListView::IconMode); 0055 setResizeMode(QListView::Adjust); 0056 KexiCategoryDrawer* categoryDrawer = new KexiCategoryDrawer(this); 0057 setCategoryDrawer(categoryDrawer); 0058 } 0059 0060 void KexiCategorizedView::setModel(QAbstractItemModel *model) 0061 { 0062 KCategorizedView::setModel(model); 0063 setSelectionModel(new KexiCategorySingleSelectionModel(model)); 0064 } 0065