00001 00042 #include "aiundomodel.hpp" 00043 00044 using namespace AiFractals; 00045 00046 AiUndoModel::AiUndoModel( QObject *parent ) 00047 :QAbstractItemModel(parent) 00048 { 00049 } 00050 00051 QUndoStack *AiUndoModel::getStack() const 00052 { 00053 return m_stack; 00054 } 00055 00056 void AiUndoModel::setStack( QUndoStack * stack ) 00057 { 00058 m_stack = stack; 00059 connect(m_stack, SIGNAL(indexChanged(int)), this, SLOT(stackChanged())); 00060 } 00061 00062 QModelIndex AiUndoModel::index( int row, int column, 00063 const QModelIndex &parent ) const 00064 { 00065 return this->createIndex(row, column); 00066 } 00067 00068 QModelIndex AiUndoModel::parent(const QModelIndex&) const 00069 { 00070 return QModelIndex(); 00071 } 00072 00073 int AiUndoModel::rowCount(const QModelIndex &parent ) const 00074 { 00075 return m_stack->count(); 00076 } 00077 00078 int AiUndoModel::columnCount(const QModelIndex &parent ) const 00079 { 00080 return 1; 00081 } 00082 00083 QVariant AiUndoModel::data(const QModelIndex &index, int role ) const 00084 { 00085 if( role == Qt::DecorationRole ) 00086 { 00087 const AiCommand * cmd = (AiCommand*) m_stack->command( index.row() ); 00088 return QIcon( QPixmap::fromImage(cmd->image.scaled(60, 60, 00089 Qt::KeepAspectRatio, Qt::SmoothTransformation) ) ); 00090 } 00091 00092 return QVariant(); 00093 } 00094 00095 QModelIndex AiUndoModel::selectedIndex() const 00096 { 00097 return this->createIndex( m_stack->index(), 0 ) ; 00098 } 00099 00100 00101 void AiUndoModel::stackChanged() 00102 { 00103 reset(); 00104 } 00105 00106 void AiUndoModel::setStackCurrentIndex( const QModelIndex &index ) 00107 { 00108 if ( index.row() <= m_stack->count() ) 00109 { 00110 m_stack->setIndex( index.row() + 1 ); 00111 } 00112 }