From 0066a1fa5e353ef833960ed443013a471f05e181 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Thu, 19 Jun 2008 16:51:11 +0000 Subject: [PATCH] * ./hurricane/src/hinspector : - No more extra arguments in HInspectorWidget & RecordModel constructors. Valid values have to be sets through setRootRecord() & setSlot(). - Key for forking sub-inspector is now *minus* 'o'. --- hurricane/src/hviewer/CellViewer.cpp | 3 +- hurricane/src/hviewer/HInspectorWidget.cpp | 53 +++++++++---------- hurricane/src/hviewer/RecordModel.cpp | 14 ++--- .../hurricane/viewer/HInspectorWidget.h | 3 +- .../hviewer/hurricane/viewer/RecordModel.h | 2 +- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/hurricane/src/hviewer/CellViewer.cpp b/hurricane/src/hviewer/CellViewer.cpp index fb7e54a0..b3084bbc 100644 --- a/hurricane/src/hviewer/CellViewer.cpp +++ b/hurricane/src/hviewer/CellViewer.cpp @@ -165,7 +165,8 @@ namespace Hurricane { //cerr << "Inspector created." << endl; if ( record ) { - HInspectorWidget* inspector = new HInspectorWidget ( record ); + HInspectorWidget* inspector = new HInspectorWidget (); + inspector->setRootRecord ( record ); inspector->show (); } else cerr << "[ERROR] Attempt to run Inspector on NULL record." << endl; diff --git a/hurricane/src/hviewer/HInspectorWidget.cpp b/hurricane/src/hviewer/HInspectorWidget.cpp index cba47ae5..1cb8fff3 100644 --- a/hurricane/src/hviewer/HInspectorWidget.cpp +++ b/hurricane/src/hviewer/HInspectorWidget.cpp @@ -129,14 +129,13 @@ namespace Hurricane { - HInspectorWidget::HInspectorWidget ( Record* rootRecord, QWidget* parent ) + HInspectorWidget::HInspectorWidget ( QWidget* parent ) : QWidget(parent) , _recordModel(NULL) , _sortModel(NULL) , _historyComboBox(NULL) , _slotsView(NULL) , _rowHeight(20) - , _rootRecord(rootRecord) , _history() { setAttribute ( Qt::WA_DeleteOnClose ); @@ -157,23 +156,7 @@ namespace Hurricane { verticalHeader->setVisible ( false ); _historyComboBox = new QComboBox ( this ); - _history.setComboBox ( _historyComboBox ); - _history.setRootRecord ( _rootRecord ); - - _recordModel = new RecordModel ( _history.getSlot(), this ); - _sortModel = new QSortFilterProxyModel ( this ); - _sortModel->setSourceModel ( _recordModel ); - _sortModel->setDynamicSortFilter ( true ); - _sortModel->setFilterKeyColumn ( 1 ); - - _slotsView->setModel ( _sortModel ); - _slotsView->horizontalHeader()->setStretchLastSection ( true ); - _slotsView->resizeColumnToContents ( 0 ); - - int rows = _sortModel->rowCount (); - for ( rows-- ; rows >= 0 ; rows-- ) - _slotsView->setRowHeight ( rows, _rowHeight ); - _slotsView->selectRow ( 0 ); + _history.setComboBox ( _historyComboBox ); _filterPatternLineEdit = new QLineEdit(this); QLabel* filterPatternLabel = new QLabel(tr("&Filter pattern:"), this); @@ -187,7 +170,6 @@ namespace Hurricane { setLayout ( inspectorLayout ); - connect ( _historyComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(historyChanged(int)) ); connect ( _filterPatternLineEdit, SIGNAL(textChanged(const QString &)) , this , SLOT(textFilterChanged()) ); @@ -199,17 +181,33 @@ namespace Hurricane { HInspectorWidget::~HInspectorWidget () { - //cerr << "HInspectorWidget::~HInspectorWidget()" << endl; - //cerr << "Records: " << Record::getAllocateds() << endl; - //cerr << "Slots: " << Slot::getAllocateds() << endl; + cerr << "HInspectorWidget::~HInspectorWidget()" << endl; + cerr << "Records: " << Record::getAllocateds() << endl; + cerr << "Slots: " << Slot::getAllocateds() << endl; } void HInspectorWidget::setRootRecord ( Record* record ) { _history.setRootRecord ( record ); - _recordModel->setSlot ( _history.getSlot(), _history.getDepth() ); - _slotsView->selectRow ( 0 ); + + if ( !_recordModel ) { + _recordModel = new RecordModel ( this ); + _sortModel = new QSortFilterProxyModel ( this ); + _sortModel->setSourceModel ( _recordModel ); + _sortModel->setDynamicSortFilter ( true ); + _sortModel->setFilterKeyColumn ( 1 ); + + _slotsView->setModel ( _sortModel ); + _slotsView->horizontalHeader()->setStretchLastSection ( true ); + _slotsView->resizeColumnToContents ( 0 ); + + // Only after creating the RecordModel can we connect the ComboBox. + connect ( _historyComboBox, SIGNAL(currentIndexChanged(int)) + , this , SLOT(historyChanged(int)) ); + } + + setSlot (); } @@ -263,7 +261,7 @@ namespace Hurricane { } } else if ( event->key() == Qt::Key_Left ) { back (); - } else if ( event->key() == Qt::Key_O ) { + } else if ( event->key() == Qt::Key_o ) { forkInspector ( _slotsView->currentIndex() ); } else { event->ignore(); @@ -291,7 +289,8 @@ namespace Hurricane { Record* record = slot->getDataRecord(); if ( record ) { - HInspectorWidget* fork = new HInspectorWidget ( record ); + HInspectorWidget* fork = new HInspectorWidget (); + fork->setRootRecord ( record ); fork->show (); } } diff --git a/hurricane/src/hviewer/RecordModel.cpp b/hurricane/src/hviewer/RecordModel.cpp index 60316b6d..ef30b366 100644 --- a/hurricane/src/hviewer/RecordModel.cpp +++ b/hurricane/src/hviewer/RecordModel.cpp @@ -10,10 +10,10 @@ namespace Hurricane { - RecordModel::RecordModel ( Slot* slot, QObject* parent ) + RecordModel::RecordModel ( QObject* parent ) : QAbstractTableModel(parent) - , _slot(slot) - , _record(slot->getDataRecord()) + , _slot(NULL) + , _record(NULL) , _depth(0) { } @@ -35,9 +35,8 @@ namespace Hurricane { emit layoutAboutToBeChanged (); - if ( _depth ) - delete _record; - delete _slot; + if ( _depth ) delete _record; + if ( _slot ) delete _slot; _slot = slot; _record = record; @@ -100,7 +99,8 @@ namespace Hurricane { int RecordModel::rowCount ( const QModelIndex& parent ) const { - return _record->_getSlotList().size(); + + return (_record) ? _record->_getSlotList().size() : 0; } diff --git a/hurricane/src/hviewer/hurricane/viewer/HInspectorWidget.h b/hurricane/src/hviewer/hurricane/viewer/HInspectorWidget.h index 790f2014..e2118ba5 100644 --- a/hurricane/src/hviewer/hurricane/viewer/HInspectorWidget.h +++ b/hurricane/src/hviewer/hurricane/viewer/HInspectorWidget.h @@ -53,7 +53,7 @@ namespace Hurricane { Q_OBJECT; public: - HInspectorWidget ( Record* rootRecord, QWidget* parent=NULL ); + HInspectorWidget ( QWidget* parent=NULL ); ~HInspectorWidget (); void setRootRecord ( Record* record ); private slots: @@ -75,7 +75,6 @@ namespace Hurricane { QTableView* _slotsView; QLineEdit* _filterPatternLineEdit; int _rowHeight; - Record* _rootRecord; History _history; }; diff --git a/hurricane/src/hviewer/hurricane/viewer/RecordModel.h b/hurricane/src/hviewer/hurricane/viewer/RecordModel.h index 9eeb3a50..11677984 100644 --- a/hurricane/src/hviewer/hurricane/viewer/RecordModel.h +++ b/hurricane/src/hviewer/hurricane/viewer/RecordModel.h @@ -14,7 +14,7 @@ namespace Hurricane { Q_OBJECT; public: - RecordModel ( Slot* slot, QObject* parent=NULL ); + RecordModel ( QObject* parent=NULL ); ~RecordModel (); bool setSlot ( Slot* slot, size_t depth ); int rowCount ( const QModelIndex& parent=QModelIndex() ) const;