Changeset 3367

Show
Ignore:
Timestamp:
05/15/08 23:14:29 (2 months ago)
Author:
aaronr
Message:

BIG update to the xml model-view stuff to accomodate temporary attributes on dynamic nodes added to the XML tree, such as is done in the results manager.

Location:
trunk/opus_gui
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/opus_gui/config/xmlmodelview/opusdatamodel.py

    r3362 r3367  
    170170                elif role == Qt.DisplayRole: 
    171171                    return QVariant(domElement.tagName()) 
     172                elif role == Qt.BackgroundRole: 
     173                    if domElement.hasAttribute(QString("temporary")) and \ 
     174                           domElement.attribute(QString("temporary")) == QString("True"): 
     175                        return QVariant(QColor(Qt.cyan)) 
     176                    else: 
     177                        return QVariant(QColor(Qt.white)) 
    172178                else: 
    173179                    return QVariant() 
     
    283289        return self.dirty 
    284290     
     291    def isTemporary(self,node): 
     292        nodeElement = node.toElement() 
     293        if not nodeElement.isNull(): 
     294            if nodeElement.hasAttribute(QString("temporary")): 
     295                if nodeElement.attribute(QString("temporary")) == QString("True"): 
     296                    return True 
     297                else: 
     298                    return False 
     299        return False 
     300         
    285301    def setData(self,index,value,role): 
    286302        if not index.isValid(): 
     
    297313                if not domElement.isNull(): 
    298314                    domElement.setTagName(value.toString()) 
    299                     self.markAsDirty() 
     315                    if not self.isTemporary(domElement): 
     316                        self.markAsDirty() 
    300317        elif index.column() == 1: 
    301318            if domNode.hasChildNodes(): 
     
    304321                    if children.item(x).isText(): 
    305322                        children.item(x).setNodeValue(QString(value.toString())) 
    306                         self.markAsDirty() 
     323                        if not self.isTemporary(children.item(x)): 
     324                            self.markAsDirty() 
    307325            else: 
    308326                #print "New text node to be added" 
     
    310328                newText = self.domDocument.createTextNode(QString(value.toString())) 
    311329                domNode.appendChild(newText) 
    312                 self.markAsDirty() 
     330                if not self.isTemporary(newText): 
     331                    self.markAsDirty() 
    313332        return True 
    314333 
     
    332351        parentItem.childItems.insert(row,item) 
    333352        self.endInsertRows() 
    334         self.markAsDirty() 
     353        if not self.isTemporary(node): 
     354            self.markAsDirty() 
    335355        return returnval 
    336356 
     
    346366        parentItem.childItems.pop(row) 
    347367        self.endRemoveRows() 
    348         self.markAsDirty() 
     368        if not self.isTemporary(parentItem.child(row).domNode): 
     369            self.markAsDirty() 
    349370        return returnval 
    350371 
     
    375396                self.removeRow(currentRow,currentParent) 
    376397                self.insertRow(currentRow+howmany,currentParent,clone) 
    377                 self.markAsDirty() 
     398                if not self.isTemporary(item.internalPointer().domNode): 
     399                    self.markAsDirty() 
    378400 
    379401    def findElementIndexByName(self,name,parent,multiple=False): 
     
    449471    #                self.stripAttribute(attribute,child,recursive) 
    450472 
    451     def create_node(self, document, name, type, value, choices = None): 
     473    def create_node(self, document, name, type, value, choices = None, temporary = False): 
    452474        newNode = document.createElement(QString(name)) 
    453475        newNode.setAttribute(QString("type"),QString(type)) 
     
    456478        if choices is not None: 
    457479            newNode.setAttribute(QString('choices'), QString(choices)) 
     480        if temporary is True: 
     481            newNode.setAttribute(QString("temporary"),QString("True")) 
    458482        return newNode 
    459483 
     
    464488                # remove the attribute 
    465489                parentElement.removeAttribute(QString(attribute)) 
    466                 self.markAsDirty() 
     490                if not self.isTemporary(parentElement): 
     491                    self.markAsDirty() 
    467492            rows = parent.childNodes().count() 
    468493            for x in xrange(0,rows,1): 
     
    474499                        # remove the attribute 
    475500                        childElement.removeAttribute(QString(attribute)) 
    476                         self.markAsDirty() 
     501                        if not self.isTemporary(childElement): 
     502                            self.markAsDirty() 
    477503                    # If this child has other children then we recurse 
    478504                    childRows = child.childNodes().count() 
     
    487513                # remove the attribute 
    488514                parentElement.removeAttribute(QString(attribute)) 
    489                 self.markAsDirty() 
     515                if not self.isTemporary(parentElement): 
     516                    self.markAsDirty() 
    490517            grandParent = parent.parentNode() 
    491518            if not grandParent.isNull(): 
  • trunk/opus_gui/results/opus_result_generator.py

    r3328 r3367  
    369369                                    name = name,  
    370370                                    type = 'indicator_result',  
    371                                     value = '') 
     371                                    value = '', 
     372                                    temporary = True) 
    372373        source_data_node = model.create_node(document = document,  
    373374                                    name = 'source_data',  
    374375                                    type = 'string',  
    375                                     value = self.source_data_name) 
     376                                    value = self.source_data_name, 
     377                                    temporary = True) 
    376378        indicator_node = model.create_node(document = document,  
    377379                                    name = 'indicator_name',  
    378380                                    type = 'string',  
    379                                     value = self.indicator_name)         
     381                                    value = self.indicator_name, 
     382                                    temporary = True)         
    380383        dataset_node = model.create_node(document = document,  
    381384                                    name = 'dataset_name',  
    382385                                    type = 'string',  
    383                                     value = self.dataset_name) 
     386                                    value = self.dataset_name, 
     387                                    temporary = True) 
    384388        year_node = model.create_node(document = document,  
    385389                                    name = 'available_years',  
    386390                                    type = 'string',  
    387                                     value = ', '.join([repr(year) for year in self.years]))                 
     391                                    value = ', '.join([repr(year) for year in self.years]), 
     392                                    temporary = True) 
    388393        parent = model.index(0,0,QModelIndex()).parent() 
    389394        index = model.findElementIndexByName("Results", parent)[0] 
  • trunk/opus_gui/results/resultManagerBase.py

    r3342 r3367  
    117117                                    name = name,  
    118118                                    type = 'source_data',  
    119                                     value = '') 
     119                                    value = '', 
     120                                    temporary = True) 
    120121 
    121122        scenario_name_node = model.create_node(document = document,  
    122123                                    name = 'scenario_name',  
    123124                                    type = 'string',  
    124                                     value = scenario_name) 
     125                                    value = scenario_name, 
     126                                    temporary = True) 
    125127 
    126128        run_name_node = model.create_node(document = document,  
    127129                                    name = 'run_name',  
    128130                                    type = 'string',  
    129                                     value = run_name) 
     131                                    value = run_name, 
     132                                    temporary = True) 
    130133 
    131134        cache_directory_node = model.create_node(document = document,  
    132135                                    name = 'cache_directory',  
    133136                                    type = 'string',  
    134                                     value = cache_directory) 
     137                                    value = cache_directory, 
     138                                    temporary = True) 
    135139 
    136140        start_year_node = model.create_node(document = document,  
    137141                                    name = 'start_year',  
    138142                                    type = 'integer',  
    139                                     value = str(start_year)) 
     143                                    value = str(start_year), 
     144                                    temporary = True) 
    140145 
    141146        end_year_node = model.create_node(document = document,  
    142147                                    name = 'end_year',  
    143148                                    type = 'integer',  
    144                                     value = str(end_year))     
     149                                    value = str(end_year), 
     150                                    temporary = True) 
    145151 
    146152        index = model.findElementIndexByName("Simulation_runs", parent)[0]