aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-10-09 11:04:01 +0000
committerBibiko <bibiko@eva.mpg.de>2010-10-09 11:04:01 +0000
commit6b60ddf1029b912586f80b6b7727f8083fb122ea (patch)
treef140424ab4acd2cda8fa1adf52cec74740b68a04 /Source
parent869e355e7f4856dee3171520f549e32855f68dc5 (diff)
downloadsequelpro-6b60ddf1029b912586f80b6b7727f8083fb122ea.tar.gz
sequelpro-6b60ddf1029b912586f80b6b7727f8083fb122ea.tar.bz2
sequelpro-6b60ddf1029b912586f80b6b7727f8083fb122ea.zip
• enabled thumbnail images of spatial geometry fields as tooltips
- note: geometrycollection support will follow soon
Diffstat (limited to 'Source')
-rw-r--r--Source/SPCustomQuery.m10
-rw-r--r--Source/SPGeometryDataView.h5
-rw-r--r--Source/SPGeometryDataView.m61
-rw-r--r--Source/SPTableContent.m16
4 files changed, 67 insertions, 25 deletions
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index 74505e23..ca045d92 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -45,6 +45,7 @@
#import "SPAlertSheets.h"
#import "SPMainThreadTrampoline.h"
#import "SPCopyTable.h"
+#import "SPGeometryDataView.h"
#import <BWToolkitFramework/BWToolkitFramework.h>
@@ -2222,7 +2223,14 @@
}
}
else if ([theValue isKindOfClass:[MCPGeometryData class]]) {
- ; // TODO
+ SPGeometryDataView *v = [[SPGeometryDataView alloc] initWithCoordinates:[theValue coordinates]];
+ image = [v thumbnailImage];
+ if(image) {
+ [SPTooltip showWithObject:image atLocation:pos ofType:@"image"];
+ [v release];
+ return nil;
+ }
+ [v release];
}
// Show the cell string value as tooltip (including line breaks and tabs)
diff --git a/Source/SPGeometryDataView.h b/Source/SPGeometryDataView.h
index c40cff97..fa1168c5 100644
--- a/Source/SPGeometryDataView.h
+++ b/Source/SPGeometryDataView.h
@@ -27,6 +27,9 @@
@interface SPGeometryDataView : NSView
{
+
+ NSWindow *geometryDataWindow;
+
NSString *type;
NSArray *coordinates;
CGFloat x_min;
@@ -43,6 +46,6 @@
- (id)initWithCoordinates:(NSDictionary*)coord;
- (void)setMax:(NSArray*)bbox;
- (NSPoint)normalizePoint:(NSPoint)aPoint;
-- (NSImage*)image;
+- (NSImage*)thumbnailImage;
@end
diff --git a/Source/SPGeometryDataView.m b/Source/SPGeometryDataView.m
index 0a5a0294..ee27f15f 100644
--- a/Source/SPGeometryDataView.m
+++ b/Source/SPGeometryDataView.m
@@ -33,51 +33,63 @@
- (id)initWithCoordinates:(NSDictionary*)coord
{
+ CGFloat maxDim;
+ CGFloat targetDim = 400.0;
+
margin_offset = 10.0;
type = [coord objectForKey:@"type"];
coordinates = [coord objectForKey:@"coordinates"];
+
x_min = (CGFloat)[[[coord objectForKey:@"bbox"] objectAtIndex:0] doubleValue];
x_max = (CGFloat)[[[coord objectForKey:@"bbox"] objectAtIndex:1] doubleValue];
y_min = (CGFloat)[[[coord objectForKey:@"bbox"] objectAtIndex:2] doubleValue];
y_max = (CGFloat)[[[coord objectForKey:@"bbox"] objectAtIndex:3] doubleValue];
- zoom_factor = 1.0;
width = x_max - x_min;
height = y_max - y_min;
- // make it a square due to aspect ratio
- if(width>height)
- height = width;
+ maxDim = (width > height) ? width : height;
+ if(maxDim != 0)
+ zoom_factor = targetDim/maxDim;
else
- width = height;
+ zoom_factor = 1.0;
+
+ width*=zoom_factor;
+ height*=zoom_factor;
+ x_min*=zoom_factor;
+ y_min*=zoom_factor;
if ( self = [super initWithFrame:NSMakeRect(0,0,width+margin_offset*2,height+margin_offset*2)] )
{
;
}
+
return self;
}
- (NSPoint)normalizePoint:(NSPoint)aPoint
{
+ aPoint.x*=zoom_factor;
+ aPoint.y*=zoom_factor;
aPoint.x-=x_min;
aPoint.y-=y_min;
aPoint.x+=margin_offset;
aPoint.y+=margin_offset;
-
return aPoint;
}
- (void)drawPoint:(NSPoint)aPoint
{
+
NSBezierPath *circlePath = [NSBezierPath bezierPath];
- [circlePath appendBezierPathWithOvalInRect:NSMakeRect(aPoint.x-2,aPoint.y-2,4,4)];
+ [circlePath appendBezierPathWithOvalInRect:NSMakeRect(aPoint.x-5,aPoint.y-5,10,10)];
[[NSColor grayColor] setStroke];
[[NSColor redColor] setFill];
[circlePath stroke];
[circlePath fill];
+
}
- (void)drawRect:(NSRect)dirtyRect
@@ -86,14 +98,17 @@
if(!type || ![type length] || !coordinates || ![coordinates count]) return;
NSBezierPath *path;
- NSColor *polyFillColor = [NSColor colorWithCalibratedRed:.5 green:.5 blue:0.5 alpha:0.05];
+ NSColor *polyFillColor1 = [NSColor colorWithCalibratedRed:0.0 green:1.0 blue:0.0 alpha:0.1];
+ NSColor *polyFillColor2 = [NSColor colorWithCalibratedRed:0.0 green:1.0 blue:1.0 alpha:0.1];
+ NSColor *polyFillColor3 = [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.1];
BOOL isFirst = YES;
NSPoint aPoint;
+ // Draw a rect as border
path = [NSBezierPath bezierPathWithRect:[self bounds]];
[path setLineWidth:0.1];
- [[NSColor whiteColor] set];
+ [[NSColor colorWithCalibratedRed:1 green:1 blue:1 alpha:0.96] set];
[path fill];
[[NSColor grayColor] set];
[path stroke];
@@ -109,7 +124,6 @@
else if([type hasSuffix:@"LINESTRING"]) {
for(NSArray* lines in coordinates) {
- path = [NSBezierPath bezierPath];
isFirst = YES;
for(NSString* coord in lines) {
aPoint = [self normalizePoint:NSPointFromString(coord)];
@@ -126,6 +140,7 @@
}
}
else if([type hasSuffix:@"POLYGON"]) {
+ NSUInteger i = 0;
for(NSArray* polygons in coordinates) {
isFirst = YES;
for(NSString* coord in polygons) {
@@ -139,21 +154,37 @@
[self drawPoint:aPoint];
}
[[NSColor blackColor] setStroke];
- [polyFillColor setFill];
+ switch(i) {
+ case 0: [polyFillColor1 setFill];
+ break;
+ case 1: [polyFillColor2 setFill];
+ break;
+ case 2: [polyFillColor3 setFill];
+ break;
+ }
[path fill];
[path stroke];
+ i++;
+ if(i>2) i=0;
}
}
}
-- (NSImage*)image
+- (NSImage*)thumbnailImage
{
- [self drawRect:[self bounds]];
+ if(!type || ![type length] || !coordinates || ![coordinates count]) return nil;
+
+ NSSize mySize = self.bounds.size;
+ NSSize imgSize = NSMakeSize( mySize.width, mySize.height );
+ NSRect myBounds = [self bounds];
+
+ NSBitmapImageRep *bitmap = [self bitmapImageRepForCachingDisplayInRect:myBounds];
+ [bitmap setSize:imgSize];
+ [self cacheDisplayInRect:myBounds toBitmapImageRep:bitmap];
- NSImage *image = [[[NSImage alloc] initWithSize:[self bounds].size] autorelease];
- NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:[self bounds]] autorelease];
+ NSImage* image = [[[NSImage alloc]initWithSize:imgSize] autorelease];
[image addRepresentation:bitmap];
return image;
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 3aa154a7..760526c9 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -3350,14 +3350,14 @@
}
}
else if ([theValue isKindOfClass:[MCPGeometryData class]]) {
- // SPGeometryDataView *v = [[SPGeometryDataView alloc] initWithCoordinates:[theValue coordinates]];
- // image = [v image];
- // if(image) {
- // [SPTooltip showWithObject:image atLocation:pos ofType:@"image"];
- // [v release];
- // return nil;
- // }
- // [v release];
+ SPGeometryDataView *v = [[SPGeometryDataView alloc] initWithCoordinates:[theValue coordinates]];
+ image = [v thumbnailImage];
+ if(image) {
+ [SPTooltip showWithObject:image atLocation:pos ofType:@"image"];
+ [v release];
+ return nil;
+ }
+ [v release];
}
// Show the cell string value as tooltip (including line breaks and tabs)