Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-27100

Suggested enhancements for QFlags<>

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 5.0.0
    • None
    • All platforms

    Description

      Please consider one or more of the following member functions for addition to the QFlags class template for inclusion in a future release.

      QFlags class
      inline QFlags &operator~=(Enum f) { i &= ~f; return *this; }
      inline QFlags &operator~=(QFlags f) { i &= ~f.i; return *this; }
      
      inline QFlags &setFlag(Enum f) { i |= f; return *this; }
      inline QFlags &unsetFlag(Enum f) { i &= ~f; return *this; }
      

      Justification:
      Testing and combining flags is well-handled in the existing class but whenever a flag needs to be unset, compiler errors are generated (unknown conversion from int to Enum) unless an explicit typecast is used.

      Example
      enum EnumFlag { Enum_1 = 0x1, Enum_2 = 0x2 };
      Q_DECLARE_FLAGS(EnumFlags, Enum)
      Q_DECLARE_OPERATORS_FOR_FLAGS(EnumFlags)
      
      EnumFlags flags(Enum_2);
      
      flags &= ~Enum_2; // compiler error: Enum_2 is converted to int
      flags &= static_cast<EnumFlag>(~Enum_2); // This is acceptable to the compiler but looks like a dog's breakfast
      
      // Usage for proposed new member functions
      flags ~= Enum_2;
      flags.unsetFlag(Enum_2);
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            robbiee Robert Escott
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes