void MultiLayer::removeLayer() {
  if (!active_graph) {
    QMessageBox::warning(
        this, tr("Remove Layer error"),
        tr("There are no layers to be removed!"));
    return;
  }
  // remove corresponding button
  LayerButton *btn = 0;
  int i;
  for (i = 0; i < buttonsList.count(); i++) {
    btn = (LayerButton *)buttonsList.at(i);
    if (btn->isOn()) {
      buttonsList.removeAll(btn);
      btn->close(true);
      break;
    }
  }

  // update the texts of the buttons
  for (i = 0; i < buttonsList.count(); i++) {
    btn = (LayerButton *)buttonsList.at(i);
    btn->setText(QString::number(i + 1));
  }

  if (active_graph->zoomOn() || active_graph->activeTool())
    emit setPointerCursor();

  int index = graphsList.indexOf(active_graph);
  graphsList.removeAt(index);
  active_graph->close();
  graphs--;
  if (index >= graphsList.count()) index--;

  if (graphs == 0) {
    active_graph = 0;
    return;
  }

  active_graph = (Graph *)graphsList.at(index);

  for (i = 0; i < (int)graphsList.count(); i++) {
    Graph *gr = (Graph *)graphsList.at(i);
    if (gr == active_graph) {
      LayerButton *button = (LayerButton *)buttonsList.at(i);
      button->setOn(TRUE);
      break;
    }
  }

  emit modifiedPlot();
}
void MultiLayer::setLayersNumber(int n) {
  if (graphs == n) return;

  int dn = graphs - n;
  if (dn > 0) {
    for (int i = 0; i < dn; i++) {  // remove layer buttons
      LayerButton *btn = (LayerButton *)buttonsList.last();
      if (btn) {
        btn->close();
        buttonsList.removeLast();
      }

      Graph *g = (Graph *)graphsList.last();
      if (g) {  // remove layers
        if (g->zoomOn() || g->activeTool()) setPointerCursor();

        g->close();
        graphsList.removeLast();
      }
    }
    graphs = n;
    if (!graphs) {
      active_graph = 0;
      return;
    }

    // check whether the active Graph.has been deleted
    if (graphsList.indexOf(active_graph) == -1)
      active_graph = (Graph *)graphsList.last();
    for (int j = 0; j < (int)graphsList.count(); j++) {
      Graph *gr = (Graph *)graphsList.at(j);
      if (gr == active_graph) {
        LayerButton *button = (LayerButton *)buttonsList.at(j);
        button->setOn(TRUE);
        break;
      }
    }
  } else {
    for (int i = 0; i < abs(dn); i++) addLayer();
  }

  emit modifiedPlot();
}
void MultiLayer::removeLayer()
{			
//remove corresponding button
LayerButton *btn=0;
int i;
for (i=0;i<(int)buttonsList->count();i++)
	{
	btn=(LayerButton*)buttonsList->at(i);	
	if (btn->isOn())	
		{
		buttonsList->take(buttonsList->find(btn));
		btn->close(TRUE);			
		break;
		}
	}
	
//update the texts of the buttons	
for (i=0;i<(int)buttonsList->count();i++)
	{
	 btn=(LayerButton*)buttonsList->at(i);	
	 btn->setText(QString::number(i+1));
	}
	
if (active_graph->selectorsEnabled() || active_graph->zoomOn() || 
	active_graph->removePointActivated() || active_graph->movePointsActivated() || 
	active_graph->enabledCursor()|| active_graph->pickerActivated())
		{
		setPointerCursor();
		}		
		
graphsList->take (graphsList->find(active_graph));
active_graph->close();
graphs--;
		
if (graphs == 0)
	{
	active_graph = 0;
	return;
	}

active_graph=(Graph*) graphsList->current();	

for (i=0;i<(int)graphsList->count();i++)
	{
	Graph *gr=(Graph *)graphsList->at(i);
	if (gr == active_graph)	
		{
		LayerButton *button=(LayerButton *)buttonsList->at(i);	
		button->setOn(TRUE);
		break;
		}
	}	
	
if (graphs)
	hbox1->setMaximumWidth(graphs*((LayerButton *)buttonsList->at(0))->width());

if (hasOverlapingLayers())
	updateTransparency();

emit modifiedPlot();
}