Qt 4.8
Public Types | Public Functions | Static Public Functions | Public Variables | Protected Variables | List of all members
QSettingsPrivate Class Referenceabstract

#include <qsettings_p.h>

Inheritance diagram for QSettingsPrivate:
QObjectPrivate QObjectData QConfFileSettingsPrivate QMacSettingsPrivate QWinSettingsPrivate

Public Types

enum  {
  F_Application = 0x0, F_Organization = 0x1, F_User = 0x0, F_System = 0x2,
  NumConfFiles = 4
}
 
enum  ChildSpec { AllKeys, ChildKeys, ChildGroups }
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Public Functions

QString actualKey (const QString &key) const
 
void beginGroupOrArray (const QSettingsGroup &group)
 
virtual QStringList children (const QString &prefix, ChildSpec spec) const =0
 
virtual void clear ()=0
 
virtual QString fileName () const =0
 
virtual void flush ()=0
 
virtual bool get (const QString &key, QVariant *value) const =0
 
virtual bool isWritable () const =0
 
 QSettingsPrivate (QSettings::Format format)
 
 QSettingsPrivate (QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
 
virtual void remove (const QString &key)=0
 
void requestUpdate ()
 
virtual void set (const QString &key, const QVariant &value)=0
 
void setStatus (QSettings::Status status) const
 
virtual void sync ()=0
 
void update ()
 
virtual ~QSettingsPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static QSettingsPrivatecreate (QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
 
static QSettingsPrivatecreate (const QString &fileName, QSettings::Format format)
 
static void iniEscapedKey (const QString &key, QByteArray &result)
 
static void iniEscapedString (const QString &str, QByteArray &result, QTextCodec *codec)
 
static void iniEscapedStringList (const QStringList &strs, QByteArray &result, QTextCodec *codec)
 
static bool iniUnescapedKey (const QByteArray &key, int from, int to, QString &result)
 
static bool iniUnescapedStringList (const QByteArray &str, int from, int to, QString &stringResult, QStringList &stringListResult, QTextCodec *codec)
 
static QString normalizedKey (const QString &key)
 
static void processChild (QString key, ChildSpec spec, QMap< QString, QString > &result)
 
static QStringList splitArgs (const QString &s, int idx)
 
static QVariant stringListToVariantList (const QStringList &l)
 
static QVariant stringToVariant (const QString &s)
 
static QStringList variantListToStringList (const QVariantList &l)
 
static QString variantToString (const QVariant &v)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

QString applicationName
 
QSettings::Format format
 
QTextCodeciniCodec
 
QString organizationName
 
QSettings::Scope scope
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Protected Variables

bool fallbacks
 
QString groupPrefix
 
QStack< QSettingsGroupgroupStack
 
bool pendingChanges
 
int spec
 
QSettings::Status status
 

Detailed Description

Definition at line 182 of file qsettings_p.h.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
F_Application 
F_Organization 
F_User 
F_System 
NumConfFiles 

Definition at line 245 of file qsettings_p.h.

245  {
246 #if !defined(Q_OS_BLACKBERRY)
247  F_Application = 0x0,
248  F_Organization = 0x1,
249  F_User = 0x0,
250  F_System = 0x2,
251  NumConfFiles = 4
252 #else
253  SandboxConfFile = 0,
254  NumConfFiles = 1
255 #endif
256  };

◆ ChildSpec

Enumerator
AllKeys 
ChildKeys 
ChildGroups 

Definition at line 202 of file qsettings_p.h.

Constructors and Destructors

◆ QSettingsPrivate() [1/2]

QSettingsPrivate::QSettingsPrivate ( QSettings::Format  format)

Definition at line 302 of file qsettings.cpp.

303  : format(format), scope(QSettings::UserScope /* nothing better to put */), iniCodec(0), spec(0), fallbacks(true),
305 {
306 }
QSettings::Scope scope
Definition: qsettings_p.h:259
QTextCodec * iniCodec
Definition: qsettings_p.h:262
QSettings::Format format
Definition: qsettings_p.h:258
QSettings::Status status
Definition: qsettings_p.h:270

◆ QSettingsPrivate() [2/2]

QSettingsPrivate::QSettingsPrivate ( QSettings::Format  format,
QSettings::Scope  scope,
const QString organization,
const QString application 
)

Definition at line 308 of file qsettings.cpp.

310  : format(format), scope(scope), organizationName(organization), applicationName(application),
312 {
313 }
QSettings::Scope scope
Definition: qsettings_p.h:259
QString applicationName
Definition: qsettings_p.h:261
QTextCodec * iniCodec
Definition: qsettings_p.h:262
QSettings::Format format
Definition: qsettings_p.h:258
QSettings::Status status
Definition: qsettings_p.h:270
QString organizationName
Definition: qsettings_p.h:260

◆ ~QSettingsPrivate()

QSettingsPrivate::~QSettingsPrivate ( )
virtual

Definition at line 315 of file qsettings.cpp.

316 {
317 }

Functions

◆ actualKey()

QString QSettingsPrivate::actualKey ( const QString key) const

Definition at line 319 of file qsettings.cpp.

320 {
321  QString n = normalizedKey(key);
322  Q_ASSERT_X(!n.isEmpty(), "QSettings", "empty key");
323  n.prepend(groupPrefix);
324  return n;
325 }
QString & prepend(QChar c)
Definition: qstring.h:261
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QString groupPrefix
Definition: qsettings_p.h:266
static QString normalizedKey(const QString &key)
Definition: qsettings.cpp:338

◆ beginGroupOrArray()

void QSettingsPrivate::beginGroupOrArray ( const QSettingsGroup group)

Definition at line 396 of file qsettings.cpp.

Referenced by create().

397 {
398  groupStack.push(group);
399  if (!group.name().isEmpty()) {
400  groupPrefix += group.name();
401  groupPrefix += QLatin1Char('/');
402  }
403 }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString name() const
Definition: qsettings_p.h:127
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
QString groupPrefix
Definition: qsettings_p.h:266
QStack< QSettingsGroup > groupStack
Definition: qsettings_p.h:265
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ children()

virtual QStringList QSettingsPrivate::children ( const QString prefix,
ChildSpec  spec 
) const
pure virtual

◆ clear()

virtual void QSettingsPrivate::clear ( )
pure virtual

◆ create() [1/2]

QSettingsPrivate * QSettingsPrivate::create ( QSettings::Format  format,
QSettings::Scope  scope,
const QString organization,
const QString application 
)
static

Definition at line 601 of file qsettings_mac.cpp.

Referenced by QWinSettingsPrivate::isWritable(), normalizedKey(), QSettings::QSettings(), and QSettings::registerFormat().

605 {
606 #ifndef QT_BOOTSTRAPPED
607  static bool useAppLocalStorage = false;
608  static bool initialized = false;
609 
610  if (!initialized) {
611  bool inSandbox = false;
612 
613 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
614  // If we are running on at least 10.7.0 and have the com.apple.security.app-sandbox
615  // entitlement, we are in a sandbox
616  SInt32 version = 0;
617  Gestalt(gestaltSystemVersion, &version);
618  SecCodeRef secCodeSelf;
619  if (version >= 0x1070 && SecCodeCopySelf(kSecCSDefaultFlags, &secCodeSelf) == errSecSuccess) {
620  SecRequirementRef sandboxReq;
621  CFStringRef entitlement = CFSTR("entitlement [\"com.apple.security.app-sandbox\"]");
622  if (SecRequirementCreateWithString(entitlement, kSecCSDefaultFlags, &sandboxReq) == errSecSuccess) {
623  if (SecCodeCheckValidity(secCodeSelf, kSecCSDefaultFlags, sandboxReq) == errSecSuccess)
624  inSandbox = true;
625  CFRelease(sandboxReq);
626  }
627  CFRelease(secCodeSelf);
628  }
629 #endif
630 
631  bool forAppStore = false;
632  if (!inSandbox) {
633  CFTypeRef val = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), CFSTR("ForAppStore"));
634  forAppStore = (val &&
635  CFGetTypeID(val) == CFStringGetTypeID() &&
636  CFStringCompare(CFStringRef(val), CFSTR("yes"), kCFCompareCaseInsensitive) == 0);
637  }
638 
639  useAppLocalStorage = inSandbox || forAppStore;
640  initialized = true;
641  }
642 
643  if (useAppLocalStorage) {
644  // Ensure that the global and app-local settings go to the same file, since that's
645  // what we really want
646  if (organization == QLatin1String("Trolltech") ||
647  organization.isEmpty() ||
648  (organization == qApp->organizationDomain() && application == qApp->applicationName()) ||
649  (organization == qApp->organizationName()) && application == qApp->applicationName())
650  {
651  CFStringRef bundleIdentifier = CFBundleGetIdentifier(CFBundleGetMainBundle());
652  if (!bundleIdentifier) {
653  qWarning("QSettingsPrivate::create: You must set the bundle identifier when using ForAppStore");
654  } else {
655  QSettingsPrivate* settings = new QMacSettingsPrivate(bundleIdentifier);
656  if (organization == QLatin1String("Trolltech"))
657  settings->beginGroupOrArray(QSettingsGroup("QtLibrarySettings"));
658  return settings;
659  }
660  }
661  }
662 #endif
663 
665  return new QMacSettingsPrivate(scope, organization, application);
666  } else {
667  return new QConfFileSettingsPrivate(format, scope, organization, application);
668  }
669 }
const struct __CFString * CFStringRef
QSettings::Scope scope
Definition: qsettings_p.h:259
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define qApp
void beginGroupOrArray(const QSettingsGroup &group)
Definition: qsettings.cpp:396
Q_CORE_EXPORT void qWarning(const char *,...)
const void * CFTypeRef

