enumerations.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "enumerations.h"
  2. Enumerations::Enumerations()
  3. {
  4. }
  5. struct Enumerations::enumeration Enumerations::get ( int enumeration_id )
  6. {
  7. return this->id2enumeration[enumeration_id];
  8. }
  9. QHash<QString, QList<struct Enumerations::enumeration>> Enumerations::get ( Enumerations::item_type item_type )
  10. {
  11. return this->itemType2enumeration[item_type];
  12. }
  13. void Enumerations::clear()
  14. {
  15. this->id2enumeration.clear();
  16. this->itemType2enumeration.clear();
  17. }
  18. void Enumerations::add ( QJsonObject json_enumeration )
  19. {
  20. struct enumeration enumeration;
  21. enumeration.id = json_enumeration["id"].toInt();
  22. enumeration.name = json_enumeration["name"].toString();
  23. enumeration.position = json_enumeration["position"].toInt();
  24. QString enumeration_fulltype = json_enumeration["type"].toString();
  25. const size_t fulltype_length = enumeration_fulltype.length();
  26. if ( enumeration_fulltype.startsWith ( "issue_" ) ) {
  27. enumeration.item_type = EIT_ISSUE;
  28. enumeration.field_name = enumeration_fulltype.right ( fulltype_length - ( sizeof ( "issue_" ) - 1 ) );
  29. } else if ( enumeration_fulltype.startsWith ( "time_entry_" ) ) {
  30. enumeration.item_type = EIT_TIME_ENTRY;
  31. enumeration.field_name = enumeration_fulltype.right ( fulltype_length - ( sizeof ( "time_entry_" ) - 1 ) );
  32. } else if ( enumeration_fulltype.startsWith ( "document_" ) ) {
  33. enumeration.item_type = EIT_DOCUMENT;
  34. enumeration.field_name = enumeration_fulltype.right ( fulltype_length - ( sizeof ( "document_" ) - 1 ) );
  35. } else {
  36. enumeration.item_type = EIT_UNKNOWN;
  37. enumeration.field_name = enumeration_fulltype;
  38. }
  39. this->id2enumeration.insert ( enumeration.id, enumeration );
  40. this->itemType2enumeration[enumeration.item_type][enumeration.field_name].append ( enumeration );
  41. }
  42. void Enumerations::set ( QJsonArray json_array )
  43. {
  44. this->clear();
  45. foreach ( const QJsonValue & val, json_array )
  46. this->add ( val.toObject() );
  47. }