Qt 4.8
Public Functions | Protected Variables | List of all members
QNSOpenSavePanelDelegate Class Reference

Public Functions

(QStringList- acceptableExtensionsForSave
 
(void) - createAccessory
 
(void) - createPopUpButton:hideDetails:
 
(void) - createTextField
 
(void) - filterChanged:
 
(QStringList- findStrippedFilterWithVisualFilterName:
 
(BOOL) - panel:shouldShowFilename:
 
(QString- removeExtensions:
 
(BOOL) - runApplicationModalPanel
 
(void) - showModelessPanel
 
(void) - showWindowModalSheet:
 
(NSString *) - strip:
 
(void) - updateProperties
 

Protected Variables

 __pad0__: NSObject{ @public NSOpenPanel *mOpenPanel
 
::QFileDialog::AcceptMode mAcceptMode
 
NSView * mAccessoryView
 
bool mConfirmOverwrite
 
NSString * mCurrentDir
 
QStringmCurrentSelection
 
::QFileDialog::FileMode mFileMode
 
::QFileDialog::Options * mFileOptions
 
QStringmLastFilterCheckPath
 
QStringListmNameFilterDropDownList
 
NSPopUpButton * mPopUpButton
 
QFileDialogPrivatemPriv
 
::QDir::Filters * mQDirFilter
 
QStringListmQDirFilterEntryList
 
int mReturnCode
 
NSSavePanel * mSavePanel
 
QStringListmSelectedNameFilter
 
NSTextField * mTextField
 

Detailed Description

Definition at line 88 of file qfiledialog_mac.mm.

Functions

◆ acceptableExtensionsForSave()

- (QStringList) acceptableExtensionsForSave

Definition at line 501 of file qfiledialog_mac.mm.

502 {
503  QStringList result;
504  for (int i=0; i<mSelectedNameFilter->count(); ++i) {
505  const QString &filter = mSelectedNameFilter->at(i);
506  if (filter.startsWith(QLatin1String("*."))
507  && !filter.contains(QLatin1Char('?'))
508  && filter.count(QLatin1Char('*')) == 1) {
509  result += filter.mid(2);
510  } else {
511  return QStringList(); // Accept everything
512  }
513  }
514  return result;
515 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
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
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
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
int count() const
Definition: qstring.h:103
QStringList * mSelectedNameFilter
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ createAccessory()

- (void) createAccessory

Definition at line 573 of file qfiledialog_mac.mm.

574 {
575  NSRect accessoryRect = { { 0.0, 0.0 }, { 450.0, 33.0 } };
576  mAccessoryView = [[NSView alloc] initWithFrame:accessoryRect];
577  [mAccessoryView addSubview:mTextField];
578  [mAccessoryView addSubview:mPopUpButton];
579 }

◆ createPopUpButton:hideDetails:()

- (void) createPopUpButton: (const QString &)  selectedFilter
hideDetails: (BOOL)  hideDetails 

Definition at line 542 of file qfiledialog_mac.mm.

542  :(const QString &)selectedFilter hideDetails:(BOOL)hideDetails
543 {
544  NSRect popUpRect = { { 100.0, 5.0 }, { 250.0, 25.0 } };
545  mPopUpButton = [[NSPopUpButton alloc] initWithFrame:popUpRect pullsDown:NO];
546  [mPopUpButton setTarget:self];
547  [mPopUpButton setAction:@selector(filterChanged:)];
548 
549  if (mNameFilterDropDownList->size() > 0) {
550  int filterToUse = -1;
551  for (int i=0; i<mNameFilterDropDownList->size(); ++i) {
552  QString currentFilter = mNameFilterDropDownList->at(i);
553  if (selectedFilter == currentFilter ||
554  (filterToUse == -1 && currentFilter.startsWith(selectedFilter)))
555  filterToUse = i;
556  QString filter = hideDetails ? [self removeExtensions:currentFilter] : currentFilter;
557  [mPopUpButton addItemWithTitle:QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(filter)];
558  }
559  if (filterToUse != -1)
560  [mPopUpButton selectItemAtIndex:filterToUse];
561  }
562 }
QStringList * mNameFilterDropDownList
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
NSPopUpButton * mPopUpButton
The QString class provides a Unicode character string.
Definition: qstring.h:83
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)

◆ createTextField()

- (void) createTextField

Definition at line 525 of file qfiledialog_mac.mm.

526 {
527  NSRect textRect = { { 0.0, 3.0 }, { 100.0, 25.0 } };
528  mTextField = [[NSTextField alloc] initWithFrame:textRect];
529  [[mTextField cell] setFont:[NSFont systemFontOfSize:
530  [NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
531  [mTextField setAlignment:NSRightTextAlignment];
532  [mTextField setEditable:false];
533  [mTextField setSelectable:false];
534  [mTextField setBordered:false];
535  [mTextField setDrawsBackground:false];
536  if (mPriv){
537  [mTextField setStringValue:[self strip:mPriv->qFileDialogUi->fileTypeLabel->text()]];
538  } else
539  [mTextField setStringValue:QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(QT_PREPEND_NAMESPACE(QFileDialog::tr)("Files of type:"))];
540 }
QFileDialogPrivate * mPriv

◆ filterChanged:()

- (void) filterChanged: (id)  sender

Definition at line 400 of file qfiledialog_mac.mm.

400  :(id)sender
401 {
402  // This mDelegate function is called when the _name_ filter changes.
403  Q_UNUSED(sender);
404  QString selection = mNameFilterDropDownList->value([mPopUpButton indexOfSelectedItem]);
405  *mSelectedNameFilter = [self findStrippedFilterWithVisualFilterName:selection];
406  if ([mSavePanel respondsToSelector:@selector(validateVisibleColumns)])
407  [mSavePanel validateVisibleColumns];
408  [self updateProperties];
409  if (mPriv)
411 }
QStringList * mNameFilterDropDownList
NSPopUpButton * mPopUpButton
The QString class provides a Unicode character string.
Definition: qstring.h:83
void QNSOpenSavePanelDelegate_filterSelected(int menuIndex)
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
QStringList * mSelectedNameFilter
#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
QFileDialogPrivate * mPriv

◆ findStrippedFilterWithVisualFilterName:()

- (QStringList) findStrippedFilterWithVisualFilterName: (QString name

Definition at line 564 of file qfiledialog_mac.mm.

564  :(QString)name
565 {
566  for (int i=0; i<mNameFilterDropDownList->size(); ++i) {
567  if (mNameFilterDropDownList->at(i).startsWith(name))
569  }
570  return QStringList();
571 }
QStringList * mNameFilterDropDownList
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
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
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QStringList qt_clean_filter_list(const QString &filter)

◆ panel:shouldShowFilename:()

- (BOOL) panel: (id)  sender
shouldShowFilename: (NSString *)  filename 

Definition at line 316 of file qfiledialog_mac.mm.

316  :(id)sender shouldShowFilename:(NSString *)filename
317 {
318  Q_UNUSED(sender);
319 
320  if ([filename length] == 0)
321  return NO;
322 
323  // Always accept directories regardless of their names (unless it is a bundle):
324  NSFileManager *fm = [NSFileManager defaultManager];
325  NSDictionary *fileAttrs = [fm attributesOfItemAtPath:filename error:nil];
326  if (!fileAttrs)
327  return NO; // Error accessing the file means 'no'.
328  NSString *fileType = [fileAttrs fileType];
329  bool isDir = [fileType isEqualToString:NSFileTypeDirectory];
330  if (isDir) {
331  if ([mSavePanel treatsFilePackagesAsDirectories] == NO) {
332  if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:filename] == NO)
333  return YES;
334  }
335  }
336 
337  QString qtFileName
338  = QFileInfo(QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString)(filename)).fileName();
339  // No filter means accept everything
340  bool nameMatches = mSelectedNameFilter->isEmpty();
341  // Check if the current file name filter accepts the file:
342  for (int i = 0; !nameMatches && i < mSelectedNameFilter->size(); ++i) {
343  if (QDir::match(mSelectedNameFilter->at(i), qtFileName))
344  nameMatches = true;
345  }
346  if (!nameMatches)
347  return NO;
348 
349  QDir::Filters filter = *mQDirFilter;
350  if ((!(filter & (QDir::Dirs | QDir::AllDirs)) && isDir)
351  || (!(filter & QDir::Files) && [fileType isEqualToString:NSFileTypeRegular])
352  || ((filter & QDir::NoSymLinks) && [fileType isEqualToString:NSFileTypeSymbolicLink]))
353  return NO;
354 
355  bool filterPermissions = ((filter & QDir::PermissionMask)
356  && (filter & QDir::PermissionMask) != QDir::PermissionMask);
357  if (filterPermissions) {
358  if ((!(filter & QDir::Readable) && [fm isReadableFileAtPath:filename])
359  || (!(filter & QDir::Writable) && [fm isWritableFileAtPath:filename])
360  || (!(filter & QDir::Executable) && [fm isExecutableFileAtPath:filename]))
361  return NO;
362  }
363  if (!(filter & QDir::Hidden)
364  && (qtFileName.startsWith(QLatin1Char('.')) || [self isHiddenFile:filename isDir:isDir]))
365  return NO;
366 
367  return YES;
368 }
::QDir::Filters * mQDirFilter
static bool match(const QStringList &filters, const QString &fileName)
Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; othe...
Definition: qdir.cpp:2047
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
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
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QStringList * mSelectedNameFilter
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
#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

◆ removeExtensions:()

- (QString) removeExtensions: (const QString &)  filter

Definition at line 517 of file qfiledialog_mac.mm.

517  :(const QString &)filter
518 {
520  if (regExp.indexIn(filter) != -1)
521  return regExp.cap(1).trimmed();
522  return filter;
523 }
const char * qt_file_dialog_filter_reg_exp
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QString trimmed(QString source)
Definition: generator.cpp:233
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
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
return(isPopup||isToolTip)

◆ runApplicationModalPanel()

- (BOOL) runApplicationModalPanel

Definition at line 253 of file qfiledialog_mac.mm.

254 {
256  NSString *filename = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.fileName());
257  NSString *filepath = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.filePath());
258  bool selectable = (mAcceptMode == QFileDialog::AcceptSave)
259  || [self panel:nil shouldShowFilename:filepath];
260  mReturnCode = [mSavePanel
261  runModalForDirectory:mCurrentDir
262  file:selectable ? filename : @"untitled"];
263 
265  return (mReturnCode == NSOKButton);
266 }
virtual void interrupt()=0
Interrupts event dispatching; i.
static mach_timebase_info_data_t info
static QAbstractEventDispatcher * instance(QThread *thread=0)
Returns a pointer to the event dispatcher object for the specified thread.
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
::QFileDialog::AcceptMode mAcceptMode
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60

◆ showModelessPanel()

- (void) showModelessPanel

Definition at line 235 of file qfiledialog_mac.mm.

236 {
237  if (mOpenPanel){
239  NSString *filename = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.fileName());
240  NSString *filepath = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.filePath());
241  bool selectable = (mAcceptMode == QFileDialog::AcceptSave)
242  || [self panel:nil shouldShowFilename:filepath];
243  [mOpenPanel
244  beginForDirectory:mCurrentDir
245  file:selectable ? filename : nil
246  types:nil
247  modelessDelegate:self
248  didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
249  contextInfo:nil];
250  }
251 }
static mach_timebase_info_data_t info
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
::QFileDialog::AcceptMode mAcceptMode
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60

◆ showWindowModalSheet:()

- (void) showWindowModalSheet: (QWidget *)  docWidget

Definition at line 273 of file qfiledialog_mac.mm.

273  :(QWidget *)docWidget
274 {
275  Q_UNUSED(docWidget);
277  NSString *filename = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.fileName());
278  NSString *filepath = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.filePath());
279  bool selectable = (mAcceptMode == QFileDialog::AcceptSave)
280  || [self panel:nil shouldShowFilename:filepath];
281  [mSavePanel
282  beginSheetForDirectory:mCurrentDir
283  file:selectable ? filename : nil
284 #ifdef QT_MAC_USE_COCOA
285  modalForWindow:QT_PREPEND_NAMESPACE(qt_mac_window_for)(docWidget)
286 #else
287  modalForWindow:nil
288 #endif
289  modalDelegate:self
290  didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
291  contextInfo:nil];
292 }
static mach_timebase_info_data_t info
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
::QFileDialog::AcceptMode mAcceptMode
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
#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

