Skip to content
Permalink
Browse files

Fix model setData implementation, allow renaming symbols through model

  • Loading branch information
nyalldawson committed Sep 12, 2018
1 parent d7edeac commit 010c2f455ce01ab29003afcabdc8e84b82ec6e83
Showing with 31 additions and 2 deletions.
  1. +3 −1 src/core/symbology/qgsstylemodel.cpp
  2. +28 −1 tests/src/python/test_qgsstylemodel.py
@@ -150,7 +150,9 @@ bool QgsStyleModel::setData( const QModelIndex &index, const QVariant &value, in
: mRampNames.at( index.row() - mSymbolNames.size() );
const QString newName = value.toString();

return true;
return isColorRamp
? mStyle->renameColorRamp( name, newName )
: mStyle->renameSymbol( name, newName );
}

case Tags:
@@ -23,7 +23,7 @@
QgsStyle,
QgsStyleProxyModel)
from qgis.testing import start_app, unittest
from qgis.PyQt.QtCore import Qt, QSize
from qgis.PyQt.QtCore import Qt, QSize, QModelIndex
from qgis.PyQt.QtGui import QColor

start_app()
@@ -758,6 +758,33 @@ def testIconSize(self):
self.assertEqual(icon.actualSize(QSize(225, 225)), QSize(200, 180))
model.setProperty('icon_sizes', None)

def testSetData(self):
"""
Test model set data
"""
style = QgsStyle()
style.createMemoryDatabase()

symbol_a = createMarkerSymbol()
symbol_a.setColor(QColor(255, 10, 10))
self.assertTrue(style.addSymbol('a', symbol_a, True))
ramp_a = QgsLimitedRandomColorRamp(5)
self.assertTrue(style.addColorRamp('ramp a', ramp_a, True))

model = QgsStyleModel(style)
self.assertEqual(model.rowCount(), 2)

self.assertEqual(style.symbolNames(), ['a'])

self.assertFalse(model.setData(QModelIndex(), 'b', Qt.EditRole))
self.assertFalse(model.setData(model.index(0, 1), 'b', Qt.EditRole))
self.assertTrue(model.setData(model.index(0, 0), 'new symbol name', Qt.EditRole))
self.assertEqual(model.data(model.index(0, 0), Qt.DisplayRole), 'new symbol name')
self.assertEqual(style.symbolNames(), ['new symbol name'])
self.assertTrue(model.setData(model.index(1, 0), 'ramp new name', Qt.EditRole))
self.assertEqual(model.data(model.index(1, 0), Qt.DisplayRole), 'ramp new name')
self.assertEqual(style.colorRampNames(), ['ramp new name'])


if __name__ == '__main__':
unittest.main()

0 comments on commit 010c2f4

Please sign in to comment.
You can’t perform that action at this time.