0.3.1
[qanava.git] / src / ui / uiStyleModel.cpp
blob38d0f7ac74a065d68fc8a67e4434e13f63c11e94
1 /*
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 //-----------------------------------------------------------------------------
29 // Qanava headers
30 #include "./uiStyleModel.h"
33 namespace qan { // ::qan
34 namespace ui { // ::qan::ui
37 //-----------------------------------------------------------------------------
38 StyleItemModel::StyleItemModel( Style& style, QObject *parent ) :
39 QAbstractItemModel( parent ),
40 _style( style )
44 //-----------------------------------------------------------------------------
48 /* Qt Model Interface *///-----------------------------------------------------
49 QVariant StyleItemModel::data( const QModelIndex &index, int role ) const
51 if ( !index.isValid( ) )
52 return QVariant( "index invalid" );
54 QVariant d;
56 if ( ( role == Qt::FontRole ) && ( index.column( ) == 0 ) )
58 QFont font;
59 font.setWeight( QFont::Bold );
60 d = font;
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()!" );
75 return d;
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 )
100 if ( section == 0 )
101 return QString( "Property" );
102 else if ( section == 1 )
103 return QString( "Value" );
105 return QVariant( );
108 QModelIndex StyleItemModel::index( int row, int column, const QModelIndex &parent ) const
110 if ( !parent.isValid( ) )
112 const void* internalPointer = 0;
113 int internalId = 0;
115 //Style::Attribute* attribute = _style.getAttributeManager( ).get( row );
116 //if ( attribute != 0 )
118 if ( column == 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
145 return 2;
147 //-----------------------------------------------------------------------------
150 } // ::qan::ui
151 } // ::qan