Ejemplo n.º 1
0
void StationTreeView::contextMenuEvent( QContextMenuEvent* event )
{
	QModelIndex index = this->selectionModel()->currentIndex();
	ModelTreeItem* item = static_cast<ModelTreeItem*>(index.internalPointer());

	if (!item)  // Otherwise sometimes it crashes when (unmotivated ;-) ) clicking in a treeview
		return;

	// The current index refers to a parent item (e.g. a listname)
	if (item->childCount() > 0)
	{
		QMenu menu;
		QAction* propertyAction = menu.addAction("Display list properties...");
		QAction* exportAction   = menu.addAction("Export to GMS...");
		QAction* saveAction   = menu.addAction("Save to file...");
		menu.addSeparator();
		QAction* removeAction   = menu.addAction("Remove station list");

		connect(propertyAction, SIGNAL(triggered()), this, SLOT(showPropertiesDialog()));
		connect(exportAction,   SIGNAL(triggered()), this, SLOT(exportList()));
		connect(saveAction,   SIGNAL(triggered()), this, SLOT(saveList()));
		connect(removeAction,   SIGNAL(triggered()), this, SLOT(removeStationList()));
		menu.exec(event->globalPos());
	}
	// The current index refers to a station object
	else
	{
		QString temp_name;
		QMenu menu;

		if (static_cast<StationTreeModel*>(model())->stationFromIndex(index,
		                                                              temp_name)->type() ==
		    GeoLib::Station::BOREHOLE)
		{
			QAction* stratAction = menu.addAction("Display Stratigraphy...");
			QAction* exportAction = menu.addAction("Export to GMS...");
			connect(stratAction, SIGNAL(triggered()), this, SLOT(displayStratigraphy()));
			connect(exportAction, SIGNAL(triggered()), this, SLOT(exportStation()));
			menu.exec(event->globalPos());
		}
		else
		{
			menu.addAction("View Information...");
			QAction* showDiagramAction = menu.addAction("View Diagram...");
			connect(showDiagramAction, SIGNAL(triggered()), this,
			        SLOT(showDiagramPrefsDialog()));
			menu.exec(event->globalPos());
		}
	}
}
Ejemplo n.º 2
0
/**
 * Removes the TreeItem with the given Index including all its children
 */
void StationTreeModel::removeStationList(QModelIndex index)
{
	if (index.isValid()) //
	{
		ModelTreeItem* item = static_cast<ModelTreeItem*>(getItem(index));

		// also delete the lists entry in the list directory of the model
		for (size_t i = 0; i < _lists.size(); i++)
			if (item == _lists[i])
				_lists.erase(_lists.begin() + i);

		removeRows(0, item->childCount(), index);
		removeRows(item->row(), 1, parent(index));
	}
}