◆ strip:()

- (NSString *) strip: (const QString &)  label

Definition at line 220 of file qfiledialog_mac.mm.

220  :(const QString &)label
221 {
222  QAction a(label, 0);
223  return qt_mac_QStringToNSString(a.iconText());
224 }
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ updateProperties()

- (void) updateProperties

Definition at line 430 of file qfiledialog_mac.mm.

431 {
432  // Call this functions if mFileMode, mFileOptions,
433  // mNameFilterDropDownList or mQDirFilter changes.
434  // The savepanel does not contain the neccessary functions for this.
435  bool chooseFilesOnly = mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::ExistingFile)
437  bool chooseDirsOnly = mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::Directory)
440 
441  [mOpenPanel setCanChooseFiles:!chooseDirsOnly];
442  [mOpenPanel setCanChooseDirectories:!chooseFilesOnly];
443  [mSavePanel setCanCreateDirectories:!(*mFileOptions & QT_PREPEND_NAMESPACE(QFileDialog::ReadOnly))];
444  [mOpenPanel setAllowsMultipleSelection:(mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::ExistingFiles))];
445  [mOpenPanel setResolvesAliases:!(*mFileOptions & QT_PREPEND_NAMESPACE(QFileDialog::DontResolveSymlinks))];
446 
447  QStringList ext = [self acceptableExtensionsForSave];
448  if (mPriv && !ext.isEmpty() && !mPriv->defaultSuffix.isEmpty())
450  [mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : QT_PREPEND_NAMESPACE(qt_mac_QStringListToNSMutableArray(ext))];
451 
452  if ([mSavePanel respondsToSelector:@selector(isVisible)] && [mSavePanel isVisible])
453  {
454  if ([mOpenPanel respondsToSelector:@selector(validateVisibleColumns)])
455  [mOpenPanel validateVisibleColumns];
456  }
457 }
::QFileDialog::Options * mFileOptions
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
QFileDialogPrivate * mPriv
::QFileDialog::FileMode mFileMode