◆ create() [2/2]

QSettingsPrivate * QSettingsPrivate::create ( const QString fileName,
QSettings::Format  format 
)
static

Definition at line 837 of file qsettings_win.cpp.

838 {
840  return new QWinSettingsPrivate(fileName);
841  } else {
842  return new QConfFileSettingsPrivate(fileName, format);
843  }
844 }

◆ fileName()

virtual QString QSettingsPrivate::fileName ( ) const
pure virtual

◆ flush()

virtual void QSettingsPrivate::flush ( )
pure virtual

◆ get()

virtual bool QSettingsPrivate::get ( const QString key,
QVariant value 
) const
pure virtual

◆ iniEscapedKey()

void QSettingsPrivate::iniEscapedKey ( const QString key,
QByteArray result 
)
static

Definition at line 596 of file qsettings.cpp.

Referenced by QConfFileSettingsPrivate::writeIniFile().

597 {
598  result.reserve(result.length() + key.length() * 3 / 2);
599  for (int i = 0; i < key.size(); ++i) {
600  uint ch = key.at(i).unicode();
601 
602  if (ch == '/') {
603  result += '\\';
604  } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')
605  || ch == '_' || ch == '-' || ch == '.') {
606  result += (char)ch;
607  } else if (ch <= 0xFF) {
608  result += '%';
609  result += hexDigits[ch / 16];
610  result += hexDigits[ch % 16];
611  } else {
612  result += "%U";
613  QByteArray hexCode;
614  for (int i = 0; i < 4; ++i) {
615  hexCode.prepend(hexDigits[ch % 16]);
616  ch >>= 4;
617  }
618  result += hexCode;
619  }
620  }
621 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QByteArray & prepend(char c)
Prepends the character ch to this byte array.
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
unsigned int uint
Definition: qglobal.h:996
static const char hexDigits[]
Definition: qsettings.cpp:594
int length() const
Same as size().
Definition: qbytearray.h:356
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449

