2
/* BEGIN_COMMON_COPYRIGHT_HEADER
4
* TOra - An Oracle Toolkit for DBA's and developers
6
* Shared/mixed copyright is held throughout files in this product
8
* Portions Copyright (C) 2000-2001 Underscore AB
9
* Portions Copyright (C) 2003-2005 Quest Software, Inc.
10
* Portions Copyright (C) 2004-2008 Numerous Other Contributors
12
* This program is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; only version 2 of
15
* the License is valid for this program.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
* As a special exception, you have permission to link this program
27
* with the Oracle Client libraries and distribute executables, as long
28
* as you follow the requirements of the GNU GPL in regard to all of the
29
* software in the executable aside from Oracle client libraries.
31
* Specifically you are not permitted to link this program with the
32
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
33
* And you are not permitted to distribute binaries compiled against
36
* You may link this product with any GPL'd Qt library.
38
* All trademarks belong to their respective owners.
40
* END_COMMON_COPYRIGHT_HEADER */
43
#include "totreewidget.h"
45
#include <QTreeWidget>
46
#include <QTreeWidgetItem>
49
toTreeWidget::toTreeWidget(QWidget *parent,
58
SIGNAL(itemSelectionChanged()),
60
SLOT(handleSelectionChange()));
63
SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
65
SLOT(handleDoubleClick(QTreeWidgetItem *, int)));
68
SIGNAL(itemClicked(QTreeWidgetItem *, int)),
70
SLOT(handleClick(QTreeWidgetItem *, int)));
73
SIGNAL(itemExpanded(QTreeWidgetItem *)),
75
SLOT(handleExpanded(QTreeWidgetItem *)));
78
SIGNAL(itemCollapsed(QTreeWidgetItem *)),
80
SLOT(handleCollapsed(QTreeWidgetItem *)));
83
SIGNAL(itemActivated(QTreeWidgetItem *, int)),
85
SLOT(handleActivated(QTreeWidgetItem *, int)));
87
columnResize = NoColumn; // q3listview default
91
toTreeWidgetItem* toTreeWidget::firstChild(void) const
93
QTreeWidgetItem *it = QTreeWidget::topLevelItem(0);
95
return dynamic_cast<toTreeWidgetItem *>(it);
100
toTreeWidgetItem* toTreeWidget::currentItem(void) const
102
QTreeWidgetItem *it = QTreeWidget::currentItem();
104
return dynamic_cast<toTreeWidgetItem *>(it);
109
toTreeWidgetItem* toTreeWidget::selectedItem(void) const
111
QList<QTreeWidgetItem *> items = QTreeWidget::selectedItems();
113
// just return the first item. widgets requiring multiple
114
// selection support should be modified to use selectedItems()
115
if (items.size() > 0)
116
return dynamic_cast<toTreeWidgetItem *>(items.at(0));
121
toTreeWidgetItem* toTreeWidget::itemAt(const QPoint &viewPos) const
123
QTreeWidgetItem *it = QTreeWidget::itemAt(viewPos);
125
return dynamic_cast<toTreeWidgetItem *>(it);
130
void toTreeWidget::setSorting(int column, bool ascending)
134
QTreeWidget::setSortingEnabled(false);
138
QTreeWidget::setSortingEnabled(true);
139
QTreeWidget::sortByColumn(column,
142
Qt::DescendingOrder);
146
const int toTreeWidget::columns(void)
148
return QTreeWidget::columnCount();
152
int toTreeWidget::addColumn(const QString &label, int width)
154
QTreeWidgetItem *head = QTreeWidget::headerItem();
158
int index = head->columnCount();
160
// dirty, dirty hack.
162
// QTreeWidget appears to always have at least one column. you're
163
// meant to add columns by using setHeaderLabels() but this is a
166
// check if we have just 1 column and it's name is "1" and then
168
if (index == 1 && head->text(0) == "1")
169
index = 0; // don't add
171
head->setText(index, label);
176
void toTreeWidget::setSelectionMode(SelectionMode mode)
181
QTreeWidget::setSelectionMode(QAbstractItemView::MultiSelection);
185
QTreeWidget::setSelectionMode(QAbstractItemView::ExtendedSelection);
189
QTreeWidget::setSelectionMode(QAbstractItemView::NoSelection);
193
QTreeWidget::setSelectionMode(QAbstractItemView::SingleSelection);
198
int toTreeWidget::selectionMode() const
200
switch (QTreeWidget::selectionMode())
202
case QAbstractItemView::MultiSelection:
205
case QAbstractItemView::ExtendedSelection:
208
case QAbstractItemView::NoSelection:
211
case QAbstractItemView::SingleSelection:
214
case QAbstractItemView::ContiguousSelection:
223
void toTreeWidget::takeItem(toTreeWidgetItem *it)
225
int pos = QTreeWidget::indexOfTopLevelItem(it);
229
QTreeWidget::takeTopLevelItem(pos);
233
void toTreeWidget::setColumnAlignment(int column, int align)
239
int toTreeWidget::itemMargin() const
245
void toTreeWidget::setTreeStepSize(int i)
251
int toTreeWidget::childCount(void) const
253
return QTreeWidget::topLevelItemCount();
257
void toTreeWidget::resizeColumnsToContents(void)
259
for (int col = 0; col < QTreeWidget::columnCount(); col++)
260
QTreeWidget::resizeColumnToContents(col);
264
void toTreeWidget::setResizeMode(ResizeMode m)
268
if (columnResize == NoColumn)
271
if (columnResize == AllColumns)
272
resizeColumnsToContents();
274
// qtreewidget will by default allow the last column the most
276
if (columnResize == LastColumn)
277
resizeColumnsToContents();
281
toTreeWidget::ResizeMode toTreeWidget::resizeMode() const
287
void toTreeWidget::setColumnWidthMode(int column, toTreeWidget::WidthMode)
293
void toTreeWidget::sort(void)
299
int toTreeWidget::visibleHeight(void)
305
void toTreeWidget::setSelected(toTreeWidgetItem* item, bool selected)
307
item->setSelected(selected);
311
void toTreeWidget::ensureItemVisible(const toTreeWidgetItem *tree)
313
QTreeWidget::scrollToItem(tree);
317
void toTreeWidget::setOpen(bool o)
319
int count = toTreeWidget::topLevelItemCount();
320
for (int i = 0; i < count; i++)
321
QTreeWidget::topLevelItem(i)->setExpanded(o);
325
void toTreeWidget::setOpen(toTreeWidgetItem *item, bool o)
327
item->setExpanded(o);
331
void toTreeWidget::repaintItem(const QTreeWidgetItem *it) const
337
void toTreeWidget::setShowSortIndicator(bool show)
343
QString toTreeWidget::columnText(int column) const
345
return QTreeWidget::headerItem()->text(column);
349
QModelIndex toTreeWidget::indexFromItem(QTreeWidgetItem *item,
352
return QTreeWidget::indexFromItem(item, column);
356
QTreeWidgetItem* toTreeWidget::itemFromIndex(const QModelIndex &index) const
358
return QTreeWidget::itemFromIndex(index);
362
void toTreeWidget::selectAll(bool s)
365
QTreeWidget::clearSelection();
367
QTreeWidget::selectAll();
371
void toTreeWidget::updateContents()
377
void toTreeWidget::handleSelectionChange()
379
QList<QTreeWidgetItem *> s = QTreeWidget::selectedItems();
381
emit selectionChanged(dynamic_cast<toTreeWidgetItem *>(s.at(0)));
383
emit selectionChanged();
387
void toTreeWidget::handleDoubleClick(QTreeWidgetItem *item, int column)
389
if (!item || column < 0)
391
emit doubleClicked(dynamic_cast<toTreeWidgetItem *>(item));
395
void toTreeWidget::handleClick(QTreeWidgetItem *item, int column)
397
if (!item || column < 0)
399
emit clicked(dynamic_cast<toTreeWidgetItem *>(item));
403
void toTreeWidget::handleExpanded(QTreeWidgetItem *item)
406
emit(expanded(dynamic_cast<toTreeWidgetItem *>(item)));
410
void toTreeWidget::handleCollapsed(QTreeWidgetItem *item)
413
emit(collapsed(dynamic_cast<toTreeWidgetItem *>(item)));
417
void toTreeWidget::handleActivated(QTreeWidgetItem *item, int column)
420
emit(returnPressed(dynamic_cast<toTreeWidgetItem *>(item)));
424
void toTreeWidget::clear(void)
426
QTreeWidget::clear();
430
// -------------------------------------------------- item
432
toTreeWidgetItem::toTreeWidgetItem(QTreeWidget *parent)
433
: QTreeWidgetItem(parent, QTreeWidgetItem::Type)
438
toTreeWidgetItem::toTreeWidgetItem(QTreeWidget *parent, toTreeWidgetItem *after)
439
: QTreeWidgetItem(parent, after, QTreeWidgetItem::Type)
444
toTreeWidgetItem::toTreeWidgetItem(toTreeWidget *parent,
445
const QString &label0,
446
const QString &label1,
447
const QString &label2,
448
const QString &label3,
449
const QString &label4,
450
const QString &label5,
451
const QString &label6,
452
const QString &label7)
453
: QTreeWidgetItem(parent, QTreeWidgetItem::Type)
455
if (!label0.isNull())
457
if (!label1.isNull())
459
if (!label2.isNull())
461
if (!label3.isNull())
463
if (!label4.isNull())
465
if (!label5.isNull())
467
if (!label6.isNull())
469
if (!label7.isNull())
474
toTreeWidgetItem::toTreeWidgetItem(toTreeWidget *parent,
475
toTreeWidgetItem *after,
476
const QString &label0,
477
const QString &label1,
478
const QString &label2,
479
const QString &label3,
480
const QString &label4,
481
const QString &label5,
482
const QString &label6,
483
const QString &label7)
484
: QTreeWidgetItem(parent, after, QTreeWidgetItem::Type)
486
if (!label0.isNull())
488
if (!label1.isNull())
490
if (!label2.isNull())
492
if (!label3.isNull())
494
if (!label4.isNull())
496
if (!label5.isNull())
498
if (!label6.isNull())
500
if (!label7.isNull())
505
toTreeWidgetItem::toTreeWidgetItem(toTreeWidgetItem *parent,
506
toTreeWidgetItem *after,
507
const QString &label0,
508
const QString &label1,
509
const QString &label2,
510
const QString &label3,
511
const QString &label4,
512
const QString &label5,
513
const QString &label6,
514
const QString &label7)
515
: QTreeWidgetItem(parent, after, QTreeWidgetItem::Type)
517
if (!label0.isNull())
519
if (!label1.isNull())
521
if (!label2.isNull())
523
if (!label3.isNull())
525
if (!label4.isNull())
527
if (!label5.isNull())
529
if (!label6.isNull())
531
if (!label7.isNull())
536
toTreeWidgetItem::toTreeWidgetItem(toTreeWidgetItem *parent,
537
const QString &label0,
538
const QString &label1,
539
const QString &label2,
540
const QString &label3,
541
const QString &label4,
542
const QString &label5,
543
const QString &label6,
544
const QString &label7)
545
: QTreeWidgetItem(parent, QTreeWidgetItem::Type)
547
if (!label0.isNull())
549
if (!label1.isNull())
551
if (!label2.isNull())
553
if (!label3.isNull())
555
if (!label4.isNull())
557
if (!label5.isNull())
559
if (!label6.isNull())
561
if (!label7.isNull())
566
toTreeWidgetItem* toTreeWidgetItem::nextSibling() const
568
toTreeWidget *tree = dynamic_cast<toTreeWidget *>(
569
QTreeWidgetItem::treeWidget());
573
QModelIndex index = tree->indexFromItem(const_cast<toTreeWidgetItem *>(this));
574
QModelIndex sibling = index.sibling(index.row() + 1, index.column());
576
if (sibling.isValid())
577
return dynamic_cast<toTreeWidgetItem *>(tree->itemFromIndex(sibling));
583
toTreeWidgetItem* toTreeWidgetItem::firstChild() const
585
if (QTreeWidgetItem::childCount() > 0)
586
return dynamic_cast<toTreeWidgetItem *>(QTreeWidgetItem::child(0));
591
toTreeWidgetItem* toTreeWidgetItem::parent() const
593
QTreeWidgetItem *p = QTreeWidgetItem::parent();
595
return dynamic_cast<toTreeWidgetItem *>(p);
600
toTreeWidget* toTreeWidgetItem::listView() const
602
return dynamic_cast<toTreeWidget *>(QTreeWidgetItem::treeWidget());
606
toTreeWidgetItem* toTreeWidgetItem::itemAbove() const
612
toTreeWidgetItem* toTreeWidgetItem::itemBelow() const
618
int toTreeWidgetItem::width(const QFontMetrics &fm,
619
const toTreeWidget *lv,
626
int toTreeWidgetItem::height()
632
bool toTreeWidgetItem::isOpen(void) const
634
return QTreeWidgetItem::isExpanded();
638
void toTreeWidgetItem::setOpen(bool o)
640
return QTreeWidgetItem::setExpanded(o);
644
void toTreeWidgetItem::setPixmap(int col, const QPixmap &pix)
646
QTreeWidgetItem::setIcon(col, QIcon(pix));
650
void toTreeWidgetItem::setSelectable(bool enable)
652
// xor out the selectable flag
653
Qt::ItemFlags fl = QTreeWidgetItem::flags() ^ Qt::ItemIsSelectable;
654
QTreeWidgetItem::setFlags(fl);
658
void toTreeWidgetItem::moveItem(toTreeWidgetItem *after)
664
void toTreeWidgetItem::setEnabled(bool b)
666
Qt::ItemFlags fl = QTreeWidgetItem::flags();
669
// xor out the enabled flag
670
fl = fl ^ Qt::ItemIsEnabled;
675
fl = fl | Qt::ItemIsEnabled;
678
QTreeWidgetItem::setFlags(fl);
682
bool toTreeWidgetItem::isEnabled() const
684
return QTreeWidgetItem::flags() & Qt::ItemIsEnabled;
688
void toTreeWidgetItem::setExpandable(bool o)
692
toTreeWidgetItem::setChildIndicatorPolicy(
693
QTreeWidgetItem::DontShowIndicator);
697
toTreeWidgetItem::setChildIndicatorPolicy(
698
QTreeWidgetItem::ShowIndicator);
703
int toTreeWidgetItem::depth() const
705
QTreeWidgetItem *parent;
707
while ((parent = QTreeWidgetItem::parent()) != NULL)
714
// -------------------------------------------------- check item
716
toTreeWidgetCheck::toTreeWidgetCheck(toTreeWidget *parent,
719
: toTreeWidgetItem(parent, text)
725
toTreeWidgetCheck::toTreeWidgetCheck(toTreeWidgetItem *parent,
728
: toTreeWidgetItem(parent, text)
734
toTreeWidgetCheck::toTreeWidgetCheck(toTreeWidget *parent,
735
toTreeWidgetItem *after,
738
: toTreeWidgetItem(parent, after, text)
744
toTreeWidgetCheck::toTreeWidgetCheck(toTreeWidgetItem *parent,
745
toTreeWidgetItem *after,
748
: toTreeWidgetItem(parent, after, text)
754
bool toTreeWidgetCheck::isOn() const
756
return checkState(0) == Qt::Checked;
760
void toTreeWidgetCheck::setOn(bool b)
762
setCheckState(0, b ? Qt::Checked : Qt::Unchecked);