Mercurial > projects > qtd
annotate examples/itemviews/customsortfiltermodel/window.d @ 282:256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
author | eldar |
---|---|
date | Fri, 16 Oct 2009 02:43:59 +0000 |
parents | 26036621830e |
children | 7a3c43424dca |
rev | line source |
---|---|
146 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | |
4 ** Contact: Qt Software Information (qt-info@nokia.com) | |
5 ** | |
6 ** This file is part of the examples of the Qt Toolkit. | |
7 ** | |
8 ** $QT_BEGIN_LICENSE:LGPL$ | |
9 ** Commercial Usage | |
10 ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 ** accordance with the Qt Commercial License Agreement provided with the | |
12 ** Software or, alternatively, in accordance with the terms contained in | |
13 ** a written agreement between you and Nokia. | |
14 ** | |
15 ** GNU Lesser General Public License Usage | |
16 ** Alternatively, this file may be used under the terms of the GNU Lesser | |
17 ** General Public License version 2.1 as published by the Free Software | |
18 ** Foundation and appearing in the file LICENSE.LGPL included in the | |
19 ** packaging of this file. Please review the following information to | |
20 ** ensure the GNU Lesser General Public License version 2.1 requirements | |
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
22 ** | |
23 ** In addition, as a special exception, Nokia gives you certain | |
24 ** additional rights. These rights are described in the Nokia Qt LGPL | |
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | |
26 ** package. | |
27 ** | |
28 ** GNU General Public License Usage | |
29 ** Alternatively, this file may be used under the terms of the GNU | |
30 ** General Public License version 3.0 as published by the Free Software | |
31 ** Foundation and appearing in the file LICENSE.GPL included in the | |
32 ** packaging of this file. Please review the following information to | |
33 ** ensure the GNU General Public License version 3.0 requirements will be | |
34 ** met: http://www.gnu.org/copyleft/gpl.html. | |
35 ** | |
36 ** If you are unsure which license is appropriate for your use, please | |
37 ** contact the sales department at qt-sales@nokia.com. | |
38 ** $QT_END_LICENSE$ | |
39 ** | |
40 ****************************************************************************/ | |
41 module window; | |
42 | |
43 | |
44 import qt.core.QAbstractItemModel; | |
45 import qt.gui.QWidget; | |
46 import qt.gui.QCheckBox; | |
47 import qt.gui.QComboBox; | |
48 import qt.gui.QDateEdit; | |
49 import qt.gui.QGroupBox; | |
50 import qt.gui.QLabel; | |
51 import qt.gui.QLineEdit; | |
52 import qt.gui.QTreeView; | |
53 import qt.gui.QHBoxLayout; | |
54 import qt.gui.QVBoxLayout; | |
55 import qt.gui.QGridLayout; | |
56 | |
213 | 57 version(D_Version2) |
58 import mysortfilterproxymodel; | |
59 else | |
60 import mysortfilterproxymodel_d1; | |
146 | 61 |
62 class Window : public QWidget | |
63 { | |
64 public: | |
65 | |
66 this() | |
67 { | |
68 proxyModel = new MySortFilterProxyModel(this); | |
69 proxyModel.setDynamicSortFilter(true); | |
70 | |
71 sourceView = new QTreeView; | |
72 sourceView.setRootIsDecorated(false); | |
73 sourceView.setAlternatingRowColors(true); | |
74 | |
75 QHBoxLayout sourceLayout = new QHBoxLayout; | |
76 | |
77 sourceLayout.addWidget(sourceView); | |
78 sourceGroupBox = new QGroupBox(tr("Original Model")); | |
79 sourceGroupBox.setLayout(sourceLayout); | |
80 | |
81 filterCaseSensitivityCheckBox = new QCheckBox(tr("Case sensitive filter")); | |
82 filterCaseSensitivityCheckBox.setChecked(true); | |
83 | |
84 filterPatternLineEdit = new QLineEdit; | |
85 filterPatternLineEdit.setText("Grace|Sports"); | |
86 | |
87 filterPatternLabel = new QLabel(tr("&Filter pattern:")); | |
88 filterPatternLabel.setBuddy(filterPatternLineEdit); | |
89 | |
90 filterSyntaxComboBox = new QComboBox; | |
91 filterSyntaxComboBox.addItem(tr("Regular expression"), new QVariant(cast(ulong) QRegExp.RegExp)); | |
92 filterSyntaxComboBox.addItem(tr("Wildcard"), new QVariant(cast(ulong) QRegExp.Wildcard)); | |
93 filterSyntaxComboBox.addItem(tr("Fixed string"), new QVariant(cast(ulong) QRegExp.FixedString)); | |
94 | |
95 fromDateEdit = new QDateEdit; | |
96 fromDateEdit.setDate(new QDate(1970, 01, 01)); | |
97 fromLabel = new QLabel(tr("F&rom:")); | |
98 fromLabel.setBuddy(fromDateEdit); | |
99 | |
100 toDateEdit = new QDateEdit; | |
101 toDateEdit.setDate(new QDate(2099, 12, 31)); | |
102 toLabel = new QLabel(tr("&To:")); | |
103 toLabel.setBuddy(toDateEdit); | |
104 | |
282
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
213
diff
changeset
|
105 connect!("textChanged")(filterPatternLineEdit, &this.textFilterChanged); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
213
diff
changeset
|
106 connect!("currentIndexChanged")(filterSyntaxComboBox, &this.textFilterChanged); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
213
diff
changeset
|
107 connect!("toggled")(filterCaseSensitivityCheckBox, &this.textFilterChanged); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
213
diff
changeset
|
108 connect!("dateChanged")(fromDateEdit, &this.dateFilterChanged); |
256ab6cb8e85
Signals look-up andNew syntax for connect. The old one will not work from now on. This will allow for the signals overload. Although changes are done for both D1 and D2 versions, D1 won't work because of compiler bugs. I am tired of waiting for fixes.
eldar
parents:
213
diff
changeset
|
109 connect!("dateChanged")(toDateEdit, &this.dateFilterChanged); |
146 | 110 |
111 proxyView = new QTreeView; | |
112 proxyView.setRootIsDecorated(false); | |
113 proxyView.setAlternatingRowColors(true); | |
114 proxyView.setModel(proxyModel); | |
115 proxyView.setSortingEnabled(true); | |
116 proxyView.sortByColumn(1, Qt.AscendingOrder); | |
117 | |
118 QGridLayout proxyLayout = new QGridLayout; | |
119 proxyLayout.addWidget(proxyView, 0, 0, 1, 3); | |
120 proxyLayout.addWidget(filterPatternLabel, 1, 0); | |
121 proxyLayout.addWidget(filterPatternLineEdit, 1, 1); | |
122 proxyLayout.addWidget(filterSyntaxComboBox, 1, 2); | |
123 proxyLayout.addWidget(filterCaseSensitivityCheckBox, 2, 0, 1, 3); | |
124 proxyLayout.addWidget(fromLabel, 3, 0); | |
125 proxyLayout.addWidget(fromDateEdit, 3, 1, 1, 2); | |
126 proxyLayout.addWidget(toLabel, 4, 0); | |
127 proxyLayout.addWidget(toDateEdit, 4, 1, 1, 2); | |
128 | |
129 proxyGroupBox = new QGroupBox(tr("Sorted/Filtered Model")); | |
130 proxyGroupBox.setLayout(proxyLayout); | |
131 | |
132 QVBoxLayout mainLayout = new QVBoxLayout; | |
133 mainLayout.addWidget(sourceGroupBox); | |
134 mainLayout.addWidget(proxyGroupBox); | |
135 setLayout(mainLayout); | |
136 | |
137 setWindowTitle(tr("Custom Sort/Filter Model")); | |
138 resize(500, 450); | |
139 } | |
140 | |
141 void setSourceModel(QAbstractItemModel model) | |
142 { | |
143 proxyModel.setSourceModel(model); | |
144 sourceView.setModel(model); | |
145 } | |
146 | |
147 private: | |
148 | |
149 void textFilterChanged() | |
150 { | |
151 QRegExp.PatternSyntax syntax = cast(QRegExp.PatternSyntax) filterSyntaxComboBox.itemData( | |
152 filterSyntaxComboBox.currentIndex()).toInt(); | |
153 Qt.CaseSensitivity caseSensitivity = | |
157 | 154 filterCaseSensitivityCheckBox.isChecked() ? Qt.CaseSensitive |
155 : Qt.CaseInsensitive; | |
146 | 156 |
157 auto regExp = new QRegExp(filterPatternLineEdit.text(), caseSensitivity, syntax); | |
158 proxyModel.setFilterRegExp(regExp); | |
159 } | |
160 | |
161 void dateFilterChanged() | |
162 { | |
163 proxyModel.setFilterMinimumDate(fromDateEdit.date()); | |
164 proxyModel.setFilterMaximumDate(toDateEdit.date()); | |
165 } | |
166 | |
167 private: | |
168 | |
169 MySortFilterProxyModel proxyModel; | |
170 | |
171 QGroupBox sourceGroupBox; | |
172 QGroupBox proxyGroupBox; | |
173 QTreeView sourceView; | |
174 QTreeView proxyView; | |
175 QCheckBox filterCaseSensitivityCheckBox; | |
176 QLabel filterPatternLabel; | |
177 QLabel fromLabel; | |
178 QLabel toLabel; | |
179 QLineEdit filterPatternLineEdit; | |
180 QComboBox filterSyntaxComboBox; | |
181 QDateEdit fromDateEdit; | |
182 QDateEdit toDateEdit; | |
183 } |