| 1 | /* |
| 2 | Copyright (C) 2005-2014 Mario Stephan <[email protected]> |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU Lesser General Public License as published |
| 6 | by the Free Software Foundation; either version 2.1 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #include "collectionsetupmodel.h"cxx . . $ `<file>/src/collectionsetupmodel.h`/ |
| 19 | #include <QDirModel> |
| 20 | #include <QTreeView> |
| 21 | |
| 22 | CollectionSetupModelcxx . . $ CollectionSetupModel#::CollectionSetupModelcxx . . $ CollectionSetupModel#CollectionSetupModel(49f6e7a06ebc5aa8).() |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | Qtcxx . . $ Qt/::ItemFlagscxx . . $ Qt/ItemFlags# CollectionSetupModelcxx . . $ CollectionSetupModel#::flagscxx . . $ CollectionSetupModel#flags(36b38c1b3d3f7b45).(const QModelIndexcxx . . $ QModelIndex#& index) const |
| 27 | { |
| 28 | Qtcxx . . $ Qt/::ItemFlagscxx . . $ Qt/ItemFlags# f = QDirModelcxx . . $ QDirModel#::flagscxx . . $ QDirModel#flags(36b38c1b3d3f7b45).(index); |
| 29 | if (index.columncxx . . $ QModelIndex#column(ea6fe5115c70a13f).() == 0) // make the first column checkable |
| 30 | f |=cxx . . $ QFlags#`operator|=`(fd64b2b07d6098e0). Qtcxx . . $ Qt/::ItemIsUserCheckablecxx . . $ Qt/ItemIsUserCheckable.; |
| 31 | return f; |
| 32 | } |
| 33 | |
| 34 | QVariantcxx . . $ QVariant# CollectionSetupModelcxx . . $ CollectionSetupModel#::datacxx . . $ CollectionSetupModel#data(69b5b18a001c0029).(const QModelIndexcxx . . $ QModelIndex#& index, int role) const |
| 35 | { |
| 36 | if (index.isValidcxx . . $ QModelIndex#isValid(3482b152b9333168).() && index.columncxx . . $ QModelIndex#column(ea6fe5115c70a13f).() == 0 && role == Qtcxx . . $ Qt/::CheckStateRolecxx . . $ Qt/CheckStateRole.) { |
| 37 | // the item is checked only if we have stored its path |
| 38 | if (checkedPartiallycxx . . $ CollectionSetupModel#checkedPartially..containscxx . . $ QSet#contains(8877ebe272b9620d).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(index))) { |
| 39 | return Qtcxx . . $ QVariant#QVariant(d4f767463ce0a6b3).::PartiallyCheckedcxx . . $ Qt/PartiallyChecked.; |
| 40 | } else |
| 41 | return (cxx . . $ QVariant#QVariant(d4f767463ce0a6b3).checkedcxx . . $ CollectionSetupModel#checked..containscxx . . $ QSet#contains(8877ebe272b9620d).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(index)) ? Qtcxx . . $ Qt/::Checkedcxx . . $ Qt/Checked. : Qtcxx . . $ Qt/::Uncheckedcxx . . $ Qt/Unchecked.); |
| 42 | } |
| 43 | return QDirModelcxx . . $ QDirModel#::datacxx . . $ QDirModel#data(69b5b18a001c0029).(index, role); |
| 44 | } |
| 45 | |
| 46 | bool CollectionSetupModelcxx . . $ CollectionSetupModel#::setDatacxx . . $ CollectionSetupModel#setData(6d1d8401440d0a2c).(const QModelIndexcxx . . $ QModelIndex#& index, const QVariantcxx . . $ QVariant#& value, int role) |
| 47 | { |
| 48 | if (index.isValidcxx . . $ QModelIndex#isValid(3482b152b9333168).() && index.columncxx . . $ QModelIndex#column(ea6fe5115c70a13f).() == 0 && role == Qtcxx . . $ Qt/::CheckStateRolecxx . . $ Qt/CheckStateRole.) { |
| 49 | // store checked paths, remove unchecked paths |
| 50 | QModelIndexcxx . . $ QModelIndex# idx = parentcxx . . $ QDirModel#parent(f800c6f2fa4cbe57).(index); |
| 51 | if (value.toIntcxx . . $ QVariant#toInt(5bd9a3493f6a7a21).() == Qtcxx . . $ Qt/::Checkedcxx . . $ Qt/Checked.) { |
| 52 | checkedcxx . . $ CollectionSetupModel#checked..insertcxx . . $ QSet#insert(b1720532d625d779).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(index)); |
| 53 | // make parents always partially checked |
| 54 | while (idx.isValidcxx . . $ QModelIndex#isValid(3482b152b9333168).()) { |
| 55 | checkedPartiallycxx . . $ CollectionSetupModel#checkedPartially..insertcxx . . $ QSet#insert(b1720532d625d779).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(idx)); |
| 56 | checkedcxx . . $ CollectionSetupModel#checked..removecxx . . $ QSet#remove(fe1ba53999e710f3).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(idx)); |
| 57 | idx =cxx . . $ QModelIndex#`operator=`(4665afb3441ab1ca). idx.parentcxx . . $ QModelIndex#parent(a394cbc57608ce34).(); |
| 58 | } |
| 59 | } else { |
| 60 | checkedcxx . . $ CollectionSetupModel#checked..removecxx . . $ QSet#remove(fe1ba53999e710f3).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(index)); |
| 61 | // make parent unchecked if index was his only child |
| 62 | while (idx.isValidcxx . . $ QModelIndex#isValid(3482b152b9333168).()) { |
| 63 | bool hasChildren = false; |
| 64 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (const QString& value, checked) |
| 65 | if (value.containscxx . . $ QString#contains(8cce4688c16f48f3).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(idx))) |
| 66 | hasChildren = true; |
| 67 | if (!hasChildren) { |
| 68 | checkedPartiallycxx . . $ CollectionSetupModel#checkedPartially..removecxx . . $ QSet#remove(fe1ba53999e710f3).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(idx)); |
| 69 | checkedcxx . . $ CollectionSetupModel#checked..insertcxx . . $ QSet#insert(b1720532d625d779).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(idx)); |
| 70 | } |
| 71 | idx =cxx . . $ QModelIndex#`operator=`(4665afb3441ab1ca). idx.parentcxx . . $ QModelIndex#parent(a394cbc57608ce34).(); |
| 72 | } |
| 73 | } |
| 74 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! dataChangedcxx . . $ QAbstractItemModel#dataChanged(ae8a85c811f0c28a).(parentcxx . . $ QDirModel#parent(f800c6f2fa4cbe57).(index), index); |
| 75 | return true; |
| 76 | } |
| 77 | return QDirModelcxx . . $ QDirModel#::setDatacxx . . $ QDirModel#setData(6d1d8401440d0a2c).(index, value, role); |
| 78 | } |
| 79 | |
| 80 | QVariantcxx . . $ QVariant# CollectionSetupModelcxx . . $ CollectionSetupModel#::headerDatacxx . . $ CollectionSetupModel#headerData(b8cfec0985494997).(int section, Qtcxx . . $ Qt/::Orientationcxx . . $ Qt/Orientation# orientation, int role) const |
| 81 | { |
| 82 | if (orientation == Qtcxx . . $ Qt/::Horizontalcxx . . $ Qt/Horizontal.) { |
| 83 | if (role != Qtcxx . . $ Qt/::DisplayRolecxx . . $ Qt/DisplayRole.) |
| 84 | return QVariantcxx . . $ QVariant#QVariant(ced63f7c635d850d).(); |
| 85 | switch (section) { |
| 86 | case 0: |
| 87 | return QStringcxx . . $ QVariant#QVariant(3520e46b33348bf6).(trcxx . . $ CollectionSetupModel#tr(75d9f1c324b4579d).("Select folders for music collection")); |
| 88 | default: |
| 89 | return QVariantcxx . . $ QVariant#QVariant(ced63f7c635d850d).(); |
| 90 | } |
| 91 | } |
| 92 | return QAbstractItemModelcxx . . $ QAbstractItemModel#::headerDatacxx . . $ QAbstractItemModel#headerData(b8cfec0985494997).(section, orientation, role); |
| 93 | } |
| 94 | |
| 95 | QStringListcxx . . $ QStringList# CollectionSetupModelcxx . . $ CollectionSetupModel#::dirsCheckedcxx . . $ CollectionSetupModel#dirsChecked(669a05bc42dd57cc).() |
| 96 | { |
| 97 | QStringListcxx . . $ QStringList# listcxx . . $ QStringList#QStringList(ced63f7c635d850d).; |
| 98 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (const QString& value, checked) |
| 99 | list <<cxx . . $ QStringList#`operator<<`(85116071a693d053). value; |
| 100 | return list; |
| 101 | } |
| 102 | |
| 103 | void CollectionSetupModelcxx . . $ CollectionSetupModel#::setDirsCheckedcxx . . $ CollectionSetupModel#setDirsChecked(fc47db3ea09604d9).(QStringListcxx . . $ QStringList# list) |
| 104 | { |
| 105 | checkedcxx . . $ CollectionSetupModel#checked..clearcxx . . $ QSet#clear(49f6e7a06ebc5aa8).(); |
| 106 | checkedPartiallycxx . . $ CollectionSetupModel#checkedPartially..clearcxx . . $ QSet#clear(49f6e7a06ebc5aa8).(); |
| 107 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (const QString& value, list) { |
| 108 | /* index parents Qt::PartiallyChecked */ |
| 109 | QModelIndexcxx . . $ QModelIndex# idx = parentcxx . . $ QDirModel#parent(f800c6f2fa4cbe57).(indexcxx . . $ QDirModel#index(bdc49d3b19f4529).(value)); |
| 110 | while (idx.isValidcxx . . $ QModelIndex#isValid(3482b152b9333168).()) { |
| 111 | checkedPartiallycxx . . $ CollectionSetupModel#checkedPartially..insertcxx . . $ QSet#insert(b1720532d625d779).(filePathcxx . . $ QDirModel#filePath(befb4f2e1d6e417f).(idx)); |
| 112 | idx =cxx . . $ QModelIndex#`operator=`(4665afb3441ab1ca). idx.parentcxx . . $ QModelIndex#parent(a394cbc57608ce34).(); |
| 113 | } |
| 114 | checkedcxx . . $ CollectionSetupModel#checked..insertcxx . . $ QSet#insert(b1720532d625d779).(value); |
| 115 | } |
| 116 | } |