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