Esempio n. 1
0
/**
 * Provides the data to display/edit for a given index and role.
 * @param  index The index for which data is requested
 * @param  role  The requested role
 * @return The relevant data
 */
QVariant LexerStyleModel::data(const QModelIndex& index, int role) const
{
	const Node* node = nodeFromIndex(index);
	if (node == NULL || node->data() == NULL)
		return 0;

	if (node->data()->type() == StyleNode) {
		// Get the lexer and style ID for this node.
		StyleData* data = static_cast<StyleData*>(node->data());
		QsciLexer* lexer = data->lexer_;
		int style = data->style_;

		switch (index.column()) {
		case 0:
			// Show language name or style name in the first column.
			if (role == Qt::DisplayRole) {
				if (style == lexer->defaultStyle())
					return lexer->language();

				return lexer->description(style);
			}
			break;

		case 1:
			// Show a formatted text string in the second column, using the
			// style's properties.
			return styleData(node, role);
		}
	}
	else {
		// Get the lexer and style ID for this node.
		PropertyData* data = static_cast<PropertyData*>(node->data());

		switch (index.column()) {
		case 0:
			if (role == Qt::DisplayRole)
				return propertyName(data->prop_);
			break;

		case 1:
			return propertyData(data, role);
		}
	}

	return QVariant();
}