61 #include <QCoreApplication> 67 static int nextTypeId_ = 2;
71 static std::map< DataType, QString > typeToString;
75 static std::map< QString , size_t > stringToTypeInfo;
79 static std::map< DataType , size_t > typeToTypeInfo;
81 static QIcon dummyIcon;
83 static std::vector< TypeInfo > types;
89 stream << type.
value() ;
94 void initializeTypes() {
95 stringToTypeInfo[
"Unknown"] = types.size();
97 typeToTypeInfo[
test] = types.size();
98 types.push_back(
TypeInfo(
DATA_UNKNOWN ,
"Unknown" ,
"Unknown.png", QCoreApplication::translate(
"Types",
"Unknown")) );
100 stringToTypeInfo[
"Group"] = types.size();
102 types.push_back(
TypeInfo(
DATA_GROUP ,
"Group" ,
"group.png", QCoreApplication::translate(
"Types",
"Group")) );
104 stringToTypeInfo[
"All"] = types.size();
105 typeToTypeInfo[
DATA_ALL] = types.size();
106 types.push_back(
TypeInfo(
DATA_ALL ,
"All" ,
"Unknown.png", QCoreApplication::translate(
"Types",
"All")) );
122 std::cerr <<
"Redefinition of existing data type!" << std::endl;
126 int type = nextTypeId_;
128 stringToTypeInfo[ _name ] = types.size();
129 typeToTypeInfo[ type ] = types.size();
130 types.push_back(
TypeInfo(type, _name,
"Unknown.png", _readableName ));
132 typeToString[type] = _name;
141 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _name );
143 if ( index != stringToTypeInfo.end() )
144 return types[ index->second ].type;
147 std::cerr <<
"Unknown Data type with name " << _name.toStdString() << std::endl;
156 std::map<DataType, QString>::iterator name = typeToString.find(_id);
158 if ( name != typeToString.end() )
162 std::cerr <<
"Unable to retrieve typeName for id " << _id << std::endl;
170 return ( stringToTypeInfo.find( _name ) != stringToTypeInfo.end() );
181 return types.begin();
185 std::vector< TypeInfo >::const_iterator
typesEnd() {
192 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _name );
194 if ( index != stringToTypeInfo.end() )
195 return types[ index->second ].iconName;
197 return "Unknown.png";
203 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
205 if ( index != typeToTypeInfo.end() )
206 return types[ index->second ].iconName;
208 return "Unknown.png";
214 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
216 if ( index != typeToTypeInfo.end() )
217 return types[ index->second ].icon;
225 if ( OpenFlipper::Options::gui() ) {
226 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
228 if ( index != typeToTypeInfo.end() ) {
229 types[ index->second ].iconName = _icon;
230 types[ index->second ].icon = QIcon( OpenFlipper::Options::iconDirStr() + QDir::separator() + _icon );
232 std::cerr <<
"Could not set icon for DataType. Type not found!" << std::endl;
239 if ( OpenFlipper::Options::gui() ) {
240 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _name );
242 if ( index != stringToTypeInfo.end() ) {
243 types[ index->second ].iconName = _icon;
244 types[ index->second ].icon = QIcon( OpenFlipper::Options::iconDirStr() + QDir::separator() + _icon );
246 std::cerr <<
"Could not set icon for DataType. Type not found!" << std::endl;
254 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
256 if ( index != typeToTypeInfo.end() )
257 return types[ index->second ].readableName ;
259 std::cerr <<
"Could not get human name for DataType. Type not found!" << std::endl;
261 return QString(QCoreApplication::translate(
"Types",
"Unknown Type"));
267 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _typeName );
269 if ( index != stringToTypeInfo.end() )
270 return types[ index->second ].readableName ;
272 std::cerr <<
"Could not get human name for DataType. Type not found!" << std::endl;
274 return QString(QCoreApplication::translate(
"Types",
"Unknown Type"));
282 std::map<DataType, size_t>::iterator index = typeToTypeInfo.find(_id);
284 if ( index != typeToTypeInfo.end() )
285 types[ index->second ].readableName = _name;
287 std::cerr <<
"Could not set human name for DataType. Type not found!" << std::endl;
293 std::map<QString, size_t>::iterator index = stringToTypeInfo.find( _typeName );
295 if ( index != stringToTypeInfo.end() )
296 types[ index->second ].readableName = _name;
298 std::cerr <<
"Could not set human name for DataType. Type not found!" << std::endl;
302 DataType::DataType():
307 DataType::DataType(
const unsigned int& _i):
314 bool DataType::operator!=(
const unsigned int& _i )
const{
315 return (_i != field);
318 bool DataType::operator!=(
const DataType& _i )
const{
319 return (field != _i.field);
324 bool DataType::operator==(
const unsigned int& _i )
const {
325 return (_i == field);
328 bool DataType::operator==(
const DataType& _i )
const{
329 return (_i.field == field);
334 DataType& DataType::operator=(
const unsigned int& _i ) {
346 bool DataType::operator<(
const unsigned int& _i )
const {
350 bool DataType::operator<(
const DataType& _i )
const {
351 return (field < _i.field);
356 bool DataType::operator&(
const unsigned int& _i )
const {
360 bool DataType::operator&(
const DataType& _i )
const {
361 return (field & _i.field);
368 inv.field = !inv.field;
374 bool DataType::contains(
const DataType& _i )
const{
376 return ( (_i.field & field) == _i.field);
381 DataType& DataType::operator|=(
const unsigned int& _i ) {
394 return (field | _i.field);
399 DataType DataType::operator++(
int ) {
423 qRegisterMetaType<IdList>(
"IdList");
424 qRegisterMetaType<DataType>(
"DataType");
425 qRegisterMetaType< QVector< int > >(
"QVector<int>");
426 qRegisterMetaType<Vector>(
"Vector");
427 qRegisterMetaType<Vector4>(
"Vector4");
428 qRegisterMetaType<Matrix4x4>(
"Matrix4x4");
429 qRegisterMetaType<UpdateType>(
"UpdateType");
430 qRegisterMetaType<Logtype>(
"LogType");
size_t typeCount()
Return the number of registered types.
std::vector< TypeInfo >::const_iterator typesBegin()
Get iterator pointing to the first element in the tyoes list.
void setTypeIcon(DataType _id, QString _icon)
Set the icon for a given dataType.
QString typeIconName(QString _name)
Get the icon of a given dataType.
DataType typeId(QString _name)
Get the id of a type with given name.
QString typeName(DataType _id)
Get the name of a type with given id.
std::vector< TypeInfo >::const_iterator typesEnd()
Get iterator pointing to the last element in the tyoes list.
const DataType DATA_UNKNOWN(0)
None of the other Objects.
std::ostream & operator<<(std::ostream &_o, const Timer &_t)
QString name() const
Return the name of this type as text.
bool typeExists(QString _name)
Check if a type with the given name exists.
const DataType DATA_GROUP(1)
Items used for Grouping.
unsigned int value() const
void setDataTypeName(DataType _id, QString _name)
Set the icon for a given dataType.
QIcon & typeIcon(DataType _id)
get the icon of a given dataType
QString dataTypeName(DataType _id)
Get DataType Human readable name ( this name might change. Use the typeName insted! ) ...
DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.