Report Viewer Delegate

Description: class implementing a protocol of report viewer delegate and a protocol for views that open by means of popup windows.

The ProceduralReportImpl.h File

#import <Foundation/Foundation.h>
#import "MAProceduralDelegate.h"
#import "MANotesViewController.h"
#import "MAProceduralReportDataViewController.h"
// Class implementing a protocol of report viewer delegate and a protocol for views that open by means of popup windows
@interface ProceduralDelegateImpl : NSObject<ProceduralDelegate, PopoverContainedControllerProtocol>
// Regular report sheet viewer view
@property (nonatomic, retain) MAProceduralReportDataViewController *dataViewController;
// Popup window
@property (nonatomic, assign) UIPopoverController *popover;
// Create an initializes class instance and sets value of regular report sheet viewer view
- (id) initWithProceduralReportDataViewController: (MAProceduralReportDataViewController *)dataViewController;
// Hides note without saving changes
- (void)cancelNote;
// Opens note for edit
// index - note index
- (void)openNoteAtIndex:(int)index;
@end

The ProceduralReportImpl.m File

#import "ProceduralDelegateImpl.h"
@implementation ProceduralDelegateImpl
// Creates a initializes class instance and sets value of regular report sheet viewer view
- (id) initWithProceduralReportDataViewController: (MAProceduralReportDataViewController *)dataViewController
{
    self = [super init];
    if (self)
    {
        // Set value of regular report sheet viewer view
        _dataViewController = dataViewController;
        // Set  empty value for popup window
        _popover = nil;
    }
    return self;
}
// Opens note for edit
// index - note index
- (void)openNoteAtIndex:(int)index
{
    // Get note by its index
    Note *note = [_dataViewController noteByIndex:index];
    // Determine dialog for saving and editing note
    AddNoteDialog *noteDialog = [[AddNoteDialog alloc] init];
    [noteDialog setDelegate:_dataViewController]; // Delegate
    [noteDialog setPoint: [note offset]]; // Note location
    [noteDialog setTimestamp:[note timestamp]]; // Note creation time
    [noteDialog setText:[note text]]; // Note text
    [noteDialog setMode: kNoteDialogNewNote]; // Edit note
    [noteDialog setNoteIndex:index]; // Note index in array of all notes
    // Refresh dialog
    [noteDialog refresh];
    // Set contents size in popup window
    [noteDialog setContentSizeForViewInPopover:CGSizeMake(300.0, 200.0)];
    // Create a popup window
    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:noteDialog] autorelease];
    UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:navController];
    popoverController.delegate = _dataViewController;
    // Display popup window
    [popoverController presentPopoverFromRect:CGRectMake([note offset].x, [note offset].y, 1, 1) inView:[_dataViewController pdfView].scrollView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    // Save popup window in the "popover" property
    _popover = popoverController;
}
// Hides note without saving changes
- (void)cancelNote
{
    // Check if popup window is displayed
    if(_popover != nil)
    {
        // Hide popup window
        [_popover dismissPopoverAnimated:NO];
        // Set empty value for popup window
        _popover = nil;
    }
}
@end

See also:

Working with Notes in Regular Report