2 Qanava - Graph drawing library for QT
3 Copyright (C) 2006 Benoit AUTHEMAN
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //-----------------------------------------------------------------------------
21 // This file is a part of the Mysire software.
23 // \file uiStyleItemModel.cpp
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2006 January 04
26 //-----------------------------------------------------------------------------
30 #include "./uiStyleModel.h"
33 namespace qan
{ // ::qan
34 namespace ui
{ // ::qan::ui
37 //-----------------------------------------------------------------------------
38 StyleItemModel::StyleItemModel( Style
& style
, QObject
*parent
) :
39 QAbstractItemModel( parent
),
44 //-----------------------------------------------------------------------------
48 /* Qt Model Interface *///-----------------------------------------------------
49 QVariant
StyleItemModel::data( const QModelIndex
&index
, int role
) const
51 if ( !index
.isValid( ) )
52 return QVariant( "index invalid" );
56 if ( ( role
== Qt::FontRole
) && ( index
.column( ) == 0 ) )
59 font
.setWeight( QFont::Bold
);
63 if ( role
== Qt::DisplayRole
)
65 if ( index
.column( ) == 0 )
67 d
= QString( "ATTR NAME" );
69 else if ( index
.column( ) == 1 )
71 d
= QString( "FIXME: StyleItemModel::data()!" );
78 bool StyleItemModel::hasChildren( const QModelIndex
& parent
) const
80 return false; // No hierarchy for articles
83 Qt::ItemFlags
StyleItemModel::flags( const QModelIndex
&index
) const
85 if ( !index
.isValid( ) )
86 return Qt::ItemIsEnabled
;
88 if ( index
.column( ) == 0 )
89 return Qt::ItemIsEnabled
| Qt::ItemIsSelectable
;
90 else if ( index
.column( ) == 1 )
91 return Qt::ItemIsEnabled
| Qt::ItemIsEditable
;
93 return Qt::ItemIsEnabled
;
96 QVariant
StyleItemModel::headerData( int section
, Qt::Orientation orientation
, int role
) const
98 if ( orientation
== Qt::Horizontal
&& role
== Qt::DisplayRole
)
101 return QString( "Property" );
102 else if ( section
== 1 )
103 return QString( "Value" );
108 QModelIndex
StyleItemModel::index( int row
, int column
, const QModelIndex
&parent
) const
110 if ( !parent
.isValid( ) )
112 const void* internalPointer
= 0;
115 //Style::Attribute* attribute = _style.getAttributeManager( ).get( row );
116 //if ( attribute != 0 )
119 internalId
= 100 + row
;
120 else if ( column
== 1 )
121 internalId
= 200 + row
;
122 // FIXME internalPointer = 200 + row; // FIXME attribute;
125 if ( internalPointer
!= 0 )
126 return createIndex( row
, column
, const_cast< void* >( internalPointer
) );
127 else if ( internalId
!= 0 )
128 return createIndex( row
, column
, internalId
);
130 return QModelIndex( );
133 QModelIndex
StyleItemModel::parent( const QModelIndex
&index
) const
135 return QModelIndex( ); // No hierarchy for articles
138 int StyleItemModel::rowCount( const QModelIndex
& parent
) const
140 return _style
.size( );
143 int StyleItemModel::columnCount( const QModelIndex
& parent
) const
147 //-----------------------------------------------------------------------------