Changeset 2229

Show
Ignore:
Timestamp:
08/25/08 23:33:57 (3 months ago)
Author:
hlamer
Message:

Progress of refactoring of XUPItem

Location:
v2/branches/dev
Files:
17 modified
2 copied

Legend:

Unmodified
Added
Removed
  • v2/branches/dev/monkey/src/templatesmanager/ui/UITemplatesWizard.cpp

    r2227 r2229  
    177177{ 
    178178        const QModelIndex idx = mProjects->scopedModel()->mapToSource( index ); 
    179         if ( XUPItem* it = mProjects->itemFromIndex( idx ) ) 
     179        if ( XUPProjectItem* it = dynamic_cast<XUPProjectItem*> (mProjects->itemFromIndex( idx )) ) 
    180180        { 
    181181                cbOperators->clear(); 
  • v2/branches/dev/monkey/src/xupmanager/AddFilesDialog.cpp

    r1999 r2229  
    11#include "AddFilesDialog.h" 
    22#include "../pMonkeyStudio.h" 
     3 
     4#include "XUPItem.h" 
     5#include "XUPProjectItem.h" 
    36 
    47#include <QGridLayout> 
     
    9295        // create operators combobox 
    9396        cbOperators = new QComboBox; 
    94         cbOperators->addItems( pi->operators() ); 
     97        cbOperators->addItems( pi->project()->operators() ); 
    9598        hl2->addWidget( cbOperators ); 
    9699        // add groupbox to layout 
  • v2/branches/dev/monkey/src/xupmanager/AddFilesDialog.h

    r1999 r2229  
    1111#include "ScopedProjectItemModel.h" 
    1212#include "ProjectItemModel.h" 
    13 #include "XUPItem.h" 
    1413 
    1514class QListView; 
  • v2/branches/dev/monkey/src/xupmanager/FilteredProjectItemModel.cpp

    r1805 r2229  
    104104         
    105105        // calculate row to insert to 
    106         int r = it->filteredVariables().indexOf( vn ); 
     106        int r = it->project()->filteredVariables().indexOf( vn ); 
    107107        int ri = -1; 
    108108        for ( int i = 0; i < pit->rowCount(); i++ ) 
    109109        { 
    110110                FilteredProjectItem* cit = pit->child( i ); 
    111                 const int ci = it->filteredVariables().indexOf( cit->item()->defaultValue() ); 
     111                const int ci = it->project()->filteredVariables().indexOf( cit->item()->defaultValue() ); 
    112112                if ( cit->item()->isProject() ) 
    113113                        continue; 
     
    127127FilteredProjectItem* FilteredProjectItemModel::createFolder( const QString& name, XUPItem* inItem ) 
    128128{ 
    129         FilteredProjectItem* fit = new FilteredProjectItem( inItem->clone( false ) ); 
     129        FilteredProjectItem* fit = new FilteredProjectItem( inItem->clone() ); 
    130130        fit->item()->setDomElement( inItem->domElement().ownerDocument().createElement( "folder" ) ); 
    131131        fit->item()->setValue( "name", name ); 
     
    186186        XUPItem* parent = it->parent(); 
    187187        // check if we need to show this value 
    188         if ( !parent->filteredVariables().contains( parent->defaultValue() ) ) 
     188        if ( !parent->project()->filteredVariables().contains( parent->defaultValue() ) ) 
    189189                return; 
    190190         
     
    193193         
    194194        // check file based 
    195         bool b = it->fileVariables().contains( parent->defaultValue() ); 
     195        bool b = it->project()->fileVariables().contains( parent->defaultValue() ); 
    196196         
    197197        if ( !it->defaultValue().isEmpty() ) 
     
    206206{ 
    207207        // check we need to show it 
    208         if ( !it->filteredVariables().contains( it->defaultValue() ) ) 
     208        if ( !it->project()->filteredVariables().contains( it->defaultValue() ) ) 
    209209                return; 
    210210         
     
    237237                { 
    238238                        // if filtered 
    239                         if ( !it->filteredVariables().isEmpty() ) 
     239                        if ( !it->project()->filteredVariables().isEmpty() ) 
    240240                        { 
    241241                                if ( it->isProject() ) 
  • v2/branches/dev/monkey/src/xupmanager/ProjectEditorModel.cpp

    r1729 r2229  
    11#include "ProjectEditorModel.h" 
    22#include "XUPItem.h" 
     3#include "XUPProjectItem.h" 
    34#include "ProjectItemModel.h" 
    45 
     
    1920        if ( XUPItem* it = mSourceModel->itemFromIndex( idx ) ) 
    2021        { 
    21                 XUPItem* pit = mProject->project(); 
     22                XUPProjectItem* pit = mProject->project(); 
    2223                // if project or parent project 
    2324                if ( it->isProject() ) 
     
    2526                // if variable and filter != values 
    2627                if ( it->isType( "variable" ) && mType != ProjectEditorModel::vtValues ) 
    27                         return it->project() == pit && !it->fileVariables().contains( it->defaultValue() ); 
     28                        return it->project() == pit && !it->project()->fileVariables().contains( it->defaultValue() ); 
    2829                // if value and filter != variable 
    2930                if ( ( it->isType( "value" ) || it->isType( "folder" ) ) && mType != ProjectEditorModel::vtVariables ) 
  • v2/branches/dev/monkey/src/xupmanager/ScopedProjectItemModel.cpp

    r1729 r2229  
    22#include "ProjectItemModel.h" 
    33#include "XUPItem.h" 
     4#include "XUPProjectItem.h" 
    45 
    56ScopedProjectItemModel::ScopedProjectItemModel( ProjectItemModel* m ) 
     
    1112} 
    1213 
    13 void ScopedProjectItemModel::setFilteredProject( XUPItem* project ) 
     14void ScopedProjectItemModel::setFilteredProject( XUPProjectItem* project ) 
    1415{ 
    1516        mProject = project; 
     
    1718} 
    1819 
    19 XUPItem* ScopedProjectItemModel::filteredProject() const 
     20XUPProjectItem* ScopedProjectItemModel::filteredProject() const 
    2021{ return mProject; } 
    2122 
     
    2526        { 
    2627                if ( mProject ) 
    27                         return ( it->children( true, false ).contains( mProject ) || it == mProject ) || 
     28                        return ( it->children( true, false ).contains( static_cast<XUPItem*> (mProject) ) || it == mProject ) || 
    2829                                ( it->project() == mProject && it->isType( "project" ) || it->isType( "scope" ) ); 
    2930                else 
  • v2/branches/dev/monkey/src/xupmanager/ScopedProjectItemModel.h

    r1998 r2229  
    88class ProjectItemModel; 
    99class XUPItem; 
     10class XUPProjectItem; 
    1011 
    1112class Q_MONKEY_EXPORT ScopedProjectItemModel : public QSortFilterProxyModel 
     
    1617        ScopedProjectItemModel( ProjectItemModel* = 0 ); 
    1718 
    18         void setFilteredProject( XUPItem* project ); 
    19         XUPItem* filteredProject() const; 
     19        void setFilteredProject( XUPProjectItem* project ); 
     20        XUPProjectItem* filteredProject() const; 
    2021         
    2122        inline ProjectItemModel* model() const { return mSourceModel; } 
     
    2324protected: 
    2425        ProjectItemModel* mSourceModel; 
    25         XUPItem* mProject; 
     26        XUPProjectItem* mProject; 
    2627 
    2728        virtual bool filterAcceptsRow( int sr, const QModelIndex& sp ) const; 
  • v2/branches/dev/monkey/src/xupmanager/XUPIO.cpp

    r2142 r2229  
    7272                        QDomElement de = l.at( i ).toElement(); 
    7373                        // create item 
    74                         XUPItem* it = p->clone( false ); 
     74                        XUPItem* it = p->clone(); 
    7575                        // assign node 
    7676                        it->setDomElement( de ); 
  • v2/branches/dev/monkey/src/xupmanager/XUPItem.cpp

    r2228 r2229  
    11#include "XUPItem.h" 
     2#include "XUPProjectItem.h" 
    23#include "ProjectItemModel.h" 
    3 #include "XUPIO.h" 
    44 
    55 
     
    88#include <QDir> 
    99 
    10 XUPItemInfos XUPItem::mXUPItemInfos; 
    11  
    12 void XUPItem::registerItem() 
    13 { 
    14         mXUPItemInfos.Registered = true; 
    15         mXUPItemInfos.TextTypes << "comment" << "value" << "emptyline" << "function"; 
    16         mXUPItemInfos.FileVariables << "FILES"; 
    17         mXUPItemInfos.VariableLabels["FILES"] = tr( "Project Files" ); 
    18         mXUPItemInfos.FilteredVariables << "FILES"; 
    19         mXUPItemInfos.Operators << "=" << "+=" << "-=" << "*=" << "~="; 
    20         mXUPItemInfos.Suffixes[tr( "Monkey Studio Project" )] = QStringList( "*.xup" ); 
    21 } 
    22  
    23 const XUPItemInfos& XUPItem::itemInfos() const 
    24 { return mXUPItemInfos; } 
    25  
    26 QStringList XUPItem::operators() const 
    27 { return mXUPItemInfos.Operators; } 
    28  
    29 void XUPItem::registerOperator( const QString& s ) 
    30 { 
    31         if ( !mXUPItemInfos.Operators.contains( s ) ) 
    32                 mXUPItemInfos.Operators << s; 
    33 } 
    34  
    35 QStringList XUPItem::filteredVariables() const 
    36 { return mXUPItemInfos.FilteredVariables; } 
    37  
    38 void XUPItem::registerFilteredVariables( const QString& s ) 
    39 { 
    40         if ( !mXUPItemInfos.FilteredVariables.contains( s ) ) 
    41                 mXUPItemInfos.FilteredVariables << s; 
    42 } 
    43  
    44 QStringList XUPItem::textTypes() const 
    45 { return mXUPItemInfos.TextTypes; } 
    46  
    47 void XUPItem::registerTextType( const QString& s ) 
    48 { 
    49         if ( !mXUPItemInfos.TextTypes.contains( s ) ) 
    50                 mXUPItemInfos.TextTypes << s; 
    51 } 
    52  
    53 QStringList XUPItem::fileVariables() const 
    54 { return mXUPItemInfos.FileVariables; } 
    55  
    56 void XUPItem::registerFileVariables( const QString& s ) 
    57 { 
    58         if ( !mXUPItemInfos.FileVariables.contains( s ) ) 
    59                 mXUPItemInfos.FileVariables << s; 
    60 } 
    61  
    62 QStringList XUPItem::pathVariables() const 
    63 { return mXUPItemInfos.PathVariables; } 
    64  
    65 void XUPItem::registerPathVariables( const QString& s ) 
    66 { 
    67         if ( !mXUPItemInfos.PathVariables.contains( s ) ) 
    68                 mXUPItemInfos.PathVariables << s; 
    69 } 
    70  
    71 QHash<QString, QStringList> XUPItem::suffixes() const 
    72 { return mXUPItemInfos.Suffixes; } 
    73  
    74 void XUPItem::registerSuffixes( const QString& l, const QStringList& s ) 
    75 { mXUPItemInfos.Suffixes[l] = s; } 
    76  
    77 QHash<QString, QString> XUPItem::variableLabels() const 
    78 { return mXUPItemInfos.VariableLabels; } 
    79  
    80 void XUPItem::registerVariableLabels( const QString& v, const QString& l ) 
    81 { mXUPItemInfos.VariableLabels[v] = l; } 
    82  
    83 QHash<QString, QIcon> XUPItem::variableIcons() const 
    84 { return mXUPItemInfos.VariableIcons; } 
    85  
    86 void XUPItem::registerVariableIcons( const QString& v, const QIcon& i ) 
    87 { mXUPItemInfos.VariableIcons[v] = i; } 
    88  
    89 QHash<QString, QStringList> XUPItem::variableSuffixes() const 
    90 { return mXUPItemInfos.VariableSuffixes; } 
    91  
    92 void XUPItem::registerVariableSuffixes( const QString& n, const QStringList& s ) 
    93 { mXUPItemInfos.VariableSuffixes[n] = s; } 
    9410 
    9511QIcon XUPItem::getIcon( const QString& o, const QString& d ) const 
    9612{ return QIcon( QFile::exists( o ) ? o : QString( ":/items/%1.png" ).arg( d ) ); } 
    9713 
    98 QString XUPItem::valueName( const QString& s ) const 
    99 { 
    100         if ( textTypes().contains( s ) ) 
    101                 return "text"; 
    102         return "name"; 
    103 } 
    104  
    105 QStringList XUPItem::files( bool a ) 
    106 { 
    107         // files list 
    108         QStringList l; 
    109          
    110         // check valid item 
    111         if ( !isType( "variable" ) || !fileVariables().contains( defaultValue() ) ) 
    112                 return l; 
    113          
    114         // check recurs items from vit 
    115         foreach ( XUPItem* cit, children( false, false ) ) 
    116                 if ( cit->isType( "value" ) ) 
    117                                 l << ( a ? cit->filePath() : cit->relativeFilePath() ); 
    118          
    119         // return list 
    120         return l; 
    121 } 
    122  
    12314QVariant XUPItem::data( int role ) const 
    12415{ 
     
    12920                if ( isType( "variable" ) ) 
    13021                { 
    131                         icn = QFile::exists( value( "icon" ) ) ? QIcon( value( "icon" ) ) : variableIcons().value( value( "name" ) ); 
     22                        icn = QFile::exists( value( "icon" ) ) ? QIcon( value( "icon" ) ) : project()->variableIcons().value( value( "name" ) ); 
    13223                        if ( icn.isNull() ) 
    13324                                icn = getIcon( QString(), value( "type" ) ); 
     
    14334                else if ( isType( "variable" ) ) 
    14435                { 
    145                         if ( variableLabels().contains( defaultValue() ) ) 
    146                                 txt = variableLabels().value( defaultValue() ); 
     36                        if ( project()->variableLabels().contains( defaultValue() ) ) 
     37                                txt = project()->variableLabels().value( defaultValue() ); 
    14738                } 
    14839                else if ( isType( "value" ) ) 
     
    15041                        if ( parent() ) 
    15142                        { 
    152                                 if ( fileVariables().contains( parent()->defaultValue() ) ) 
     43                                if ( project()->fileVariables().contains( parent()->defaultValue() ) ) 
    15344                                        txt = QFileInfo( defaultInterpretedValue() ).fileName(); 
    154                                 else if ( pathVariables().contains( parent()->defaultValue() ) ) 
     45                                else if ( project()->pathVariables().contains( parent()->defaultValue() ) ) 
    15546                                        txt = relativeFilePath( defaultInterpretedValue() ); 
    15647                        } 
     
    19687{ return dynamic_cast<ProjectItemModel*>( QStandardItem::model() ); } 
    19788 
    198 XUPItem* XUPItem::clone( bool b ) const 
    199 { return b ? new XUPItem( domElement(), projectFilePath(), modified() ) : new XUPItem; } 
     89XUPItem* XUPItem::clone() const 
     90{ return new XUPItem; } //FIXME 
    20091 
    20192void XUPItem::appendRow( XUPItem* it ) 
     
    257148} 
    258149 
     150QStringList XUPItem::files( bool a ) 
     151{ 
     152        // files list 
     153        QStringList l; 
     154         
     155        // check valid item 
     156        if ( !isType( "variable" ) || !project()->fileVariables().contains( defaultValue() ) ) 
     157                return l; 
     158         
     159        // check recurs items from vit 
     160        foreach ( XUPItem* cit, children( false, false ) ) 
     161                if ( cit->isType( "value" ) ) 
     162                                l << ( a ? cit->filePath() : cit->relativeFilePath() ); 
     163         
     164        // return list 
     165        return l; 
     166} 
     167 
     168void XUPItem::addFiles( const QStringList& files, XUPItem* scope, const QString& op ) 
     169{ 
     170        // abort if no files 
     171        if ( files.isEmpty() ) 
     172                return; 
     173         
     174        // set scope 
     175        if ( !scope ) 
     176                scope = this; 
     177         
     178        // get variable item 
     179        XUPItem* vit = 0; 
     180        foreach ( XUPItem* cit, scope->children( false, true ) ) 
     181        { 
     182                if ( cit->isType( "variable" ) && cit->defaultValue() == "FILES" && cit->value( "operator", "=" ) == op ) 
     183                { 
     184                        vit = cit; 
     185                        break; 
     186                } 
     187        } 
     188         
     189        // check variable exists or not 
     190        bool exists = vit; 
     191         
     192        // create variable if needed 
     193        if ( !exists ) 
     194        { 
     195                vit = clone(); 
     196                vit->setDomElement( mDomElement.ownerDocument().createElement( "variable" ) ); 
     197                scope->domElement().appendChild( vit->domElement() ); 
     198                vit->setValue( vit->valueName(), "FILES" ); 
     199                vit->setValue( "operator", op ); 
     200                vit->setValue( "multiline", "true" ); 
     201        } 
     202         
     203        // get all files 
     204        QStringList existingFiles = vit->files(); 
     205         
     206        // add files 
     207        foreach ( QString f, files ) 
     208        { 
     209                QString fp = filePath( f ); 
     210                if ( !existingFiles.contains( fp ) ) 
     211                { 
     212                        XUPItem* it = clone(); 
     213                        it->setDomElement( mDomElement.ownerDocument().createElement( "value" ) ); 
     214                        vit->domElement().appendChild( it->domElement() ); 
     215                        it->setValue( it->valueName(), relativeFilePath( fp ) ); 
     216                        vit->appendRow( it ); 
     217                } 
     218        } 
     219        // append var item only at last will prevent multiple call of addFilteredValue from filtered view 
     220        if ( !exists ) 
     221                scope->appendRow( vit ); 
     222         
     223        // update scope nested if needed 
     224        if ( scope->isType( "scope" ) ) 
     225                scope->setValue( "nested", scope->rowCount() > 1 ? "false" : "true" ); 
     226} 
     227 
     228void XUPItem::removeFiles( const QStringList& files, XUPItem* scope, const QString& op ) 
     229{ 
     230        // abort if no files 
     231        if ( files.isEmpty() ) 
     232                return; 
     233         
     234        // set scope 
     235        if ( !scope ) 
     236                scope = this; 
     237         
     238        // get variable item 
     239        XUPItem* vit = 0; 
     240        foreach ( XUPItem* cit, scope->children( false, true ) ) 
     241        { 
     242                if ( cit->isType( "variable" ) && cit->defaultValue() == "FILES" && cit->value( "operator" ) == op ) 
     243                { 
     244                        vit = cit; 
     245                        break; 
     246                } 
     247        } 
     248         
     249        // if not variable, cancel 
     250        if ( !vit ) 
     251                return; 
     252         
     253        // check each child 
     254        foreach ( XUPItem* cit, vit->children( false, false ) ) 
     255                if ( cit->isType( "value" ) && files.contains( cit->filePath() ) ) 
     256                        cit->remove(); 
     257         
     258        // remove variable item if emptyline 
     259        if ( !vit->hasChildren() ) 
     260                vit->remove(); 
     261         
     262        // update scope nested if needed 
     263        if ( scope->isType( "scope" ) ) 
     264                scope->setValue( "nested", scope->rowCount() > 1 ? "false" : "true" ); 
     265} 
     266 
    259267void XUPItem::setDomElement( const QDomElement& e ) 
    260268{ 
     
    277285QString XUPItem::defaultInterpretedValue() const 
    278286{ return defaultValue(); } 
     287 
     288QString XUPItem::valueName( const QString& s ) const 
     289{ 
     290        if ( project()->textTypes().contains( s ) ) //FIXME Do it's right? 
     291                return "text"; 
     292        return "name"; 
     293} 
    279294 
    280295QString XUPItem::valueName() const 
     
    351366bool XUPItem::isProjectContainer() const 
    352367{ return false; } 
    353  
    354 bool XUPItem::loadProject( const QString& s, const QString& v ) 
    355 { 
    356         if ( XUPIO::loadXUP( this, s, v ) ) 
    357         { 
    358                 mProjectFilePath = s; 
    359                 setModified( false ); 
    360                 return true; 
    361         } 
    362         return false; 
    363 } 
    364  
    365 bool XUPItem::saveProject( const QString& s, const QString& v ) 
    366 { 
    367         if ( XUPIO::saveXUP( this, s.isEmpty() ? projectFilePath() : s, v ) ) 
    368         { 
    369                 mProjectFilePath = s.isEmpty() ? projectFilePath() : s; 
    370                 setModified( false ); 
    371                 return true; 
    372         } 
    373         return false; 
    374 } 
    375  
    376 void XUPItem::addFiles( const QStringList& files, XUPItem* scope, const QString& op ) 
    377 { 
    378         // abort if no files 
    379         if ( files.isEmpty() ) 
    380                 return; 
    381          
    382         // set scope 
    383         if ( !scope ) 
    384                 scope = this; 
    385          
    386         // get variable item 
    387         XUPItem* vit = 0; 
    388         foreach ( XUPItem* cit, scope->children( false, true ) ) 
    389         { 
    390                 if ( cit->isType( "variable" ) && cit->defaultValue() == "FILES" && cit->value( "operator", "=" ) == op ) 
    391                 { 
    392                         vit = cit; 
    393                         break; 
    394                 } 
    395         } 
    396          
    397         // check variable exists or not 
    398         bool exists = vit; 
    399          
    400         // create variable if needed 
    401         if ( !exists ) 
    402         { 
    403                 vit = clone( false ); 
    404                 vit->setDomElement( mDomElement.ownerDocument().createElement( "variable" ) ); 
    405                 scope->domElement().appendChild( vit->domElement() ); 
    406                 vit->setValue( vit->valueName(), "FILES" ); 
    407                 vit->setValue( "operator", op ); 
    408                 vit->setValue( "multiline", "true" ); 
    409         } 
    410          
    411         // get all files 
    412         QStringList existingFiles = vit->files(); 
    413          
    414         // add files 
    415         foreach ( QString f, files ) 
    416         { 
    417                 QString fp = filePath( f ); 
    418                 if ( !existingFiles.contains( fp ) ) 
    419                 { 
    420                         XUPItem* it = clone( false ); 
    421                         it->setDomElement( mDomElement.ownerDocument().createElement( "value" ) ); 
    422                         vit->domElement().appendChild( it->domElement() ); 
    423                         it->setValue( it->valueName(), relativeFilePath( fp ) ); 
    424                         vit->appendRow( it ); 
    425                 } 
    426         } 
    427          
    428         // append var item only at last will prevent multiple call of addFilteredValue from filtered view 
    429         if ( !exists ) 
    430                 scope->appendRow( vit ); 
    431          
    432         // update scope nested if needed 
    433         if ( scope->isType( "scope" ) ) 
    434                 scope->setValue( "nested", scope->rowCount() > 1 ? "false" : "true" ); 
    435 } 
    436  
    437 void XUPItem::removeFiles( const QStringList& files, XUPItem* scope, const QString& op ) 
    438 { 
    439         // abort if no files 
    440         if ( files.isEmpty() ) 
    441                 return; 
    442          
    443         // set scope 
    444         if ( !scope ) 
    445                 scope = this; 
    446          
    447         // get variable item 
    448         XUPItem* vit = 0; 
    449         foreach ( XUPItem* cit, scope->children( false, true ) ) 
    450         { 
    451                 if ( cit->isType( "variable" ) && cit->defaultValue() == "FILES" && cit->value( "operator" ) == op ) 
    452                 { 
    453                         vit = cit; 
    454                         break; 
    455                 } 
    456         } 
    457          
    458         // if not variable, cancel 
    459         if ( !vit ) 
    460                 return; 
    461          
    462         // check each child 
    463         foreach ( XUPItem* cit, vit->children( false, false ) ) 
    464                 if ( cit->isType( "value" ) && files.contains( cit->filePath() ) ) 
    465                         cit->remove(); 
    466