class library: Spawner - don't access PriorityQueue-array
[supercollider.git] / QtCollider / widgets / QcTreeWidget.h
blob4e434714251210c2d8cf910ba9b5bf73df20b8c9
1 /************************************************************************
3 * Copyright 2011 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #ifndef QC_TREE_WIDGET_H
23 #define QC_TREE_WIDGET_H
25 #include "../Common.h"
26 #include "../QObjectProxy.h"
27 #include "../safeptr.hpp"
29 #include <VMGlobals.h>
30 #include <PyrObject.h>
32 #include <QTreeWidget>
33 #include <QTreeWidgetItem>
34 #include <QApplication>
36 using namespace QtCollider;
38 class QcTreeWidget : public QTreeWidget
40 public:
42 class Item : public QTreeWidgetItem
44 public:
45 enum { Type = QTreeWidgetItem::UserType };
46 Item()
47 : QTreeWidgetItem( Item::Type ), _safePtr(this) {}
48 Item( const QStringList & strings )
49 : QTreeWidgetItem( strings, Item::Type ), _safePtr(this) {}
50 ~Item() { _safePtr.invalidate(); }
51 SafePtr<Item> safePtr() const { return _safePtr; }
52 static SafePtr<Item> safePtr( QTreeWidgetItem* );
53 static void initialize( VMGlobals *, PyrObject *, const SafePtr<Item> & );
54 static int finalize( VMGlobals *, PyrObject * );
55 private:
56 SafePtr<Item> _safePtr;
59 typedef SafePtr<Item> ItemPtr;
61 Q_OBJECT
62 Q_PROPERTY( VariantList columns READ columns WRITE setColumns )
63 Q_PROPERTY( QcTreeWidget::ItemPtr currentItem READ currentItem WRITE setCurrentItem );
65 public:
67 Q_INVOKABLE QcTreeWidget::ItemPtr item( const QcTreeWidget::ItemPtr & parent, int index );
68 Q_INVOKABLE QcTreeWidget::ItemPtr parentItem( const QcTreeWidget::ItemPtr & );
69 Q_INVOKABLE int indexOfItem( const QcTreeWidget::ItemPtr & );
71 Q_INVOKABLE QcTreeWidget::ItemPtr addItem
72 ( const QcTreeWidget::ItemPtr & parent, const VariantList & data );
74 Q_INVOKABLE QcTreeWidget::ItemPtr insertItem
75 ( const QcTreeWidget::ItemPtr & parent, int index, const VariantList & data );
77 Q_INVOKABLE void removeItem( const QcTreeWidget::ItemPtr & );
79 Q_INVOKABLE VariantList strings( const QcTreeWidget::ItemPtr & );
80 Q_INVOKABLE void setText( const QcTreeWidget::ItemPtr &, int column, const QString & );
81 Q_INVOKABLE void setColor( const QcTreeWidget::ItemPtr &, int column, const QColor & );
82 Q_INVOKABLE void setTextColor( const QcTreeWidget::ItemPtr &, int column, const QColor & );
84 Q_INVOKABLE QWidget * itemWidget( const QcTreeWidget::ItemPtr &, int column );
85 Q_INVOKABLE void setItemWidget( const QcTreeWidget::ItemPtr &, int column, QObjectProxy * );
86 Q_INVOKABLE void removeItemWidget( const QcTreeWidget::ItemPtr &, int column );
88 Q_INVOKABLE void sort( int column, bool descending );
90 Q_SIGNALS:
92 void action();
93 void itemPressedAction();
94 void currentItemChanged();
96 public:
98 QcTreeWidget();
100 ItemPtr currentItem() const;
101 void setCurrentItem( const ItemPtr & );
103 VariantList columns() const;
104 void setColumns( const VariantList & );
106 private:
108 QTreeWidgetItem * _itemOnPress;
109 bool _emitAction;
112 Q_DECLARE_METATYPE( QcTreeWidget::ItemPtr );
114 #endif