Graph* MultiLayer::addLayer()
{
addLayerButton();
	
Graph* g = new Graph(canvas,0,WDestructiveClose);
g->setGeometry(QRect(0,0,graph_width, graph_height));
g->plotWidget()->resize(QSize(graph_width, graph_height));	
graphsList->append(g);
active_graph=g;
g->show();
connectLayer(g);
return g;
}
Graph* MultiLayer::insertFirstLayer()
{
LayerButton *btn = addLayerButton();	
Graph* g = new Graph(canvas,0,0);	

g->setGeometry(QRect(0,0,graph_width,graph_height));
g->plotWidget()->resize(QSize(graph_width,graph_height));
connectLayer(g);
setGeometry(QRect(0, 0,graphs*graph_width,rows*graph_height+btn->height()));
g->setIgnoreResizeEvents(true);

active_graph=g;
graphsList->append(g);
return g;
}
Graph* MultiLayer::addLayer(int x, int y, int width, int height)
{
addLayerButton();
	
Graph* g = new Graph(canvas,0,WDestructiveClose);
g->removeLegend();

QSize size=QSize(width,height);
g->plotWidget()->resize(size);
g->setGeometry(x,y,width,height);

graphsList->append(g);
active_graph=g;
g->show();
return g;
}
Graph *MultiLayer::addLayer(int x, int y, int width, int height) {
  addLayerButton();
  if (!width && !height) {
    width = graph_width;
    height = graph_height;
  }
  removeLayoutButton->setEnabled(true);

  Graph *g = new Graph(canvas);
  g->setAttribute(Qt::WA_DeleteOnClose);
  g->setGeometry(x, y, width, height);
  g->plotWidget()->resize(QSize(width, height));
  graphsList.append(g);

  active_graph = g;
  g->show();
  connectLayer(g);
  return g;
}
Graph* MultiLayer::addLayer(int x, int y, int width, int height)
{
	addLayerButton();
	if (!width && !height){
		width =	canvas->width() - left_margin - right_margin - (d_cols - 1)*colsSpace;
		height = canvas->height() - top_margin - left_margin - (d_rows - 1)*rowsSpace;

		int layers = graphsList.size();
		x = left_margin + (layers % d_cols)*(width + colsSpace);
	    y = top_margin + (layers / d_cols)*(height + rowsSpace);
	}

	Graph* g = new Graph(x, y, width, height, canvas);
    g->show();
	graphsList.append(g);

	active_graph = g;
	connectLayer(g);
	return g;
}
Graph* MultiLayer::addLayerToOrigin()
{
addLayerButton();
	
Graph* g = new Graph(canvas,0,0);
g->removeLegend();

int w = canvas->width();
int h = canvas->height();
g->setGeometry(QRect(0, 0, w, h));
g->plotWidget()->resize(QSize(w,h));
graphsList->append(g);
	
connectLayer(g);
active_graph=g;

makeTransparentLayer(g);
g->show();
emit modifiedPlot();
return g;
}