examples/assistant/simpletextviewer/findfiledialog.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the examples of the Qt Toolkit.
     7 ** This file is part of the examples of the Qt Toolkit.
     8 **
     8 **
   100 
   100 
   101     QFile file(path + fileName);
   101     QFile file(path + fileName);
   102     if (file.open(QIODevice::ReadOnly)) {
   102     if (file.open(QIODevice::ReadOnly)) {
   103         QString data(file.readAll());
   103         QString data(file.readAll());
   104 
   104 
   105         if (fileName.endsWith(".html"))
   105         if (fileName.endsWith(QLatin1String(".html")))
   106             currentEditor->setHtml(data);
   106             currentEditor->setHtml(data);
   107         else
   107         else
   108             currentEditor->setPlainText(data);
   108             currentEditor->setPlainText(data);
   109     }
   109     }
   110     close();
   110     close();
   117             foundFilesTree->topLevelItemCount() > 0);
   117             foundFilesTree->topLevelItemCount() > 0);
   118 }
   118 }
   119 
   119 
   120 void FindFileDialog::findFiles()
   120 void FindFileDialog::findFiles()
   121 {
   121 {
   122     QRegExp filePattern(fileNameComboBox->currentText() + "*");
   122     QRegExp filePattern(fileNameComboBox->currentText() + '*');
   123     filePattern.setPatternSyntax(QRegExp::Wildcard);
   123     filePattern.setPatternSyntax(QRegExp::Wildcard);
   124 
   124 
   125     QDir directory(directoryComboBox->currentText());
   125     QDir directory(directoryComboBox->currentText());
   126 
   126 
   127     QStringList allFiles = directory.entryList(QDir::Files | QDir::NoSymLinks);
   127     QStringList allFiles = directory.entryList(QDir::Files | QDir::NoSymLinks);
   128     QStringList matchingFiles;
   128     QStringList matchingFiles;
   129 
   129 
   130     foreach (QString file, allFiles) {
   130     foreach (const QString &file, allFiles) {
   131         if (filePattern.exactMatch(file))
   131         if (filePattern.exactMatch(file))
   132             matchingFiles << file;
   132             matchingFiles << file;
   133     }
   133     }
   134     showFiles(matchingFiles);
   134     showFiles(matchingFiles);
   135 }
   135 }