Properties

◆ __pad0__

- __pad0__
protected

Definition at line 96 of file qfiledialog_mac.mm.

◆ mAcceptMode

- QFileDialog:
protected

Definition at line 106 of file qfiledialog_mac.mm.

◆ mAccessoryView

- (NSView*) mAccessoryView
protected

Definition at line 98 of file qfiledialog_mac.mm.

◆ mConfirmOverwrite

- (bool) mConfirmOverwrite
protected

Definition at line 103 of file qfiledialog_mac.mm.

◆ mCurrentDir

- (NSString*) mCurrentDir
protected

Definition at line 102 of file qfiledialog_mac.mm.

◆ mCurrentSelection

- (QString*) mCurrentSelection
protected

Definition at line 112 of file qfiledialog_mac.mm.

◆ mFileMode

- QFileDialog:
protected

Definition at line 108 of file qfiledialog_mac.mm.

◆ mFileOptions

- QFileDialog:
protected

Definition at line 109 of file qfiledialog_mac.mm.

◆ mLastFilterCheckPath

- (QString*) mLastFilterCheckPath
protected

Definition at line 111 of file qfiledialog_mac.mm.

◆ mNameFilterDropDownList

- (QStringList*) mNameFilterDropDownList
protected

Definition at line 114 of file qfiledialog_mac.mm.

◆ mPopUpButton

- (NSPopUpButton*) mPopUpButton
protected

Definition at line 99 of file qfiledialog_mac.mm.

◆ mPriv

- (QFileDialogPrivate*) mPriv
protected

Definition at line 101 of file qfiledialog_mac.mm.

◆ mQDirFilter

- QDir:
protected

Definition at line 107 of file qfiledialog_mac.mm.

◆ mQDirFilterEntryList

- (QStringList*) mQDirFilterEntryList
protected

Definition at line 113 of file qfiledialog_mac.mm.

◆ mReturnCode

- (int) mReturnCode
protected

Definition at line 104 of file qfiledialog_mac.mm.

◆ mSavePanel

- (NSSavePanel*) mSavePanel
protected

Definition at line 97 of file qfiledialog_mac.mm.

Referenced by runApplicationModalPanel.

◆ mSelectedNameFilter

- (QStringList*) mSelectedNameFilter
protected

Definition at line 115 of file qfiledialog_mac.mm.

◆ mTextField

- (NSTextField*) mTextField
protected

Definition at line 100 of file qfiledialog_mac.mm.


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