* ./hurricane/src/hurricane/DbU.{h,cpp} :

- Add forgotten converter function physicalToGrid(), physical units to
       founder grid units.

 * ./hurricane/src/hinspector :
   - Added history support, and ability to move through the history stack.
   - Fork support : by typing 'O' (capitalized 'o' letter)  you can open
       a new inspector on the current record.
This commit is contained in:
Jean-Paul Chaput 2008-06-18 12:14:19 +00:00
parent 98ece39fab
commit 62d5b757fb
6 changed files with 452 additions and 311 deletions

View File

@ -17,188 +17,285 @@
#include "hurricane/Slot.h"
HInspectorWidget::HInspectorWidget ( Record* rootRecord, QWidget* parent )
: QWidget(parent)
, _slotsHistory()
, _recordModel(NULL)
, _sortModel(NULL)
, _recordsHistoryComboBox(NULL)
, _slotsView(NULL)
, _rowHeight(20)
, _rootRecord(rootRecord)
{
setAttribute ( Qt::WA_DeleteOnClose );
_rowHeight = QFontMetrics(Graphics::getFixedFont()).height() + 4;
//recordsHistoryComboBox = new QComboBox(this);
_slotsView = new QTableView(this);
_slotsView->setShowGrid(false);
_slotsView->setAlternatingRowColors(true);
_slotsView->setSelectionBehavior(QAbstractItemView::SelectRows);
_slotsView->setSortingEnabled(true);
QHeaderView* horizontalHeader = _slotsView->horizontalHeader ();
horizontalHeader->setStretchLastSection ( true );
horizontalHeader->setMinimumSectionSize ( 200 );
QHeaderView* verticalHeader = _slotsView->verticalHeader ();
verticalHeader->setVisible ( false );
Slot* rootSlot = getSlot ( "TopLevelSlot", _rootRecord );
_slotsHistory.push_back ( rootSlot );
_recordModel = new RecordModel ( rootSlot->getClone(), 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 );
QGridLayout* inspectorLayout = new QGridLayout();
//inspectorLayout->addWidget(recordsHistoryComboBox, 0, 0, 1, 2);
inspectorLayout->addWidget(_slotsView, 1, 0, 1, 2);
_filterPatternLineEdit = new QLineEdit(this);
QLabel* filterPatternLabel = new QLabel(tr("&Filter pattern:"), this);
filterPatternLabel->setBuddy(_filterPatternLineEdit);
inspectorLayout->addWidget(filterPatternLabel, 2, 0);
inspectorLayout->addWidget(_filterPatternLineEdit, 2, 1);
//QGroupBox* inspectorGroupBox = new QGroupBox(tr("Hurricane inspector"), this);
//inspectorGroupBox->setLayout(inspectorLayout);
//QVBoxLayout* mainLayout = new QVBoxLayout;
//mainLayout->addWidget(inspectorGroupBox);
//setLayout(mainLayout);
setLayout(inspectorLayout);
//connect(recordsHistoryComboBox, SIGNAL(currentIndexChanged(int)),
// this, SLOT(recordChanged(int)));
connect ( _filterPatternLineEdit
, SIGNAL(textChanged(const QString &))
, this
, SLOT(textFilterChanged())
);
setWindowTitle(tr("Inspector"));
resize(500, 300);
}
namespace Hurricane {
HInspectorWidget::~HInspectorWidget ()
{
//cerr << "HInspector::~HInspector() - " << hex << (void*)this << dec << endl;
clearHistory ();
//cerr << "Records: " << Record::getAllocateds() << endl;
//cerr << "Slots: " << Slot::getAllocateds() << endl;
}
void HInspectorWidget::setRootRecord ( Record* record )
{
//recordsHistoryComboBox->clear();
clearHistory ();
_rootRecord = record;
Slot* rootSlot = getSlot("TopLevelRecord",record);
_slotsHistory.push_back ( rootSlot );
_recordModel->setSlot ( rootSlot->getClone(), _slotsHistory.size() );
}
void HInspectorWidget::clearHistory ()
{
if ( !_slotsHistory.empty() ) {
if ( _slotsHistory.size() > 1 )
delete _slotsHistory[0]->getDataRecord();
for ( size_t i=0 ; i < _slotsHistory.size() ; i++ )
delete _slotsHistory[i];
_slotsHistory.clear ();
HInspectorWidget::History::History ()
: _depth(0)
, _slots()
, _comboBox(NULL)
{
}
}
bool HInspectorWidget::setSlot ( Slot* slot )
{
if ( !slot ) return false;
bool change = true;
//cerr << "HInspector::setSlot() - " << hex << (void*)slot << dec << endl;
change = _recordModel->setSlot ( slot, _slotsHistory.size() );
int rows = _sortModel->rowCount ();
for ( rows-- ; rows >= 0 ; rows-- )
_slotsView->setRowHeight ( rows, _rowHeight );
//cerr << "Records: " << Record::getAllocateds() << endl;
//cerr << "Slots: " << Slot::getAllocateds() << endl;
return change;
}
void HInspectorWidget::pushSlot ( Slot* slot )
{
//cerr << "pushSlot() - [clone of] " << hex << (void*)slot << dec << endl;
_slotsHistory.push_back ( slot->getClone() );
if ( !setSlot(slot->getClone()) ) {
//cerr << "pushSlot() cancelled" << endl;
delete _slotsHistory.back ();
_slotsHistory.pop_back ();
HInspectorWidget::History::~History ()
{
clear ( true );
}
}
void HInspectorWidget::popSlot ()
{
if ( _slotsHistory.size() > 1 ) {
//cerr << "popSlot() - " << hex << (void*)_slotsHistory.back() << dec << endl;
//cerr << "popSlot() - " << _slotsHistory.back()->getDataString() << endl;
delete _slotsHistory.back ();
_slotsHistory.pop_back ();
setSlot ( _slotsHistory.back()->getClone() );
}
}
void HInspectorWidget::keyPressEvent(QKeyEvent *event)
{
if ( event->matches(QKeySequence::MoveToNextChar) ) {
QModelIndex index = _slotsView->currentIndex();
if ( index.isValid() ) {
Slot* slot = _recordModel->getRecord()->getSlot(_sortModel->mapToSource(index).row());
if ( slot )
pushSlot ( slot );
void HInspectorWidget::History::push ( Slot* slot )
{
if ( _depth < _slots.size()-1 ) {
while ( _depth < _slots.size()-1 ) pop ();
}
} else if ( event->matches(QKeySequence::MoveToPreviousChar) ) {
popSlot ();
} else {
event->ignore();
_depth++;
_slots.push_back ( slot->getClone() );
_comboBox->addItem ( QString("%1: %2").arg(_depth).arg(_slots[_slots.size()-1]->getDataString().c_str()));
_comboBox->setCurrentIndex ( _depth );
}
}
void HInspectorWidget::textFilterChanged ()
{
_sortModel->setFilterRegExp ( _filterPatternLineEdit->text() );
}
void HInspectorWidget::History::pop ()
{
if ( _slots.size() > 1 ) {
delete _slots.back ();
_slots.pop_back ();
_comboBox->removeItem ( _slots.size() );
if ( _depth == _slots.size() )
_comboBox->setCurrentIndex ( --_depth );
}
}
void HInspectorWidget::History::back ()
{
if ( _depth == 0 ) return;
_comboBox->setCurrentIndex ( --_depth );
}
void HInspectorWidget::History::goTo ( int depth )
{
if ( ( depth < 0 ) || ( depth >= (int)_slots.size() ) ) return;
_depth = depth;
}
size_t HInspectorWidget::History::getDepth () const
{
return _depth;
}
Slot* HInspectorWidget::History::getSlot () const
{
return _slots[_depth]->getClone();
}
void HInspectorWidget::History::clear ( bool inDelete )
{
if ( !_slots.empty() ) {
// Delete the rootRecord only if it'not the current viewed record.
if ( _depth != 0 ) {
delete _slots[0]->getDataRecord();
}
for ( size_t i=0 ; i < _slots.size() ; i++ )
delete _slots[i];
_slots.clear ();
if ( !inDelete )
_comboBox->clear ();
}
}
void HInspectorWidget::History::setComboBox ( QComboBox* comboBox )
{
assert ( comboBox != NULL );
_comboBox = comboBox;
}
void HInspectorWidget::History::setRootRecord ( Record* rootRecord )
{
assert ( _comboBox != NULL );
assert ( rootRecord != NULL );
clear ();
Slot* rootSlot = ::getSlot ( "<TopLevelSlot>", rootRecord );
_slots.push_back ( rootSlot );
_comboBox->addItem ( QString("%1: %2").arg(_depth).arg(_slots[_slots.size()-1]->getDataString().c_str()));
_depth = 0;
}
HInspectorWidget::HInspectorWidget ( Record* rootRecord, QWidget* parent )
: QWidget(parent)
, _recordModel(NULL)
, _sortModel(NULL)
, _historyComboBox(NULL)
, _slotsView(NULL)
, _rowHeight(20)
, _rootRecord(rootRecord)
, _history()
{
setAttribute ( Qt::WA_DeleteOnClose );
_rowHeight = QFontMetrics(Graphics::getFixedFont()).height() + 4;
_slotsView = new QTableView(this);
_slotsView->setShowGrid(false);
_slotsView->setAlternatingRowColors(true);
_slotsView->setSelectionBehavior(QAbstractItemView::SelectRows);
_slotsView->setSortingEnabled(true);
QHeaderView* horizontalHeader = _slotsView->horizontalHeader ();
horizontalHeader->setStretchLastSection ( true );
horizontalHeader->setMinimumSectionSize ( 200 );
QHeaderView* verticalHeader = _slotsView->verticalHeader ();
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 );
_filterPatternLineEdit = new QLineEdit(this);
QLabel* filterPatternLabel = new QLabel(tr("&Filter pattern:"), this);
filterPatternLabel->setBuddy(_filterPatternLineEdit);
QGridLayout* inspectorLayout = new QGridLayout();
inspectorLayout->addWidget(_historyComboBox , 0, 0, 1, 2);
inspectorLayout->addWidget(_slotsView , 1, 0, 1, 2);
inspectorLayout->addWidget(filterPatternLabel , 2, 0);
inspectorLayout->addWidget(_filterPatternLineEdit, 2, 1);
setLayout ( inspectorLayout );
connect ( _historyComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(historyChanged(int)) );
connect ( _filterPatternLineEdit, SIGNAL(textChanged(const QString &))
, this , SLOT(textFilterChanged())
);
setWindowTitle(tr("Inspector"));
resize(500, 300);
}
HInspectorWidget::~HInspectorWidget ()
{
//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 );
}
bool HInspectorWidget::setSlot ()
{
bool change = true;
change = _recordModel->setSlot ( _history.getSlot(), _history.getDepth() );
if ( change ) {
int rows = _sortModel->rowCount ();
for ( rows-- ; rows >= 0 ; rows-- )
_slotsView->setRowHeight ( rows, _rowHeight );
_slotsView->selectRow ( 0 );
}
return change;
}
void HInspectorWidget::pushSlot ( Slot* slot )
{
_history.push ( slot );
if ( !setSlot() )
_history.pop ();
}
void HInspectorWidget::popSlot ()
{
_history.pop ();
setSlot ();
}
void HInspectorWidget::back ()
{
_history.back ();
setSlot ();
}
void HInspectorWidget::keyPressEvent(QKeyEvent *event)
{
if ( event->key() == Qt::Key_Right ) {
QModelIndex index = _slotsView->currentIndex();
if ( index.isValid() ) {
Slot* slot = _recordModel->getRecord()->getSlot(_sortModel->mapToSource(index).row());
if ( slot )
pushSlot ( slot );
}
} else if ( event->key() == Qt::Key_Left ) {
back ();
} else if ( event->key() == Qt::Key_O ) {
forkInspector ( _slotsView->currentIndex() );
} else {
event->ignore();
}
}
void HInspectorWidget::textFilterChanged ()
{
_sortModel->setFilterRegExp ( _filterPatternLineEdit->text() );
}
void HInspectorWidget::historyChanged ( int depth )
{
_history.goTo ( depth );
setSlot ();
}
void HInspectorWidget::forkInspector ( const QModelIndex& index )
{
if ( index.isValid() ) {
Slot* slot = _recordModel->getRecord()->getSlot(_sortModel->mapToSource(index).row());
Record* record = slot->getDataRecord();
if ( record ) {
HInspectorWidget* fork = new HInspectorWidget ( record );
fork->show ();
}
}
}
} // End of Hurricane namespace.

View File

@ -7,106 +7,107 @@
#include "hurricane/inspector/RecordModel.h"
RecordModel::RecordModel ( Slot* slot, QObject* parent )
: QAbstractTableModel(parent)
, _slot(slot)
, _record(slot->getDataRecord())
, _depth(1)
{ }
namespace Hurricane {
RecordModel::~RecordModel ()
{
//cerr << "RecordModel::~RecordModel()" << endl;
delete _record;
delete _slot;
}
RecordModel::RecordModel ( Slot* slot, QObject* parent )
: QAbstractTableModel(parent)
, _slot(slot)
, _record(slot->getDataRecord())
, _depth(0)
{ }
bool RecordModel::setSlot ( Slot* slot, size_t depth )
{
//cerr << "RecordModel::setSlot() " << _depth << " -> " << depth << endl;
//cerr << slot->getDataString() << endl;
Record* record = slot->getDataRecord ();
if ( !record ) {
//cerr << "RecordModel::setSlot() - Cancelling, NULL record" << endl;
delete slot;
return false;
RecordModel::~RecordModel ()
{
delete _record;
delete _slot;
}
emit layoutAboutToBeChanged ();
if ( _depth > 1 ) delete _record;
delete _slot;
_slot = slot;
_record = record;
_depth = depth;
emit layoutChanged ();
return true;
}
QVariant RecordModel::data ( const QModelIndex& index, int role ) const
{
static QFont nameFont = Graphics::getFixedFont ( QFont::Bold );
static QFont valueFont = Graphics::getFixedFont ( QFont::Normal, true );
if ( !index.isValid() ) return QVariant ();
if ( role == Qt::SizeHintRole ) {
switch (index.column()) {
case 0: return 200;
case 1: return -1;
bool RecordModel::setSlot ( Slot* slot, size_t depth )
{
Record* record = slot->getDataRecord ();
if ( !record ) {
delete slot;
return false;
}
emit layoutAboutToBeChanged ();
if ( _depth )
delete _record;
delete _slot;
_slot = slot;
_record = record;
_depth = depth;
emit layoutChanged ();
return true;
}
if ( role == Qt::FontRole ) {
switch (index.column()) {
case 0: return nameFont;
case 1: return valueFont;
}
}
if ( role == Qt::DisplayRole ) {
int row = index.row ();
Slot* slot = _record->getSlot ( row );
if ( slot ) {
switch ( index.column() ) {
case 0: return QVariant(slot->getName ().c_str());
case 1: return QVariant(slot->getDataString().c_str());
QVariant RecordModel::data ( const QModelIndex& index, int role ) const
{
static QFont nameFont = Graphics::getFixedFont ( QFont::Bold );
static QFont valueFont = Graphics::getFixedFont ( QFont::Normal, true );
if ( !index.isValid() ) return QVariant ();
if ( role == Qt::SizeHintRole ) {
switch (index.column()) {
case 0: return 200;
case 1: return -1;
}
}
}
return QVariant();
}
}
if ( role == Qt::FontRole ) {
switch (index.column()) {
case 0: return nameFont;
case 1: return valueFont;
}
}
QVariant RecordModel::headerData ( int section
, Qt::Orientation orientation
, int role ) const
{
if ( ( orientation == Qt::Vertical ) || ( section > 1 ) || (role != Qt::DisplayRole) )
if ( role == Qt::DisplayRole ) {
int row = index.row ();
Slot* slot = _record->getSlot ( row );
if ( slot ) {
switch ( index.column() ) {
case 0: return QVariant(slot->getName ().c_str());
case 1: return QVariant(slot->getDataString().c_str());
}
}
}
return QVariant();
if ( section == 0 )
return QVariant ( tr("Object Attribute") );
return QVariant ( tr("Value") );
}
}
int RecordModel::rowCount ( const QModelIndex& parent ) const
{
return _record->_getSlotList().size();
}
QVariant RecordModel::headerData ( int section
, Qt::Orientation orientation
, int role ) const
{
if ( ( orientation == Qt::Vertical ) || ( section > 1 ) || (role != Qt::DisplayRole) )
return QVariant();
if ( section == 0 )
return QVariant ( tr("Object Attribute") );
return QVariant ( tr("Value") );
}
int RecordModel::columnCount ( const QModelIndex& parent ) const
{
return 2;
}
int RecordModel::rowCount ( const QModelIndex& parent ) const
{
return _record->_getSlotList().size();
}
int RecordModel::columnCount ( const QModelIndex& parent ) const
{
return 2;
}
} // End of Hurricane namespace.

View File

@ -3,51 +3,84 @@
#define __HINSPECTOR_WIDGET_H__
#include "hurricane/Commons.h"
using namespace Hurricane;
#include <QWidget>
#include "hurricane/Commons.h"
class QSortFilterProxyModel;
class QModelIndex;
class QTableView;
class QLineEdit;
class QComboBox;
class QHeaderView;
class RecordModel;
namespace Hurricane {
class HInspectorWidget : public QWidget {
Q_OBJECT;
class RecordModel;
public:
typedef vector<Slot*> SlotsVector;
public:
HInspectorWidget ( Record* rootRecord, QWidget* parent=NULL );
~HInspectorWidget ();
void setRootRecord ( Record* record );
private slots:
void textFilterChanged ();
protected:
void keyPressEvent ( QKeyEvent * event );
private:
void clearHistory ();
void pushSlot ( Slot* slot );
void popSlot ();
bool setSlot ( Slot* slot );
class HInspectorWidget : public QWidget {
private:
SlotsVector _slotsHistory;
RecordModel* _recordModel;
QSortFilterProxyModel* _sortModel;
QComboBox* _recordsHistoryComboBox;
QTableView* _slotsView;
QLineEdit* _filterPatternLineEdit;
int _rowHeight;
Record* _rootRecord;
};
public:
typedef vector<Slot*> SlotsVector;
private:
class History {
public:
History ();
~History ();
void push ( Slot* slot );
void pop ();
void back ();
void goTo ( int depth );
void clear ( bool inDelete=false );
void setComboBox ( QComboBox* comboBox );
void setRootRecord ( Record* rootRecord );
size_t getDepth () const;
Slot* getSlot () const;
private:
size_t _depth;
SlotsVector _slots;
QComboBox* _comboBox;
private:
History ( const History& );
History& operator= ( const History& );
};
Q_OBJECT;
public:
HInspectorWidget ( Record* rootRecord, QWidget* parent=NULL );
~HInspectorWidget ();
void setRootRecord ( Record* record );
private slots:
void textFilterChanged ();
void historyChanged ( int depth );
void forkInspector ( const QModelIndex& index );
protected:
void keyPressEvent ( QKeyEvent * event );
private:
void pushSlot ( Slot* slot );
void popSlot ();
void back ();
bool setSlot ();
private:
RecordModel* _recordModel;
QSortFilterProxyModel* _sortModel;
QComboBox* _historyComboBox;
QTableView* _slotsView;
QLineEdit* _filterPatternLineEdit;
int _rowHeight;
Record* _rootRecord;
History _history;
};
} // End of Hurricane namespace.
#endif // __HINSPECTOR_WIDGET_H__

View File

@ -6,34 +6,37 @@
#include "hurricane/Commons.h"
using namespace Hurricane;
namespace Hurricane {
class RecordModel : public QAbstractTableModel {
Q_OBJECT;
class RecordModel : public QAbstractTableModel {
Q_OBJECT;
public:
RecordModel ( Slot* slot, QObject* parent=NULL );
~RecordModel ();
bool setSlot ( Slot* slot, size_t depth );
int rowCount ( const QModelIndex& parent=QModelIndex() ) const;
int columnCount ( const QModelIndex& parent=QModelIndex() ) const;
QVariant data ( const QModelIndex& index, int role=Qt::DisplayRole ) const;
QVariant headerData ( int section, Qt::Orientation orientation, int role=Qt::DisplayRole ) const;
inline Record* getRecord ();
inline Slot* getSlot ();
public:
RecordModel ( Slot* slot, QObject* parent=NULL );
~RecordModel ();
bool setSlot ( Slot* slot, size_t depth );
int rowCount ( const QModelIndex& parent=QModelIndex() ) const;
int columnCount ( const QModelIndex& parent=QModelIndex() ) const;
QVariant data ( const QModelIndex& index, int role=Qt::DisplayRole ) const;
QVariant headerData ( int section, Qt::Orientation orientation, int role=Qt::DisplayRole ) const;
inline Record* getRecord ();
inline Slot* getSlot ();
private:
Slot* _slot;
Record* _record;
size_t _depth;
};
private:
Slot* _slot;
Record* _record;
size_t _depth;
};
// Inline Functions.
inline Record* RecordModel::getRecord () { return _record; }
inline Slot* RecordModel::getSlot () { return _slot; }
// Inline Functions.
inline Record* RecordModel::getRecord () { return _record; }
inline Slot* RecordModel::getSlot () { return _slot; }
} // End of Hurricane namespace.
#endif // __RECORD_MODEL_H__

View File

@ -134,6 +134,12 @@ namespace Hurricane {
{ return _physicalsPerGrid; }
double DbU::physicalToGrid ( double physical, UnitPower p )
{
return ( physical * getUnitPower(p) ) / _physicalsPerGrid;
}
void DbU::setGridsPerLambda ( double gridsPerLambda )
{
if ( ( rint(gridsPerLambda) != gridsPerLambda )

View File

@ -67,6 +67,7 @@ namespace Hurricane {
static double getUnitPower ( UnitPower p );
static void setPhysicalsPerGrid ( double gridsPerLambda, UnitPower p );
static double getPhysicalsPerGrid ();
static double physicalToGrid ( double physical, UnitPower p );
// Lamba Managment.
static void setGridsPerLambda ( double gridsPerLambda );
static double getGridsPerLambda ();