Commit 105c834d authored by Matthias Möller's avatar Matthias Möller

- fixes doc warnings

- minor performance improvements

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16190 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 2b1f1321
......@@ -96,7 +96,7 @@ int TreeModel::columnCount(const QModelIndex &/*_parent*/) const
* @param _role defines the kind of data requested
* @return requested data
*/
QVariant TreeModel::data(const QModelIndex &_index,const int _role) const
QVariant TreeModel::data(const QModelIndex &_index, int _role) const
{
// Skip invalid requests
......@@ -146,52 +146,43 @@ QVariant TreeModel::data(const QModelIndex &_index,const int _role) const
// Visible
case 1 :
if (_role == Qt::CheckStateRole ) {
bool visibility = false;
// visiblity group
if (item->isGroup()){
bool visible = false;
// target group
if (item->isGroup() && item->childCount() > 0)
{
QList< TreeItem* > children = item->getLeafs();
bool initRound = true;
for (int i=0; i < children.size() ; i++){
if (initRound){
visibility = children[i]->visible();
initRound = false;
}else if (visibility != children[i]->visible())
visible = children[0]->visible();
for (int i=0; i < children.size() ; ++i)
{
if (visible != children[i]->visible())
return QVariant(Qt::PartiallyChecked);
}
}else
//visibility item
visibility = item->visible();
if (visibility)
return QVariant(Qt::Checked);
}
else
return QVariant(Qt::Unchecked);
visible = item->visible();
return (visible) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
}
return QVariant();
break;
// Source
case 2 :
if (_role == Qt::CheckStateRole ) {
bool source = false;
// source group
if (item->isGroup()){
// target group
if (item->isGroup() && item->childCount() > 0)
{
QList< TreeItem* > children = item->getLeafs();
bool initRound = true;
for (int i=0; i < children.size() ; i++){
if (initRound){
source = children[i]->source();
initRound = false;
}else if (source != children[i]->source())
source = children[0]->source();
for (int i=0; i < children.size() ; ++i)
{
if (source != children[i]->source())
return QVariant(Qt::PartiallyChecked);
}
}else
//source item
source = item->source();
if (source)
return QVariant(Qt::Checked);
}
else
return QVariant(Qt::Unchecked);
source = item->source();
return (source) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
}
return QVariant();
......@@ -200,32 +191,27 @@ QVariant TreeModel::data(const QModelIndex &_index,const int _role) const
if (_role == Qt::CheckStateRole ) {
bool target = false;
// target group
if (item->isGroup()){
if (item->isGroup() && item->childCount() > 0)
{
QList< TreeItem* > children = item->getLeafs();
bool initRound = true;
for (int i=0; i < children.size() ; i++){
if (initRound){
target = children[i]->target();
initRound = false;
}else if (target != children[i]->target())
target = children[0]->target();
for (int i=0; i < children.size() ; ++i)
{
if (target != children[i]->target())
return QVariant(Qt::PartiallyChecked);
}
}else
//target item
target = item->target();
if (target)
return QVariant(Qt::Checked);
}
else
return QVariant(Qt::Unchecked);
target = item->target();
return (target) ? QVariant(Qt::Checked) : QVariant(Qt::Unchecked);
}
return QVariant();
break;
default:
return QVariant();
}
return QVariant();
}
......@@ -274,8 +260,8 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex &_index) const
* @param _role the role that defines the type of data
* @return the requested data
*/
QVariant TreeModel::headerData(const int _section,const Qt::Orientation _orientation,
const int _role) const
QVariant TreeModel::headerData(int _section, Qt::Orientation _orientation,
int _role) const
{
if (_orientation == Qt::Horizontal && _role == Qt::DisplayRole) {
......@@ -301,7 +287,7 @@ QVariant TreeModel::headerData(const int _section,const Qt::Orientation _orienta
* @param _parent parent item
* @return corresponding ModelIndex
*/
QModelIndex TreeModel::index(const int _row,const int _column, const QModelIndex &_parent) const
QModelIndex TreeModel::index(int _row, int _column,const QModelIndex &_parent) const
{
// if (!hasIndex(row, column, _parent))
// return QModelIndex();
......@@ -381,52 +367,35 @@ void TreeModel::objectChanged(int _id) {
//if internal and external representation are both valid
if (obj != 0 && item != 0){
//update the name
bool updateRow = false;
if ( obj->name() != item->name() ){
item->name( obj->name() );
//TODO actually we do not need to update the whole row but single column somehow doesn't work
QModelIndex index0 = getModelIndex(item,0);
QModelIndex index1 = getModelIndex(item,3);
if ( index0.isValid() && index1.isValid() )
emit dataChanged( index0, index1);
updateRow = true;
}
//update visibility
if ( obj->visible() != item->visible() ){
item->visible( obj->visible() );
QModelIndex index0 = getModelIndex(item,0);
QModelIndex index1 = getModelIndex(item,3);
if ( index0.isValid() && index1.isValid() ){
//the whole row has to be updated because of the grey background-color
emit dataChanged( index0, index1);
}
updateRow = true;
}
//update source flag
if ( obj->source() != item->source() ){
item->source( obj->source() );
//TODO actually we do not need to update the whole row but single column somehow doesn't work
QModelIndex index0 = getModelIndex(item,0);
QModelIndex index1 = getModelIndex(item,3);
if ( index0.isValid() && index1.isValid() ){
//the whole row has to be updated because of the grey background-color
emit dataChanged( index0, index1);
}
updateRow = true;
}
//update target flag
if ( obj->target() != item->target() ){
item->target( obj->target() );
updateRow = true;
}
if (updateRow)
{
//TODO actually we do not need to update the whole row but single column somehow doesn't work
QModelIndex index0 = getModelIndex(item,0);
QModelIndex index1 = getModelIndex(item,3);
......@@ -527,20 +496,11 @@ void TreeModel::moveItem(TreeItem* _item, TreeItem* _parent ){
QModelIndex oldParentIndex = itemIndex.parent();
QModelIndex newParentIndex = getModelIndex(_parent, 0);
//delete everything at the old location
beginRemoveRows( oldParentIndex, itemIndex.row(), itemIndex.row() );
beginMoveRows ( oldParentIndex, itemIndex.row(), itemIndex.row(), newParentIndex,0 );
_item->parent()->removeChild(_item);
endRemoveRows();
//insert it at the new location
beginInsertRows(newParentIndex, _parent->childCount(), _parent->childCount() ); //insert at the bottom
_item->setParent( _parent );
_parent->appendChild( _item );
endInsertRows();
emit layoutChanged();
endMoveRows();
}
//******************************************************************************
......
......@@ -55,7 +55,7 @@ class TreeModel : public QAbstractItemModel
signals:
// the connected TreeView changed data
void dataChangedInside(int _id, int _column, const QVariant& _value);
void dataChangedInside(int _id, int _column,const QVariant& _value);
// an object was moved via dragNdrop
void moveBaseObject(int _id, int _newParentId);
......@@ -75,25 +75,25 @@ public:
public:
/// Get the data of the corresponding entry
QVariant data(const QModelIndex &_index,const int _role) const;
QVariant data(const QModelIndex &_index,int _role) const;
/// return the types of the corresponding entry
Qt::ItemFlags flags(const QModelIndex &_index) const;
/// return the header data of the model
QVariant headerData(const int _section,
const Qt::Orientation _orientation,
const int _role = Qt::DisplayRole) const;
QVariant headerData(int _section,
Qt::Orientation _orientation,
int _role = Qt::DisplayRole) const;
/// Get the ModelIndex at given row,column
QModelIndex index(const int row,const int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex index(int _row, int _column,
const QModelIndex &_parent = QModelIndex()) const;
/// Get the parent ModelIndex
QModelIndex parent(const QModelIndex &index) const;
QModelIndex parent(const QModelIndex &_index) const;
/// get the number of rows
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int rowCount(const QModelIndex &_parent = QModelIndex()) const;
/** \brief Return the number of columns
*
......@@ -104,12 +104,12 @@ public:
/** \brief Set Data at 'index' to 'value'
*
* @param index a ModelIndex defining the positin in the model
* @param value the new value
* @param role unused
* @param _index a ModelIndex defining the positin in the model
* @param _value the new value
* @param _role unused
* @return return if the data was set successfully
*/
bool setData(const QModelIndex &index, const QVariant &value , int role);
bool setData(const QModelIndex &_index, const QVariant &_value , int _role);
/** @} */
......
......@@ -88,34 +88,34 @@ int TreeModel::columnCount(const QModelIndex &/*_parent*/) const
/** \brief Returns the data stored under the given role for the item referred to by the index
*
* @param index a ModelIndex that defines the item in the tree
* @param role defines the kind of data requested
* @param _index a ModelIndex that defines the item in the tree
* @param _role defines the kind of data requested
* @return requested data
*/
QVariant TreeModel::data(const QModelIndex &index, int role) const
QVariant TreeModel::data(const QModelIndex &_index, int _role) const
{
// Skip invalid requests
if (!index.isValid())
if (!_index.isValid())
return QVariant();
// Get the corresponding tree item
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
TreeItem *item = static_cast<TreeItem*>(_index.internalPointer());
if ( item == rootItem_ ) {
std::cerr << "Root" << std::endl;
}
// Set the background color of the objects row
if ( role == Qt::BackgroundRole ) {
if ( _role == Qt::BackgroundRole ) {
if ( !item->visible() ) {
return QVariant (QBrush (QColor (192, 192, 192)));
}
}
if (role == Qt::DisplayRole)
if (_role == Qt::DisplayRole)
{
switch (index.column ())
switch (_index.column ())
{
case 0:
return QVariant(item->id());
......@@ -134,18 +134,18 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const
/** \brief Returns the item flags for the given index
*
* @param index ModelIndex that defines an item in the tree
* @param _index ModelIndex that defines an item in the tree
* @return flags for the given ModelIndex
*/
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
Qt::ItemFlags TreeModel::flags(const QModelIndex &_index) const
{
if (!index.isValid())
if (!_index.isValid())
return 0;
Qt::ItemFlags flags = 0;
// Show/Source/Target
if ( index.column() == 0 || index.column() == 1 )
if ( _index.column() == 0 || _index.column() == 1 )
flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
else
flags = Qt::ItemIsEnabled;
......@@ -158,19 +158,19 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
/** \brief Returns the data in the header
*
* @param section the column in the header
* @param orientation header orientation (only horizontal handled)
* @param role the role that defines the type of data
* @param _section the column in the header
* @param _orientation header orientation (only horizontal handled)
* @param _role the role that defines the type of data
* @return the requested data
*/
QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
int role) const
QVariant TreeModel::headerData(int _section, Qt::Orientation _orientation,
int _role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
if (_orientation == Qt::Horizontal && _role == Qt::DisplayRole) {
if (section == 0)
if (_section == 0)
return QVariant("ID");
else if (section == 1)
else if (_section == 1)
return QVariant("Name");
else
return QVariant();
......@@ -184,12 +184,12 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
/** \brief Returns the index of the item in the model specified by the given row, column and parent index.
*
* @param row the row
* @param column the column
* @param _row the row
* @param _column the column
* @param _parent parent item
* @return corresponding ModelIndex
*/
QModelIndex TreeModel::index(int row, int column, const QModelIndex &_parent) const
QModelIndex TreeModel::index(int _row, int _column, const QModelIndex &_parent) const
{
TreeItem *parentItem;
......@@ -198,9 +198,9 @@ QModelIndex TreeModel::index(int row, int column, const QModelIndex &_parent) co
else
parentItem = static_cast<TreeItem*>(_parent.internalPointer());
TreeItem *childItem = parentItem->child(row);
TreeItem *childItem = parentItem->child(_row);
if (childItem)
return createIndex(row, column, childItem);
return createIndex(_row, _column, childItem);
else
return QModelIndex();
}
......@@ -210,15 +210,15 @@ QModelIndex TreeModel::index(int row, int column, const QModelIndex &_parent) co
/** \brief Return index of parent item
*
* @param index a ModelIndex
* @param _index a ModelIndex
* @return parent of the given ModelIndex
*/
QModelIndex TreeModel::parent(const QModelIndex &index) const
QModelIndex TreeModel::parent(const QModelIndex &_index) const
{
if (!index.isValid())
if (!_index.isValid())
return QModelIndex();
TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
TreeItem *childItem = static_cast<TreeItem*>(_index.internalPointer());
TreeItem *parentItem = childItem->parent();
if (parentItem == rootItem_)
......@@ -413,13 +413,13 @@ void TreeModel::moveItem(TreeItem* _item, TreeItem* _parent ){
/** \brief Return item at given index
*
* @param index a ModelIndex
* @param _index a ModelIndex
* @return item at given index
*/
TreeItem* TreeModel::getItem(const QModelIndex &index) const
TreeItem* TreeModel::getItem(const QModelIndex &_index) const
{
if (index.isValid()) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (_index.isValid()) {
TreeItem *item = static_cast<TreeItem*>(_index.internalPointer());
if (item) return item;
}
return rootItem_;
......@@ -430,13 +430,13 @@ TreeItem* TreeModel::getItem(const QModelIndex &index) const
/** \brief Return item-name at given index
*
* @param index a ModelIndex
* @param _index a ModelIndex
* @return name of the item at given index
*/
QString TreeModel::itemName(const QModelIndex &index) const
QString TreeModel::itemName(const QModelIndex &_index) const
{
if (index.isValid()) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (_index.isValid()) {
TreeItem *item = static_cast<TreeItem*>(_index.internalPointer());
if (item)
return item->name();
}
......@@ -447,13 +447,13 @@ QString TreeModel::itemName(const QModelIndex &index) const
/** \brief Return item-id at given index
*
* @param index a ModelIndex
* @param _index a ModelIndex
* @return item-id at given index
*/
int TreeModel::itemId(const QModelIndex &index) const
int TreeModel::itemId(const QModelIndex &_index) const
{
if (index.isValid()) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (_index.isValid()) {
TreeItem *item = static_cast<TreeItem*>(_index.internalPointer());
if (item)
return item->id();
}
......@@ -507,6 +507,8 @@ QModelIndex TreeModel::getModelIndex(int _id, int _column ){
/** \brief Recursively update a column up to the root of the tree
*
* @param _item item to start with
* @param _column column which needs the update (1: visibility)
* @param _value value which will be assigned
*/
void TreeModel::propagateUpwards(TreeItem* _item, int _column, bool _value ){
......@@ -536,6 +538,7 @@ void TreeModel::propagateUpwards(TreeItem* _item, int _column, bool _value ){
/** \brief Recursively update a column up to the root of the tree
*
* @param _item item to start with
* @param _column column which needs the update (1: visibility)
*/
void TreeModel::propagateDownwards(TreeItem* _item, int _column ){
......@@ -572,10 +575,10 @@ void TreeModel::propagateDownwards(TreeItem* _item, int _column ){
//******************************************************************************
bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int /*role*/)
bool TreeModel::setData(const QModelIndex &_index, const QVariant &_value, int /*role*/)
{
emit dataChangedInside( itemId(index), index.column(), value );
emit dataChangedInside( itemId(_index), _index.column(), _value );
return true;
}
......
......@@ -73,25 +73,25 @@ class TreeModel : public QAbstractItemModel
public:
/// Get the data of the corresponding entry
QVariant data(const QModelIndex &index, int role) const;
QVariant data(const QModelIndex &_index, int _role) const;
/// return the types of the corresponding entry
Qt::ItemFlags flags(const QModelIndex &index) const;
Qt::ItemFlags flags(const QModelIndex &_index) const;
/// return the header data of the model
QVariant headerData(int section,
Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QVariant headerData(int _section,
Qt::Orientation _orientation,
int _role = Qt::DisplayRole) const;
/// Get the ModelIndex at given row,column
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex index(int _row, int _column,
const QModelIndex &_parent = QModelIndex()) const;
/// Get the parent ModelIndex
QModelIndex parent(const QModelIndex &index) const;
QModelIndex parent(const QModelIndex &_index) const;
/// get the number of rows
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int rowCount(const QModelIndex &_parent = QModelIndex()) const;
/** \brief Return the number of columns
*
......@@ -102,12 +102,12 @@ public:
/** \brief Set Data at 'index' to 'value'
*
* @param index a ModelIndex defining the positin in the model
* @param value the new value
* @param role unused
* @param _index a ModelIndex defining the positin in the model
* @param _value the new value
* @param _role unused
* @return return if the data was set successfully
*/
bool setData(const QModelIndex &index, const QVariant &value , int role);
bool setData(const QModelIndex &_index, const QVariant &_value , int _role);
/** @} */
......@@ -131,13 +131,13 @@ public:
bool getObjectName(TreeItem* _object , QString& _name);
/// Get the TreeItem corresponding to a given ModelIndex
TreeItem *getItem(const QModelIndex &index) const;
TreeItem *getItem(const QModelIndex &_index) const;
/// Get the name of a TreeItem corresponding to a given ModelIndex
QString itemName(const QModelIndex &index) const;
QString itemName(const QModelIndex &_index) const;
/// Get the id of a TreeItem corresponding to a given ModelIndex
int itemId(const QModelIndex &index) const;
int itemId(const QModelIndex &_index) const;
/// The object with the given id has been changed. Check if model also has to be changed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment