[OpendTect_Developers] New procedure for save changes at close/survey-change

Kristofer Tingdahl kristofer.tingdahl at dgbes.com
Tue Feb 15 17:25:52 CET 2011


Dear fellow developers!

In OpendTect 4.2 and later, there is a new functionality for asking the user
if he wants to save various things before the survey changes or OpendTect is
closes. Previously, there were many different dialogs that would pop up in
sequence prompting the user to save certain things. In the new system, there
is one dialog that has a list of all unsaved objects, with buttons to save
them. It also features a 'Cancel' button, so the survey changes or closing
of OpendTect can be aborted.

The sequence of events goes like this at a survey change or OpendTect
closure:

   1. NotSavedPrompter::doTrigger() is called from OpendTect.
   2. NotSavedPrompter triggers its promptSaving notifier
   3. Objects in OpendTect that are not saved add themselves to the
   NotSavedPrompter by the addObject() function.
   4. A dialog is displayed with all the unsaved objects.
   5. The user selects which objects he wants to save, and for each one, a
   callback is triggered. If the object is saved successfully, that object will
   be grayed out in the list.
   6. When the user is finished, he presses OK, and OpendTect closes or
   moves on to a new survey.

As we have been very busy with other things around dGB Earth Sciences (i.e.
the fantastic HorizonCube), we have not implemented the changes for many 'in
house' objects in 4.2, but we are gradually moving there for future
releases.

The interface for this new functionality is found in
include/uiTools/uinotsaveddlg.h

To utilize the new functionality, there are a couple of things you have to
do:

1. Let the NotSavedPrompter know about the existence of your object. You do
that by subscribing to the promptSaving notifier.

MyClass::MyClass()
{
    NotSavedPrompter::NSP().promptSaving.notify(
        mCB(this,MyClass,askSaveCB) );
}

2. Let NotSavedPrompter know when you are going out of business.

MyClass::~MyClass()
{
    NotSavedPrompter::NSP().promptSaving.remove(
        mCB(this,MyClass,askSaveCB) );
}

3. Implement code that checks if your object is not saved, and if it is not,
the NotSavedPrompter should be informed, so the dialog can include your
object.

void MyClass::askSaveCB( CallBacker* )
{
    if ( not_saved )
    {
        BufferString str("Object type \"" );
        str += name(); str += "\"";

        PtrMan<IOObj> ioobj = IOM().get( mid );
        const bool issaveas = (bool) ioobj;

        NotSavedPrompter::NSP().addObject( new NotSavedPrompter::Data(
            str.buf(), mCB(this,MyClass,saveCB()), issaveas, 0 ) );
    }
}

4. Implement code that saves the object:

void MyClass::saveCB( CallBacker* )
{
    if ( NotSavedPrompter::NSP().isSaveAs() )
    {
        uiParent* uip = NotSavedPrompter::NSP().getParent();
        //Start dlg with uiparent and get new name
    }

    if ( successfulSave )
        NotSavedPrompter::NSP().reportSuccessfullSave()
}


Happy coding!

-- 
Kristofer Tingdahl, Ph. D.
Executive Vice President - Americas
dGB Earth Sciences
+1 281 240 3939
http://www.dgbes.com

<http://www.dgbes.com>Join us our page on
facebook<http://www.facebook.com/pages/OpendTect/116868268369067>
!




-- 
Kristofer Tingdahl, Ph. D.
Executive Vice President - Americas
dGB Earth Sciences
+1 281 240 3939
http://www.dgbes.com

Join our page on
facebook<http://www.facebook.com/pages/OpendTect/116868268369067>
!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20110215/52310806/attachment.html>


More information about the Developers mailing list