/* -------------------------- gnuMultiFunc class --------------------------

   This class handles all operations related to the storage and retrieval of 
   multiple functions and their options. These should be called from
   gnuInterface. 

   It is currently implemented with Qt's dictionary datastructure for keeping
   up with a list of plotFileOb's. 

   This file is part of Xgfe: X Windows GUI front end to Gnuplot
   Copyright (C) 1998 David Ishee

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

   ------------------------------------------------------------------------*/

#include "gnuMultiFunc.h"

gnuMultiFunc::gnuMultiFunc()
{
  // create new function list
  funcList = new QDict<gnuPlotFunction>(101,TRUE); // max 100 elements
  funcList->setAutoDelete(TRUE); // autodelete members when removed

  // create new iterator
  funcListIterator = new QDictIterator<gnuPlotFunction>(*funcList);
}

void gnuMultiFunc::insertMultiFuncNew(string function)
{
  gnuPlotFunction* thisFunc = new gnuPlotFunction; // create a new plot function

  thisFunc->setFunction(function); // set function
  funcList->insert(function.c_str(),thisFunc); // insert into list
}

void gnuMultiFunc::removeMultiFunc(string function)
{
  funcList->remove(function.c_str());
}

void gnuMultiFunc::setMultiFuncStyleOption(string function, string style)
{
  tempFunc = (*funcList)[function.c_str()];
  tempFunc->setFunctionStyleType(style);
}

string gnuMultiFunc::getMultiFuncStyleOption(string function)
{
  tempFunc = (*funcList)[function.c_str()];
  return tempFunc->getFunctionStyleType();
}

string gnuMultiFunc::getMultiFuncFirstFunction()
{
  // set iterator to first element
  tempFunc = funcListIterator->toFirst();
  
  // check for error (empty list = null)
  if (tempFunc == 0)
    return "END";
  else
  {
    return tempFunc->getFunction();
  }
  
}

string gnuMultiFunc::getMultiFuncNextFunction()
{
  // increment function list iterator
  tempFunc = ++(*funcListIterator);

  // check for error (end of list = null)
  if (tempFunc == 0)
    return "END";
  else
  {
    // get and return function
    return tempFunc->getFunction();
  }  
}

string gnuMultiFunc::getMultiFuncFirstPlotCmd()
{
  // set iterator to first element
  tempFunc = funcListIterator->toFirst();
  
  // check for error (empty list = null)
  if (tempFunc == 0)
    return "END";
  else
  {
    // get plot command
    return tempFunc->getPlotCmd();
  }
}

string gnuMultiFunc::getMultiFuncNextPlotCmd()
{
  // increment function list iterator
  tempFunc = ++(*funcListIterator);

  // check for error (end of list = null)
  if (tempFunc == 0)
    return "END";
  else
  {
    // get and return function plotting command
    return tempFunc->getPlotCmd();
  }
}

void gnuMultiFunc::setLegendTitle(string function, string title)
{
  tempFunc = (*funcList)[function.c_str()];
  tempFunc->setLegendTitle(title);
}

string gnuMultiFunc::getLegendTitle(string function)
{
  tempFunc = (*funcList)[function.c_str()];
  return tempFunc->getLegendTitle();
}


syntax highlighted by Code2HTML, v. 0.9.1