PySide6.QtNfc.QNdefFilter¶
- class QNdefFilter¶
- The - QNdefFilterclass provides a filter for matching NDEF messages. More_…- Synopsis¶- Methods¶- def - __init__()
- def - appendRecord()
- def - clear()
- def - match()
- def - orderMatch()
- def - recordAt()
- def - recordCount()
- def - setOrderMatch()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- The - QNdefFilterencapsulates the structure of an NDEF message and is used for matching messages that have a particular structure.- The following filter matches NDEF messages that contain a single smart poster record: - QNdefFilter filter; filter.append(QNdefRecord::NfcRtd, "Sp"); - The following filter matches NDEF messages that contain a URI, a localized piece of text and an optional JPEG image. The order of the records must be in the order specified: - QNdefFilter filter; filter.setOrderMatch(true); filter.appendRecord(QNdefRecord::NfcRtd, "U"); filter.appendRecord<QNdefNfcTextRecord>(); filter.appendRecord(QNdefRecord::Mime, "image/jpeg", 0, 1); - The - match()method can be used to check if a message matches the filter.- Matching Algorithms¶- The filter behavior depends on the value of - orderMatch()parameter.- Note - In the discussion below we will consider the filter records to be equal if their - typeNameFormatand- typeparameters match. Joining two records means adding their- minimumand- maximumvalues, respectively.- Unordered Matching¶- If the record order is not taken into account, all the equal records in the filter can be joined. The resulting filter will contain only unique records, each with the updated - minimumand- maximumvalue.- Consider the following example: - QNdefFilter filter; filter.appendRecord<QNdefNfcTextRecord>(0, 1); filter.appendRecord<QNdefNfcTextRecord>(0, 1); filter.appendRecord(QNdefRecord::Mime, "", 1, 1); filter.appendRecord<QNdefNfcTextRecord>(1, 1); filter.setOrderMatch(false); - With the unordered matching, the filter will be simplified to the following: - QNdefFilter filter; filter.appendRecord<QNdefNfcTextRecord>(1, 3); filter.appendRecord(QNdefRecord::Mime, "", 1, 1); filter.setOrderMatch(false); - Once the filter contains only the unique records, the matching algorithm iterates through the message and calculates the actual amount of records of each type. If all the actual amounts fit in the corresponding [minimum, maximum] ranges, the matching algorithm returns - true.- Ordered Matching¶- If the record order is important, a different approach is applied. In this case the equal records can’t be simply joined together. However, the consecutive equal records can still be joined. Then, the matching algorithm iterates through the message, this time also taking the positions of the records into account. - Handling Empty Type in Filter Record¶- It’s possible to add a filter record with an empty - type. In this case the empty type will act as a wildcard for any type.- For example, the filter can be defined as follows: - QNdefFilter filter; filter.addRecord(QNdefRecord::Mime, "", 1, 1); - This filter specifies that the message must contain exactly one NDEF record with - Mime- typeNameFormat(), and any- type().- Handling Extra Records in the Message¶- If the message contains some records that do not match any record in the filter, the matching algorithm will return - false.- Filter Examples¶- In the table below, each filter record is specified by the following parameters (in the given order): - typeNameFormat- contains the- typeNameFormat() of the record.
- type- contains the- type() of the record.
- minimum- contains the minimum amount of occurrences of the record in the message.
- maximum- contains the maximum amount of occurrences of the record in the message.
 - The filter contains multiple records. - The message consists of multiple - QNdefRecords. In the table below, only the- typeNameFormat() and- type() of each record will be shown, because the other parameters do not matter for filtering.- Filter - Message - Match Result - Comment - Empty filter - Empty message - Match - Empty filter - Non-empty message - No match - Non-empty filter - Empty message - No match - [( - NfcRtd, “T”, 1, 2), (- Mime, “”, 1, 1), (- Empty, “”, 0, 100)]- [( - Mime, “image/jpeg”), (- Empty, “”), (- NfcRtd, “T”), (- Empty, “”), (- NfcRtd, “T”)]- Unordered: match - Ordered filter does not match because the message must start with a - NfcRtdrecord, but it starts with- Mime.- Ordered: no match - [( - NfcRtd, “T”, 0, 2), (- Mime, “”, 1, 1), (- NfcRtd, “T”, 1, 1)]- Unordered: match - Ordered filter does not match because an - NfcRtdrecord is expected after- Mime, but the message does not have it.- Ordered: no match - [( - NfcRtd, “T”, 0, 2), (- NfcRtd, “T”, 1, 1), (- Mime, “”, 1, 1)]- Unordered: match - Both cases match because the message contains the required minimum of records in the correct order. - Ordered: match - __init__()¶
 - Constructs a new NDEF filter. - __init__(other)
- Parameters:
- other – - QNdefFilter
 
 - Constructs a new NDEF filter that is a copy of - other.- Verifies the - recordand appends it to the NDEF filter.- Returns - trueif the record was appended successfully. Otherwise returns- false.- appendRecord(typeNameFormat, type[, min=1[, max=1]])
- Parameters:
- typeNameFormat – - TypeNameFormat
- type – - QByteArray
- min – int 
- max – int 
 
- Return type:
- bool 
 
 - Appends a record with type name format - typeNameFormatand type- typeto the NDEF filter. The record must occur between- minand- maxtimes in the NDEF message.- Returns - trueif the record was appended successfully. Otherwise returns- false.- clear()¶
 - Clears the filter. - match(message)¶
- Parameters:
- message – - QNdefMessage
- Return type:
- bool 
 
 - Returns - trueif the- messagematches the given filter. Otherwise returns- false.- See - Matching Algorithmsfor more detailed explanation of matching.- orderMatch()¶
- Return type:
- bool 
 
 - Returns - trueif the filter takes NDEF record order into account when matching. Otherwise returns- false.- See also - Returns the NDEF record at index - i.- imust be a valid index (i.e. 0 <= i <- recordCount()).- See also - recordCount()¶
- Return type:
- int 
 
 - Returns the number of NDEF records in the filter. - setOrderMatch(on)¶
- Parameters:
- on – bool 
 
 - Sets the ordering requirements of the filter. If - onis- true, the filter will only match if the order of records in the filter matches the order of the records in the NDEF message. If- onis- false, the order of the records is not taken into account when matching.- By default record order is not taken into account. - See also - class Record¶
- Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- PySide6.QtNfc.QNdefFilter.Record.typeNameFormat¶
 - PySide6.QtNfc.QNdefFilter.Record.type¶
 - PySide6.QtNfc.QNdefFilter.Record.minimum¶
 - PySide6.QtNfc.QNdefFilter.Record.maximum¶