Qt Virtual Chart Table (QVCT)
COverlayBaseTree.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 // QT
20 #include <QTreeWidget>
21 #include <QWidget>
22 
23 // QVCT
25 
26 
27 //------------------------------------------------------------------------------
28 // CONSTRUCTORS / DESTRUCTOR
29 //------------------------------------------------------------------------------
30 
31 COverlayBaseTree::COverlayBaseTree( QWidget* _pqparent, const QString& _rqsName )
32  : QTreeWidget( _pqparent ), COverlay( _rqsName )
33  , bCurrentItemJustChanged( false )
34 {
35  // Tree widget
36  QTreeWidget::setRootIsDecorated( false );
37  QTreeWidget::setIndentation( 16 );
38  QTreeWidget::addTopLevelItem( this );
39  // ... signals
40  QObject::connect( this, SIGNAL( itemClicked(QTreeWidgetItem*,int) ), this, SLOT( slotItemClicked(QTreeWidgetItem*,int) ) );
41  QObject::connect( this, SIGNAL( itemDoubleClicked(QTreeWidgetItem*,int) ), this, SLOT( slotItemDoubleClicked(QTreeWidgetItem*,int) ) );
42  QObject::connect( this, SIGNAL( itemChanged(QTreeWidgetItem*,int) ), this, SLOT( slotItemChanged(QTreeWidgetItem*,int) ) );
43  QObject::connect( this, SIGNAL( currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) ), this, SLOT( slotCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) ) );
44 }
45 
46 
47 //------------------------------------------------------------------------------
48 // METHODS
49 //------------------------------------------------------------------------------
50 
51 //
52 // SLOTS
53 //
54 
55 void COverlayBaseTree::slotCurrentItemChanged( QTreeWidgetItem* _pqTreeWidgetItem, QTreeWidgetItem* _pqTreeWidgetItemPrevious )
56 {
57  showDetail( _pqTreeWidgetItem );
59 }
60 
61 void COverlayBaseTree::slotItemClicked( QTreeWidgetItem* _pqTreeWidgetItem, int _iColumn )
62 {
63  if( !bCurrentItemJustChanged ) showDetail( _pqTreeWidgetItem );
65 }
66 
67 void COverlayBaseTree::slotItemDoubleClicked( QTreeWidgetItem* _pqTreeWidgetItem, int _iColumn )
68 {
69  setPosition( _pqTreeWidgetItem );
70 }
71 
72 void COverlayBaseTree::slotItemChanged( QTreeWidgetItem* _pqTreeWidgetItem, int _iColumn )
73 {
74  onChange( _pqTreeWidgetItem, _iColumn );
75 }
76 
77 //
78 // OTHER
79 //
80 
82 {
83  // NOTE: Since 'this' is both the QTreeWidget and its top-level QTreeWidgetItem,
84  // it MUST be removed as top-level QTreeWidgetItem before the QTreeWidget
85  // is destructed (and all its children as well). Failure to do so would
86  // result in the QTreeWidget destructing itself (and lead to segmentation
87  // fault on application exit).
88  QTreeWidget::takeTopLevelItem( 0 ); // this
89 }
void slotItemChanged(QTreeWidgetItem *_pqTreeWidgetItem, int _iColumn)
Slot to handle item (content) changes in the underlying QTreeWidget.
void slotItemDoubleClicked(QTreeWidgetItem *_pqTreeWidgetItem, int _iColumn)
Slot to handle item double-click in the underlying QTreeWidget.
void destroy()
Prepare the underlying QTreeWidget for destruction.
bool bCurrentItemJustChanged
Flag to track when the focused item just changed.
COverlayBaseTree(QWidget *_pqParent, const QString &_rqsName)
void slotItemClicked(QTreeWidgetItem *_pqTreeWidgetItem, int _iColumn)
Slot to handle item click in the underlying QTreeWidget.
void slotCurrentItemChanged(QTreeWidgetItem *_pqTreeWidgetItem, QTreeWidgetItem *_pqTreeWidgetItemPrevious)
Slot to handle current item changes in the underlying QTreeWidget.
virtual void onChange(QTreeWidgetItem *_pqTreeWidgetItem, int __iColumn)=0
Handles item (content) changes in the underlying QTreeWidget.
Generic overlay.
Definition: COverlay.hpp:45
virtual void setPosition(const QTreeWidgetItem *_pqTreeWidgetItem) const =0
Centers the chart on the given overlay object's position.
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const =0
Displays the given overlay object's details (in the appropriate widget/view)