OSDN Git Service

Made getLogFile() function "const" and made sure that we will return a const referenc...
[lamexp/LameXP.git] / src / Model_FileList.cpp
index 1b83b05..4d1e559 100644 (file)
@@ -40,6 +40,7 @@
 
 FileListModel::FileListModel(void)
 :
+       m_blockUpdates(false),
        m_fileIcon(":/icons/page_white_cd.png")
 {
 }
@@ -138,26 +139,30 @@ void FileListModel::addFile(const QString &filePath)
 {
        QFileInfo fileInfo(filePath);
        const QString key = MAKE_KEY(fileInfo.canonicalFilePath()); 
+       const bool flag = (!m_blockUpdates);
 
        if(!m_fileStore.contains(key))
        {
-               beginInsertRows(QModelIndex(), m_fileList.count(), m_fileList.count());
+               if(flag) beginInsertRows(QModelIndex(), m_fileList.count(), m_fileList.count());
                m_fileStore.insert(key, AudioFileModel(fileInfo.canonicalFilePath(), fileInfo.baseName()));
                m_fileList.append(key);
-               endInsertRows();
+               if(flag) endInsertRows();
+               emit rowAppended();
        }
 }
 
 void FileListModel::addFile(const AudioFileModel &file)
 {
        const QString key = MAKE_KEY(file.filePath()); 
+       const bool flag = (!m_blockUpdates);
 
        if(!m_fileStore.contains(key))
        {
-               beginInsertRows(QModelIndex(), m_fileList.count(), m_fileList.count());
+               if(flag) beginInsertRows(QModelIndex(), m_fileList.count(), m_fileList.count());
                m_fileStore.insert(key, file);
                m_fileList.append(key);
-               endInsertRows();
+               if(flag) endInsertRows();
+               emit rowAppended();
        }
 }
 
@@ -204,7 +209,7 @@ AudioFileModel FileListModel::getFile(const QModelIndex &index)
 {
        if(index.row() >= 0 && index.row() < m_fileList.count())
        {
-               return m_fileList.at(index.row());
+               return m_fileStore.value(m_fileList.at(index.row()));
        }
        else
        {