From e6636042890e1dbfc442dfa0fedd9797c7cb8eff Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Sat, 10 Mar 2012 13:37:44 +0000 Subject: Make common code KVC compliant, and implement NSCopying where relevant git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@420 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64 --- tikzit/src/common/NodeStyle.m | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'tikzit/src/common/NodeStyle.m') diff --git a/tikzit/src/common/NodeStyle.m b/tikzit/src/common/NodeStyle.m index b3d9ab2..8d8b83f 100644 --- a/tikzit/src/common/NodeStyle.m +++ b/tikzit/src/common/NodeStyle.m @@ -28,7 +28,7 @@ + (int) defaultStrokeThickness { return 1; } -- (id)init { +- (id)initWithName:(NSString*)nm { self = [super initWithNotificationName:@"NodeStylePropertyChanged"]; if (self != nil) { strokeThickness = [NodeStyle defaultStrokeThickness]; @@ -36,21 +36,41 @@ strokeColorRGB = [[ColorRGB alloc] initWithRed:0 green:0 blue:0]; fillColorRGB = [[ColorRGB alloc] initWithRed:255 green:255 blue:255]; - name = @"new"; + name = nm; category = nil; shapeName = SHAPE_CIRCLE; } return self; } -- (id)initWithName:(NSString*)nm { - self = [self init]; - if (self != nil) { - [self setName:nm]; - } +- (id)init { + self = [self initWithName:@"new"]; return self; } +- (id)copyWithZone:(NSZone*)zone { + NodeStyle *style = [[NodeStyle allocWithZone:zone] init]; + + [style setStrokeThickness:[self strokeThickness]]; + [style setScale:[self scale]]; + [style setStrokeColorRGB:[self strokeColorRGB]]; + [style setFillColorRGB:[self fillColorRGB]]; + [style setName:[self name]]; + [style setShapeName:[self shapeName]]; + [style setCategory:[self category]]; + + return style; +} + +- (void)dealloc { + [name release]; + [category release]; + [shapeName release]; + [strokeColorRGB release]; + [fillColorRGB release]; + [super dealloc]; +} + + (NodeStyle*)defaultNodeStyleWithName:(NSString*)nm { return [[[NodeStyle alloc] initWithName:nm] autorelease]; } @@ -164,11 +184,6 @@ return ([fillColorRGB name] != nil); } -- (void)dealloc { - [self setName:nil]; - [super dealloc]; -} - @end // vi:ft=objc:ts=4:noet:sts=4:sw=4 -- cgit v1.2.3