view data/model/QueryModel.h @ 242:60e84bb658bc

integration of new sparql query
author lbajardsilogic
date Thu, 27 Mar 2008 16:53:45 +0000
parents 59d84a8bb76c
children
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*	Sound Access	
		EASAIER client application.	
		Silogic 2007. Laure Bajard. 
	
	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 (at your option) any later version.  See the file    
	COPYING included with this distribution for more information.
*/

#ifndef _QUERY_MODEL_H_
#define _QUERY_MODEL_H_

#include <QStringList>

#include <map>

#include "base/PropertyContainer.h"

class QueryThemeModel;

class QueryModel {

public:
	QueryModel();
	virtual ~QueryModel();

	void addTheme(const QString &name, const QString &label);
	void newGroup(const QString &name, const QString &label);
	void addProperty(const QString &name, const QString &label, const QString &type, const QString &range="", const QString &unit="", const QString &comment="");

	void addRange(const QString &propertyName, const QString &range);

	inline std::map<QString , QueryThemeModel* >& getThemes(){return m_themeModels;}

protected:

	std::map<QString , QueryThemeModel* >		m_themeModels;

	QueryThemeModel		*m_curThemeModel;

};

class QueryThemeModel : public PropertyContainer {

	Q_OBJECT
public:
	QueryThemeModel(const QString &name, const QString &label);
	virtual ~QueryThemeModel();

	void newGroup(const QString &name, const QString &label);

	void addProperty(const QString &name, const QString &label, const QString &type, const QString &range, const QString &unit, const QString &comment);

	inline QString getName() const {return m_name;}
	inline QString getLabel() const {return m_label;}

	virtual PropertyList getProperties() const;
	virtual QString getPropertyLabel(const PropertyName &name) const;
	virtual PropertyType getPropertyType(const PropertyName &name) const;
    virtual int getPropertyRangeAndValue(const PropertyName &name, int *min, int *max) const;
    virtual QString getPropertyValueLabel(const PropertyName &name, int value) const;

	QString getPropertyValue(const PropertyName &name) const;
	QStringList getPropertyRange(const PropertyName &name) const;

	virtual QString getPropertyContainerName() const {return objectName();}
	virtual QString getPropertyContainerIconName() const {return "";}

	QString getPropertyGroup(const PropertyName &name) const;
	QString getPropertyGroupLabel(const PropertyName &name) const;

	QString getPropertyUnit(const PropertyName &name) const;
	QString getPropertyComment(const PropertyName &name) const;

	virtual void setProperty(const PropertyName &name, int value);

	void addRange(const QString &propertyName, const QString &range);

public slots:
	void setProperty(const PropertyName &name, QString value);
	void setProperty(int value);
	void setProperty(QString value);

protected:

	class PropertyModel
	{
	public:
		PropertyModel(const QString &name, const QString &label, const QString &type, 
			const QString &range, const QString &unit, const QString &comment, 
			const QString &groupName, const QString &groupLabel);
		virtual ~PropertyModel(){};

		inline QString		getLabel() const {return m_label;}
		inline PropertyType getType() const {return m_type;}
		inline QStringList	getRange() const {return m_range;}
		inline QString		getUnit() const {return m_unit;}
		inline QString		getComment() const {return m_comment;}
		inline QString		getValueLabel(int value) const {return m_range.at(value);}
		inline int		getMinRange() const {return m_min;}
		inline int		getMaxRange() const {return m_max;}

		inline QString		getGroupName() const {return m_groupName;}
		inline QString		getGroupLabel() const {return m_groupLabel;}

		inline QString		getValue() const {return m_value;}

		void setValue(int value){if (m_type == ValueProperty) {m_value = m_range.at(value);} else {m_value = QString::number(value);}}
		void setValue(QString value){m_value = value;}

		void addRange(const QString &range); 
		
	protected:
		QString			m_name;
		QString			m_label;
		PropertyType	m_type;
		QString			m_unit;
		QString			m_comment;
		
		QStringList		m_range;
		int				m_min;
		int				m_max;

		QString			m_groupName;
		QString			m_groupLabel;

		QString			m_value;
	};

	PropertyList						m_propertiesName;
	std::map<QString, PropertyModel*>	m_properties;

	QString		m_name;
	QString		m_label;

	QString		m_curGroupName;
	QString		m_curGroupLabel;
};

#endif