Example #1
0
 def __setRuleData(self, column, content, value):
     """change rule data in the model"""
     dirty, message = False, None
     if column == 0:
         name = unicode(value)
         if content.name != english(name):
             dirty = True
             content.name = english(name)
     elif column == 1 and isinstance(content, ParameterRule):
         oldParameter = content.parameter
         if isinstance(content, IntRule):
             if content.parameter != value.toInt()[0]:
                 dirty = True
                 content.parameter = value.toInt()[0]
         elif isinstance(content, BoolRule):
             return False, ''
         elif isinstance(content, StrRule):
             if content.parameter != unicode(value):
                 dirty = True
                 content.parameter = unicode(value)
         else:
             if content.parameter != unicode(value):
                 dirty = True
                 content.parameter = unicode(value)
         message = content.validate()
         if message:
             content.parameter = oldParameter
             dirty = False
     else:
         unitName = str(self.rootItem.content(column).toString())
         dirty, message = content.score.change(unitName, value)
     return dirty, message
Example #2
0
File: rule.py Project: KDE/kajongg
 def save(self, minus=False, forced=False):
     """save the ruleset to the database.
     If it does not yet exist in database, give it a new id
     If the name already exists in the database, also give it a new name
     If the hash already exists in the database, only save if forced=True"""
     if not forced:
         if minus:
             # if we save a template, only check for existing templates. Otherwise this could happen:
             # clear kajongg.db, play game with DMJL, start ruleset editor, copy DMJL.
             # since play Game saved the used ruleset with id 1, id 1 is found here and no new
             # template is generated. Next the ruleset editor shows the original ruleset in italics
             # and the copy with normal font but identical name, and the
             # copy is never saved.
             qData = Query(
                 "select id from ruleset where hash=? and id<0", (self.hash,)).records
         else:
             qData = Query(
                 "select id from ruleset where hash=?", (self.hash,)).records
         if qData:
             # is already in database
             self.rulesetId = qData[0][0]
             return
     with Internal.db:
         self.rulesetId, self.name = self._newKey(minus)
         Query(
             'INSERT INTO ruleset(id,name,hash,description) VALUES(?,?,?,?)',
             (self.rulesetId, english(self.name),
              self.hash, self.description),
             failSilent=True)
         cmd = 'INSERT INTO rule(ruleset, list, position, name, definition, ' \
             'points, doubles, limits, parameter) VALUES(?,?,?,?,?,?,?,?,?)'
         args = list(self.ruleRecord(x) for x in self.allRules)
         Query(cmd, args)
Example #3
0
 def __generateName(widget):
     """generate a name for this widget to be used in the config file"""
     orgWidget = widget
     name = english(widget.objectName())
     if not name:
         while widget.parentWidget():
             name = widget.__class__.__name__ + name
             widget = widget.parentWidget()
             if widget.parentWidget():
                 widgetName = english(widget.parentWidget().objectName())
                 if widgetName:
                     name = widgetName + name
                     break
     if not name:
         name = orgWidget.__class__.__name__
     return str(name)
Example #4
0
 def setData(self, index, value, role=Qt.EditRole):
     """change data in the model"""
     # pylint:  disable=too-many-branches
     if not index.isValid():
         return False
     try:
         dirty = False
         column = index.column()
         item = index.internalPointer()
         ruleset = item.ruleset()
         content = item.rawContent
         if role == Qt.EditRole:
             if isinstance(content, Ruleset) and column == 0:
                 name = unicode(value)
                 oldName = content.name
                 content.rename(english(name))
                 dirty = oldName != content.name
             elif isinstance(content, RuleBase):
                 dirty, message = self.__setRuleData(column, content, value)
                 if message:
                     Sorry(message)
                     return False
             else:
                 return False
         elif role == Qt.CheckStateRole:
             if isinstance(content, BoolRule) and column == 1:
                 if not isinstance(ruleset, PredefinedRuleset):
                     newValue = value == Qt.Checked
                     if content.parameter != newValue:
                         dirty = True
                         content.parameter = newValue
             else:
                 return False
         if dirty:
             if isinstance(content, RuleBase):
                 ruleset.updateRule(content)
             self.dataChanged.emit(index, index)
         return True
     except BaseException:
         return False
Example #5
0
File: rule.py Project: KDE/kajongg
def ruleKey(name):
    """the key is used for finding a rule in a RuleList"""
    return english(name).replace(' ', '').replace('.', '')