Mercurial > projects > qtd
changeset 209:3f024154460c
file rename for interview demo
author | eldar |
---|---|
date | Tue, 14 Jul 2009 09:52:28 +0000 |
parents | be08f1b4ba39 |
children | 3ea0efe4d31e |
files | demos/interview/main.d demos/interview/model.d demos/interview/model_d1.d demos/interview/model_d2.d |
diffstat | 4 files changed, 208 insertions(+), 208 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/interview/main.d Tue Jul 14 09:34:48 2009 +0000 +++ b/demos/interview/main.d Tue Jul 14 09:52:28 2009 +0000 @@ -35,9 +35,9 @@ ** ****************************************************************************/ version(D_Version2) - import model_d2; + import model; else - import model; + import model_d1; import qt.gui.QApplication; import qt.gui.QItemSelectionModel;
--- a/demos/interview/model.d Tue Jul 14 09:34:48 2009 +0000 +++ b/demos/interview/model.d Tue Jul 14 09:52:28 2009 +0000 @@ -35,7 +35,7 @@ ** ****************************************************************************/ -module model; +module model_d2; import qt.gui.QIcon; import qt.gui.QPixmap; @@ -45,10 +45,9 @@ import qt.core.QVariant; import qt.core.QModelIndex; -import tango.core.Array; -import Integer = tango.text.convert.Integer; +import std.conv; //, std.algorithm; +import std.stdio; - class Node { this(Node parent_ = null) @@ -59,7 +58,16 @@ Node parent; Node[] children; } - + +size_t find(Node[] arr, Node elem) +{ + size_t res = arr.length; + for(size_t i = 0; i < arr.length; i++) + if (arr[i] is elem) + res = i; + return res; +} + class Model : QAbstractItemModel { @@ -81,18 +89,18 @@ } - override QModelIndex index(int row, int column, QModelIndex parent) + override QModelIndex index(int row, int column, const QModelIndex parent) { if (row < rc && row >= 0 && column < cc && column >= 0) { Node p = cast(Node) parent.internalPointer(); Node n = getNode(row, p); - if (n !is null) - return createIndex(row, column, cast(void*)n); + if (n !is null) + return createIndex(row, column, cast(void*)n); } return QModelIndex(); } - override QModelIndex parent(QModelIndex child) + override QModelIndex parent(const QModelIndex child) { if (child.isValid()) { Node n = cast(Node) child.internalPointer(); @@ -103,22 +111,22 @@ return QModelIndex(); } - override int rowCount(QModelIndex parent) + override int rowCount(const QModelIndex parent) { return (parent.isValid() && parent.column() != 0) ? 0 : rc; } - override int columnCount(QModelIndex parent) + override int columnCount(const QModelIndex parent) { return cc; } - override QVariant data(QModelIndex index, int role) + override QVariant data(const QModelIndex index, int role) { if (!index.isValid) return new QVariant; if (role == Qt.DisplayRole) - return new QVariant("Item " ~ Integer.toString(index.row) ~ ":" ~ Integer.toString(index.column)); + return new QVariant("Item " ~ to!string(index.row) ~ ":" ~ to!string(index.column)); if (role == Qt.DecorationRole) { if (index.column == 0) //return iconProvider.icon(QFileIconProvider::Folder); @@ -131,20 +139,20 @@ override QVariant headerData(int section, Qt.Orientation orientation, int role) { if (role == Qt.DisplayRole) - return new QVariant(Integer.toString(section)); + return new QVariant(to!string(section)); if (role == Qt.DecorationRole) return services.toVariant; return QAbstractItemModel.headerData(section, orientation, role); } - override bool hasChildren(QModelIndex parent) + override bool hasChildren(const QModelIndex parent) { if (parent.isValid && parent.column != 0) return false; return rc > 0 && cc > 0; } - override int flags(QModelIndex index) + override int flags(const QModelIndex index) { if (!index.isValid) return 0;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/interview/model_d1.d Tue Jul 14 09:52:28 2009 +0000 @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information +** to ensure GNU General Public Licensing requirements will be met: +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. In addition, as a special +** exception, Nokia gives you certain additional rights. These rights +** are described in the Nokia Qt GPL Exception version 1.3, included in +** the file GPL_EXCEPTION.txt in this package. +** +** Qt for Windows(R) Licensees +** As a special exception, Nokia, as the sole copyright holder for Qt +** Designer, grants users of the Qt/Eclipse Integration plug-in the +** right for the Qt/Eclipse Integration to link to functionality +** provided by Qt Designer and its related libraries. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** +****************************************************************************/ + +module model; + +import qt.gui.QIcon; +import qt.gui.QPixmap; +import qt.gui.QFileIconProvider; + +import qt.core.QAbstractItemModel; +import qt.core.QVariant; +import qt.core.QModelIndex; + +import tango.core.Array; +import Integer = tango.text.convert.Integer; + + +class Node +{ + this(Node parent_ = null) + { + parent = parent_; + } + + Node parent; + Node[] children; +} + +class Model : QAbstractItemModel +{ + + this(int rows, int columns, QObject parent = null) + { + super(parent); + rc = rows; + cc = columns; + tree = new Node[rows]; + foreach(ref node; tree) { + node = new Node; + } + + iconProvider = new QFileIconProvider; + + folder = iconProvider.icon(QFileIconProvider.Folder); + file = iconProvider.icon(QFileIconProvider.File); + services = new QIcon(":/images/services.png"); + } + + + override QModelIndex index(int row, int column, QModelIndex parent) + { + if (row < rc && row >= 0 && column < cc && column >= 0) { + Node p = cast(Node) parent.internalPointer(); + Node n = getNode(row, p); + if (n !is null) + return createIndex(row, column, cast(void*)n); + } + return QModelIndex(); + } + + override QModelIndex parent(QModelIndex child) + { + if (child.isValid()) { + Node n = cast(Node) child.internalPointer(); + Node p = parent(n); + if (p !is null) + return createIndex(row(p), 0, cast(void*)p); + } + return QModelIndex(); + } + + override int rowCount(QModelIndex parent) + { + return (parent.isValid() && parent.column() != 0) ? 0 : rc; + } + + override int columnCount(QModelIndex parent) + { + return cc; + } + + override QVariant data(QModelIndex index, int role) + { + if (!index.isValid) + return new QVariant; + if (role == Qt.DisplayRole) + return new QVariant("Item " ~ Integer.toString(index.row) ~ ":" ~ Integer.toString(index.column)); + if (role == Qt.DecorationRole) { + if (index.column == 0) + //return iconProvider.icon(QFileIconProvider::Folder); + return folder.toVariant; + return file.toVariant; + } + return new QVariant; + } + + override QVariant headerData(int section, Qt.Orientation orientation, int role) + { + if (role == Qt.DisplayRole) + return new QVariant(Integer.toString(section)); + if (role == Qt.DecorationRole) + return services.toVariant; + return QAbstractItemModel.headerData(section, orientation, role); + } + + override bool hasChildren(QModelIndex parent) + { + if (parent.isValid && parent.column != 0) + return false; + return rc > 0 && cc > 0; + } + + override int flags(QModelIndex index) + { + if (!index.isValid) + return 0; + return (Qt.ItemIsDragEnabled | Qt.ItemIsSelectable | Qt.ItemIsEnabled); + } + + Node getNode(int row, Node parent) + { + if(parent !is null && parent.children.length == 0) { + for(int i = 0; i < rc; i++) + parent.children ~= new Node(parent); + } + + Node[] v = parent !is null ? parent.children : tree; + return v[row]; + } + + Node parent(Node child) + { + return child !is null ? child.parent : null; + } + + int row(Node node) + { + Node[] v = node.parent !is null ? node.parent.children : tree; + return find(v, node); + } + + + int rc, cc; + Node[] tree; + QFileIconProvider iconProvider; + + QIcon folder, services, file; +}
--- a/demos/interview/model_d2.d Tue Jul 14 09:34:48 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,190 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information -** to ensure GNU General Public Licensing requirements will be met: -** http://www.fsf.org/licensing/licenses/info/GPLv2.html and -** http://www.gnu.org/copyleft/gpl.html. In addition, as a special -** exception, Nokia gives you certain additional rights. These rights -** are described in the Nokia Qt GPL Exception version 1.3, included in -** the file GPL_EXCEPTION.txt in this package. -** -** Qt for Windows(R) Licensees -** As a special exception, Nokia, as the sole copyright holder for Qt -** Designer, grants users of the Qt/Eclipse Integration plug-in the -** right for the Qt/Eclipse Integration to link to functionality -** provided by Qt Designer and its related libraries. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** -****************************************************************************/ - -module model_d2; - -import qt.gui.QIcon; -import qt.gui.QPixmap; -import qt.gui.QFileIconProvider; - -import qt.core.QAbstractItemModel; -import qt.core.QVariant; -import qt.core.QModelIndex; - -import std.conv; //, std.algorithm; -import std.stdio; - -class Node -{ - this(Node parent_ = null) - { - parent = parent_; - } - - Node parent; - Node[] children; -} - -size_t find(Node[] arr, Node elem) -{ - size_t res = arr.length; - for(size_t i = 0; i < arr.length; i++) - if (arr[i] is elem) - res = i; - return res; -} - -class Model : QAbstractItemModel -{ - - this(int rows, int columns, QObject parent = null) - { - super(parent); - rc = rows; - cc = columns; - tree = new Node[rows]; - foreach(ref node; tree) { - node = new Node; - } - - iconProvider = new QFileIconProvider; - - folder = iconProvider.icon(QFileIconProvider.Folder); - file = iconProvider.icon(QFileIconProvider.File); - services = new QIcon(":/images/services.png"); - } - - - override QModelIndex index(int row, int column, const QModelIndex parent) - { - if (row < rc && row >= 0 && column < cc && column >= 0) { - Node p = cast(Node) parent.internalPointer(); - Node n = getNode(row, p); - if (n !is null) - return createIndex(row, column, cast(void*)n); - } - return QModelIndex(); - } - - override QModelIndex parent(const QModelIndex child) - { - if (child.isValid()) { - Node n = cast(Node) child.internalPointer(); - Node p = parent(n); - if (p !is null) - return createIndex(row(p), 0, cast(void*)p); - } - return QModelIndex(); - } - - override int rowCount(const QModelIndex parent) - { - return (parent.isValid() && parent.column() != 0) ? 0 : rc; - } - - override int columnCount(const QModelIndex parent) - { - return cc; - } - - override QVariant data(const QModelIndex index, int role) - { - if (!index.isValid) - return new QVariant; - if (role == Qt.DisplayRole) - return new QVariant("Item " ~ to!string(index.row) ~ ":" ~ to!string(index.column)); - if (role == Qt.DecorationRole) { - if (index.column == 0) - //return iconProvider.icon(QFileIconProvider::Folder); - return folder.toVariant; - return file.toVariant; - } - return new QVariant; - } - - override QVariant headerData(int section, Qt.Orientation orientation, int role) - { - if (role == Qt.DisplayRole) - return new QVariant(to!string(section)); - if (role == Qt.DecorationRole) - return services.toVariant; - return QAbstractItemModel.headerData(section, orientation, role); - } - - override bool hasChildren(const QModelIndex parent) - { - if (parent.isValid && parent.column != 0) - return false; - return rc > 0 && cc > 0; - } - - override int flags(const QModelIndex index) - { - if (!index.isValid) - return 0; - return (Qt.ItemIsDragEnabled | Qt.ItemIsSelectable | Qt.ItemIsEnabled); - } - - Node getNode(int row, Node parent) - { - if(parent !is null && parent.children.length == 0) { - for(int i = 0; i < rc; i++) - parent.children ~= new Node(parent); - } - - Node[] v = parent !is null ? parent.children : tree; - return v[row]; - } - - Node parent(Node child) - { - return child !is null ? child.parent : null; - } - - int row(Node node) - { - Node[] v = node.parent !is null ? node.parent.children : tree; - return find(v, node); - } - - - int rc, cc; - Node[] tree; - QFileIconProvider iconProvider; - - QIcon folder, services, file; -}