◆ iniEscapedString()

void QSettingsPrivate::iniEscapedString ( const QString str,
QByteArray result,
QTextCodec codec 
)
static

Definition at line 679 of file qsettings.cpp.

Referenced by iniEscapedStringList(), and QConfFileSettingsPrivate::writeIniFile().

680 {
681  bool needsQuotes = false;
682  bool escapeNextIfDigit = false;
683  int i;
684  int startPos = result.size();
685 
686  result.reserve(startPos + str.size() * 3 / 2);
687  for (i = 0; i < str.size(); ++i) {
688  uint ch = str.at(i).unicode();
689  if (ch == ';' || ch == ',' || ch == '=')
690  needsQuotes = true;
691 
692  if (escapeNextIfDigit
693  && ((ch >= '0' && ch <= '9')
694  || (ch >= 'a' && ch <= 'f')
695  || (ch >= 'A' && ch <= 'F'))) {
696  result += "\\x";
697  result += QByteArray::number(ch, 16);
698  continue;
699  }
700 
701  escapeNextIfDigit = false;
702 
703  switch (ch) {
704  case '\0':
705  result += "\\0";
706  escapeNextIfDigit = true;
707  break;
708  case '\a':
709  result += "\\a";
710  break;
711  case '\b':
712  result += "\\b";
713  break;
714  case '\f':
715  result += "\\f";
716  break;
717  case '\n':
718  result += "\\n";
719  break;
720  case '\r':
721  result += "\\r";
722  break;
723  case '\t':
724  result += "\\t";
725  break;
726  case '\v':
727  result += "\\v";
728  break;
729  case '"':
730  case '\\':
731  result += '\\';
732  result += (char)ch;
733  break;
734  default:
735  if (ch <= 0x1F || (ch >= 0x7F && !codec)) {
736  result += "\\x";
737  result += QByteArray::number(ch, 16);
738  escapeNextIfDigit = true;
739 #ifndef QT_NO_TEXTCODEC
740  } else if (codec) {
741  // slow
742  result += codec->fromUnicode(str.at(i));
743 #endif
744  } else {
745  result += (char)ch;
746  }
747  }
748  }
749 
750  if (needsQuotes
751  || (startPos < result.size() && (result.at(startPos) == ' '
752  || result.at(result.size() - 1) == ' '))) {
753  result.insert(startPos, '"');
754  result += '"';
755  }
756 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
QByteArray fromUnicode(const QString &uc) const
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray...
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
unsigned int uint
Definition: qglobal.h:996
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
QByteArray & insert(int i, char c)
Inserts character ch at index position i in the byte array.

◆ iniEscapedStringList()

void QSettingsPrivate::iniEscapedStringList ( const QStringList strs,
QByteArray result,
QTextCodec codec 
)
static

Definition at line 766 of file qsettings.cpp.

Referenced by QConfFileSettingsPrivate::writeIniFile().

767 {
768  if (strs.isEmpty()) {
769  /*
770  We need to distinguish between empty lists and one-item
771  lists that contain an empty string. Ideally, we'd have a
772  @EmptyList() symbol but that would break compatibility
773  with Qt 4.0. @Invalid() stands for QVariant(), and
774  QVariant().toStringList() returns an empty QStringList,
775  so we're in good shape.
776 
777  ### Qt 5: Use a nicer syntax, e.g. @List, for variant lists
778  */
779  result += "@Invalid()";
780  } else {
781  for (int i = 0; i < strs.size(); ++i) {
782  if (i != 0)
783  result += ", ";
784  iniEscapedString(strs.at(i), result, codec);
785  }
786  }
787 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QTextCodec * codec(MYSQL *mysql)
Definition: qsql_mysql.cpp:220
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static void iniEscapedString(const QString &str, QByteArray &result, QTextCodec *codec)
Definition: qsettings.cpp:679

◆ iniUnescapedKey()

bool QSettingsPrivate::iniUnescapedKey ( const QByteArray key,
int  from,
int  to,
QString result 
)
static

Definition at line 623 of file qsettings.cpp.

Referenced by QConfFileSettingsPrivate::readIniFile(), and QConfFileSettingsPrivate::readIniSection().

624 {
625  bool lowercaseOnly = true;
626  int i = from;
627  result.reserve(result.length() + (to - from));
628  while (i < to) {
629  int ch = (uchar)key.at(i);
630 
631  if (ch == '\\') {
632  result += QLatin1Char('/');
633  ++i;
634  continue;
635  }
636 
637  if (ch != '%' || i == to - 1) {
638  if (uint(ch - 'A') <= 'Z' - 'A') // only for ASCII
639  lowercaseOnly = false;
640  result += QLatin1Char(ch);
641  ++i;
642  continue;
643  }
644 
645  int numDigits = 2;
646  int firstDigitPos = i + 1;
647 
648  ch = key.at(i + 1);
649  if (ch == 'U') {
650  ++firstDigitPos;
651  numDigits = 4;
652  }
653 
654  if (firstDigitPos + numDigits > to) {
655  result += QLatin1Char('%');
656  // ### missing U
657  ++i;
658  continue;
659  }
660 
661  bool ok;
662  ch = key.mid(firstDigitPos, numDigits).toInt(&ok, 16);
663  if (!ok) {
664  result += QLatin1Char('%');
665  // ### missing U
666  ++i;
667  continue;
668  }
669 
670  QChar qch(ch);
671  if (qch.isUpper())
672  lowercaseOnly = false;
673  result += qch;
674  i = firstDigitPos + numDigits;
675  }
676  return lowercaseOnly;
677 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
unsigned char uchar
Definition: qglobal.h:994
static int numDigits(qlonglong n)
Definition: qvalidator.cpp:385
unsigned int uint
Definition: qglobal.h:996
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ iniUnescapedStringList()

bool QSettingsPrivate::iniUnescapedStringList ( const QByteArray str,
int  from,
int  to,
QString stringResult,
QStringList stringListResult,
QTextCodec codec 
)
static

Definition at line 789 of file qsettings.cpp.

Referenced by QConfFileSettingsPrivate::readIniSection().

792 {
793 #ifdef QT_NO_TEXTCODE
794  Q_UNUSED(codec);
795 #endif
796  static const char escapeCodes[][2] =
797  {
798  { 'a', '\a' },
799  { 'b', '\b' },
800  { 'f', '\f' },
801  { 'n', '\n' },
802  { 'r', '\r' },
803  { 't', '\t' },
804  { 'v', '\v' },
805  { '"', '"' },
806  { '?', '?' },
807  { '\'', '\'' },
808  { '\\', '\\' }
809  };
810  static const int numEscapeCodes = sizeof(escapeCodes) / sizeof(escapeCodes[0]);
811 
812  bool isStringList = false;
813  bool inQuotedString = false;
814  bool currentValueIsQuoted = false;
815  int escapeVal = 0;
816  int i = from;
817  char ch;
818 
819 StSkipSpaces:
820  while (i < to && ((ch = str.at(i)) == ' ' || ch == '\t'))
821  ++i;
822  // fallthrough
823 
824 StNormal:
825  while (i < to) {
826  switch (str.at(i)) {
827  case '\\':
828  ++i;
829  if (i >= to)
830  goto end;
831 
832  ch = str.at(i++);
833  for (int j = 0; j < numEscapeCodes; ++j) {
834  if (ch == escapeCodes[j][0]) {
835  stringResult += QLatin1Char(escapeCodes[j][1]);
836  goto StNormal;
837  }
838  }
839 
840  if (ch == 'x') {
841  escapeVal = 0;
842 
843  if (i >= to)
844  goto end;
845 
846  ch = str.at(i);
847  if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f'))
848  goto StHexEscape;
849  } else if (ch >= '0' && ch <= '7') {
850  escapeVal = ch - '0';
851  goto StOctEscape;
852  } else if (ch == '\n' || ch == '\r') {
853  if (i < to) {
854  char ch2 = str.at(i);
855  // \n, \r, \r\n, and \n\r are legitimate line terminators in INI files
856  if ((ch2 == '\n' || ch2 == '\r') && ch2 != ch)
857  ++i;
858  }
859  } else {
860  // the character is skipped
861  }
862  break;
863  case '"':
864  ++i;
865  currentValueIsQuoted = true;
866  inQuotedString = !inQuotedString;
867  if (!inQuotedString)
868  goto StSkipSpaces;
869  break;
870  case ',':
871  if (!inQuotedString) {
872  if (!currentValueIsQuoted)
873  iniChopTrailingSpaces(stringResult);
874  if (!isStringList) {
875  isStringList = true;
876  stringListResult.clear();
877  stringResult.squeeze();
878  }
879  stringListResult.append(stringResult);
880  stringResult.clear();
881  currentValueIsQuoted = false;
882  ++i;
883  goto StSkipSpaces;
884  }
885  // fallthrough
886  default: {
887  int j = i + 1;
888  while (j < to) {
889  ch = str.at(j);
890  if (ch == '\\' || ch == '"' || ch == ',')
891  break;
892  ++j;
893  }
894 
895 #ifndef QT_NO_TEXTCODEC
896  if (codec) {
897  stringResult += codec->toUnicode(str.constData() + i, j - i);
898  } else
899 #endif
900  {
901  int n = stringResult.size();
902  stringResult.resize(n + (j - i));
903  QChar *resultData = stringResult.data() + n;
904  for (int k = i; k < j; ++k)
905  *resultData++ = QLatin1Char(str.at(k));
906  }
907  i = j;
908  }
909  }
910  }
911  goto end;
912 
913 StHexEscape:
914  if (i >= to) {
915  stringResult += QChar(escapeVal);
916  goto end;
917  }
918 
919  ch = str.at(i);
920  if (ch >= 'a')
921  ch -= 'a' - 'A';
922  if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) {
923  escapeVal <<= 4;
924  escapeVal += strchr(hexDigits, ch) - hexDigits;
925  ++i;
926  goto StHexEscape;
927  } else {
928  stringResult += QChar(escapeVal);
929  goto StNormal;
930  }
931 
932 StOctEscape:
933  if (i >= to) {
934  stringResult += QChar(escapeVal);
935  goto end;
936  }
937 
938  ch = str.at(i);
939  if (ch >= '0' && ch <= '7') {
940  escapeVal <<= 3;
941  escapeVal += ch - '0';
942  ++i;
943  goto StOctEscape;
944  } else {
945  stringResult += QChar(escapeVal);
946  goto StNormal;
947  }
948 
949 end:
950  if (!currentValueIsQuoted)
951  iniChopTrailingSpaces(stringResult);
952  if (isStringList)
953  stringListResult.append(stringResult);
954  return isStringList;
955 }
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
static void iniChopTrailingSpaces(QString &str)
Definition: qsettings.cpp:758
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
static const char hexDigits[]
Definition: qsettings.cpp:594
void clear()
Removes all items from the list.
Definition: qlist.h:764
void squeeze()
Releases any memory not required to store the character data.
Definition: qstring.h:114
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
static const KeyPair *const end
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isWritable()

virtual bool QSettingsPrivate::isWritable ( ) const
pure virtual

◆ normalizedKey()

QString QSettingsPrivate::normalizedKey ( const QString key)
static

Definition at line 338 of file qsettings.cpp.

Referenced by actualKey().

339 {
340  QString result = key;
341 
342  int i = 0;
343  while (i < result.size()) {
344  while (result.at(i) == QLatin1Char('/')) {
345  result.remove(i, 1);
346  if (i == result.size())
347  goto after_loop;
348  }
349  while (result.at(i) != QLatin1Char('/')) {
350  ++i;
351  if (i == result.size())
352  return result;
353  }
354  ++i; // leave the slash alone
355  }
356 
357 after_loop:
358  if (!result.isEmpty())
359  result.truncate(i - 1); // remove the trailing slash
360  return result;
361 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QString class provides a Unicode character string.
Definition: qstring.h:83
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int key
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ processChild()

void QSettingsPrivate::processChild ( QString  key,
ChildSpec  spec,
QMap< QString, QString > &  result 
)
static

Definition at line 380 of file qsettings.cpp.

Referenced by QConfFileSettingsPrivate::children(), and QMacSettingsPrivate::children().

381 {
382  if (spec != AllKeys) {
383  int slashPos = key.indexOf(QLatin1Char('/'));
384  if (slashPos == -1) {
385  if (spec != ChildKeys)
386  return;
387  } else {
388  if (spec != ChildGroups)
389  return;
390  key.truncate(slashPos);
391  }
392  }
393  result.insert(key, QString());
394 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ remove()

virtual void QSettingsPrivate::remove ( const QString key)
pure virtual

◆ requestUpdate()

void QSettingsPrivate::requestUpdate ( )

Definition at line 422 of file qsettings.cpp.

423 {
424  if (!pendingChanges) {
425  pendingChanges = true;
426 #ifndef QT_NO_QOBJECT
427  Q_Q(QSettings);
429 #else
430  update();
431 #endif
432  }
433 }
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
#define Q_Q(Class)
Definition: qglobal.h:2483
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ set()

virtual void QSettingsPrivate::set ( const QString key,
const QVariant value 
)
pure virtual

◆ setStatus()

void QSettingsPrivate::setStatus ( QSettings::Status  status) const

◆ splitArgs()

QStringList QSettingsPrivate::splitArgs ( const QString s,
int  idx 
)
static

Definition at line 957 of file qsettings.cpp.

Referenced by stringToVariant().

958 {
959  int l = s.length();
960  Q_ASSERT(l > 0);
961  Q_ASSERT(s.at(idx) == QLatin1Char('('));
962  Q_ASSERT(s.at(l - 1) == QLatin1Char(')'));
963 
964  QStringList result;
965  QString item;
966 
967  for (++idx; idx < l; ++idx) {
968  QChar c = s.at(idx);
969  if (c == QLatin1Char(')')) {
970  Q_ASSERT(idx == l - 1);
971  result.append(item);
972  } else if (c == QLatin1Char(' ')) {
973  result.append(item);
974  item.clear();
975  } else {
976  item.append(c);
977  }
978  }
979 
980  return result;
981 }
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString & append(QChar c)
Definition: qstring.cpp:1777
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QFactoryLoader * l
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ stringListToVariantList()

QVariant QSettingsPrivate::stringListToVariantList ( const QStringList l)
static

Definition at line 444 of file qsettings.cpp.

Referenced by QConfFileSettingsPrivate::readIniSection(), and QWinSettingsPrivate::readKey().

445 {
446  QStringList outStringList = l;
447  for (int i = 0; i < outStringList.count(); ++i) {
448  const QString &str = outStringList.at(i);
449 
450  if (str.startsWith(QLatin1Char('@'))) {
451  if (str.length() >= 2 && str.at(1) == QLatin1Char('@')) {
452  outStringList[i].remove(0, 1);
453  } else {
454  QVariantList variantList;
455  for (int j = 0; j < l.count(); ++j)
456  variantList.append(stringToVariant(l.at(j)));
457  return variantList;
458  }
459  }
460  }
461  return outStringList;
462 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QFactoryLoader * l
static QVariant stringToVariant(const QString &s)
Definition: qsettings.cpp:551
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ stringToVariant()

QVariant QSettingsPrivate::stringToVariant ( const QString s)
static

Definition at line 551 of file qsettings.cpp.

Referenced by qtValue(), QConfFileSettingsPrivate::readIniSection(), QWinSettingsPrivate::readKey(), and stringListToVariantList().

552 {
553  if (s.startsWith(QLatin1Char('@'))) {
554  if (s.endsWith(QLatin1Char(')'))) {
555  if (s.startsWith(QLatin1String("@ByteArray("))) {
556  return QVariant(s.toLatin1().mid(11, s.size() - 12));
557  } else if (s.startsWith(QLatin1String("@Variant("))) {
558 #ifndef QT_NO_DATASTREAM
559  QByteArray a(s.toLatin1().mid(9));
561  stream.setVersion(QDataStream::Qt_4_0);
562  QVariant result;
563  stream >> result;
564  return result;
565 #else
566  Q_ASSERT(!"QSettings: Cannot load custom types without QDataStream support");
567 #endif
568 #ifndef QT_NO_GEOM_VARIANT
569  } else if (s.startsWith(QLatin1String("@Rect("))) {
571  if (args.size() == 4)
572  return QVariant(QRect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt()));
573  } else if (s.startsWith(QLatin1String("@Size("))) {
575  if (args.size() == 2)
576  return QVariant(QSize(args[0].toInt(), args[1].toInt()));
577  } else if (s.startsWith(QLatin1String("@Point("))) {
579  if (args.size() == 2)
580  return QVariant(QPoint(args[0].toInt(), args[1].toInt()));
581 #endif
582  } else if (s == QLatin1String("@Invalid()")) {
583  return QVariant();
584  }
585 
586  }
587  if (s.startsWith(QLatin1String("@@")))
588  return QVariant(s.mid(1));
589  }
590 
591  return QVariant(s);
592 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QStringList splitArgs(const QString &s, int idx)
Definition: qsettings.cpp:957
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static FILE * stream
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static int toInt(const QByteArray &str)
Definition: generator.cpp:167
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ sync()

virtual void QSettingsPrivate::sync ( )
pure virtual

◆ update()

void QSettingsPrivate::update ( )

Definition at line 416 of file qsettings.cpp.

Referenced by requestUpdate().

417 {
418  flush();
419  pendingChanges = false;
420 }
virtual void flush()=0

◆ variantListToStringList()

QStringList QSettingsPrivate::variantListToStringList ( const QVariantList l)
static

Definition at line 435 of file qsettings.cpp.

Referenced by QWinSettingsPrivate::set(), and QConfFileSettingsPrivate::writeIniFile().

436 {
437  QStringList result;
439  for (; it != l.constEnd(); ++it)
440  result.append(variantToString(*it));
441  return result;
442 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
friend class const_iterator
Definition: qlist.h:264
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QString variantToString(const QVariant &v)
Definition: qsettings.cpp:464
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ variantToString()

QString QSettingsPrivate::variantToString ( const QVariant v)
static

Definition at line 464 of file qsettings.cpp.

Referenced by macValue(), QWinSettingsPrivate::set(), variantListToStringList(), and QConfFileSettingsPrivate::writeIniFile().

465 {
466  QString result;
467 
468  switch (v.type()) {
469  case QVariant::Invalid:
470  result = QLatin1String("@Invalid()");
471  break;
472 
473  case QVariant::ByteArray: {
474  QByteArray a = v.toByteArray();
475  result = QLatin1String("@ByteArray(");
476  result += QString::fromLatin1(a.constData(), a.size());
477  result += QLatin1Char(')');
478  break;
479  }
480 
481  case QVariant::String:
482  case QVariant::LongLong:
483  case QVariant::ULongLong:
484  case QVariant::Int:
485  case QVariant::UInt:
486  case QVariant::Bool:
487  case QVariant::Double:
488  case QVariant::KeySequence: {
489  result = v.toString();
490  if (result.startsWith(QLatin1Char('@')))
491  result.prepend(QLatin1Char('@'));
492  break;
493  }
494 #ifndef QT_NO_GEOM_VARIANT
495  case QVariant::Rect: {
496  QRect r = qvariant_cast<QRect>(v);
497  result += QLatin1String("@Rect(");
498  result += QString::number(r.x());
499  result += QLatin1Char(' ');
500  result += QString::number(r.y());
501  result += QLatin1Char(' ');
502  result += QString::number(r.width());
503  result += QLatin1Char(' ');
504  result += QString::number(r.height());
505  result += QLatin1Char(')');
506  break;
507  }
508  case QVariant::Size: {
509  QSize s = qvariant_cast<QSize>(v);
510  result += QLatin1String("@Size(");
511  result += QString::number(s.width());
512  result += QLatin1Char(' ');
513  result += QString::number(s.height());
514  result += QLatin1Char(')');
515  break;
516  }
517  case QVariant::Point: {
518  QPoint p = qvariant_cast<QPoint>(v);
519  result += QLatin1String("@Point(");
520  result += QString::number(p.x());
521  result += QLatin1Char(' ');
522  result += QString::number(p.y());
523  result += QLatin1Char(')');
524  break;
525  }
526 #endif // !QT_NO_GEOM_VARIANT
527 
528  default: {
529 #ifndef QT_NO_DATASTREAM
530  QByteArray a;
531  {
533  s.setVersion(QDataStream::Qt_4_0);
534  s << v;
535  }
536 
537  result = QLatin1String("@Variant(");
538  result += QString::fromLatin1(a.constData(), a.size());
539  result += QLatin1Char(')');
540 #else
541  Q_ASSERT(!"QSettings: Cannot save custom types without QDataStream support");
542 #endif
543  break;
544  }
545  }
546 
547  return result;
548 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString & prepend(QChar c)
Definition: qstring.h:261
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
int width() const
Returns the width.
Definition: qsize.h:126
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Properties

◆ applicationName

QString QSettingsPrivate::applicationName

Definition at line 261 of file qsettings_p.h.

◆ fallbacks

bool QSettingsPrivate::fallbacks
protected

◆ format

QSettings::Format QSettingsPrivate::format

Definition at line 258 of file qsettings_p.h.

Referenced by QSettings::registerFormat().

◆ groupPrefix

QString QSettingsPrivate::groupPrefix
protected

Definition at line 266 of file qsettings_p.h.

Referenced by actualKey(), and beginGroupOrArray().

◆ groupStack

QStack<QSettingsGroup> QSettingsPrivate::groupStack
protected

Definition at line 265 of file qsettings_p.h.

Referenced by beginGroupOrArray().

◆ iniCodec

QTextCodec* QSettingsPrivate::iniCodec

◆ organizationName

QString QSettingsPrivate::organizationName

Definition at line 260 of file qsettings_p.h.

◆ pendingChanges

bool QSettingsPrivate::pendingChanges
protected

Definition at line 269 of file qsettings_p.h.

Referenced by requestUpdate(), and update().

◆ scope

QSettings::Scope QSettingsPrivate::scope

Definition at line 259 of file qsettings_p.h.

Referenced by QWinSettingsPrivate::isWritable(), and normalizedKey().

◆ spec

int QSettingsPrivate::spec
protected

◆ status

QSettings::Status QSettingsPrivate::status
mutableprotected

The documentation for this class was generated from the following files: