[Uml-devel] branches/work/soc-umbrello/umbrello/codeimpwizard

Andi Fischer andi.fischer at hispeed.ch
Mon Nov 14 22:27:12 UTC 2011


SVN commit 1264218 by fischer:

Same patch as for trunk in r1263106 - selection of files fixed in code import wizard.

 M  +22 -61    codeimpselectpage.cpp  


--- branches/work/soc-umbrello/umbrello/codeimpwizard/codeimpselectpage.cpp #1264217:1264218
@@ -63,8 +63,6 @@
     connect(ui_selectAllButton, SIGNAL(clicked()), this, SLOT(selectAll()));
     connect(ui_deselectAllButton, SIGNAL(clicked()), this, SLOT(deselectAll()));
 
-    connect(this, SIGNAL(selectionChanged()), this, SLOT(updateSelectionCounter()));
-
     setupToolTips();
 }
 
@@ -148,9 +146,9 @@
 {
     bool found = false;
     QString filename = path.fileName();
-    foreach (const QString &extension, m_fileExtensions) {
-        filename.remove('*');
-        if (filename.contains(extension)) {
+    foreach (QString extension, m_fileExtensions) {
+        extension.remove('*');
+        if (filename.endsWith(extension)) {
             found = true;
             break;
         }
@@ -236,29 +234,39 @@
         QFileInfo fileInfo = indexModel->fileInfo(index);
         if (fileInfo.isDir()) {
             int rows = indexModel->rowCount(index);
-            uDebug() << "item has children = " << rows;
+            uDebug() << "item has directory and has children = " << rows;
             QItemSelectionModel* selectionModel = ui_treeView->selectionModel();
             for(int row = 0; row < rows; ++row) {
                 QModelIndex childIndex = indexModel->index(row, 0, index);
                 if (selectionModel->isSelected(index)) {
+                    // uDebug() << "select all children";
+                    QFileInfo childInfo = indexModel->fileInfo(childIndex);
+                    if (childInfo.isDir() && ui_subdirCheckBox->isChecked()) {
+                        treeClicked(childIndex);
+                    }
+                    else {
+                        if (matchFilter(childInfo)) {
                     selectionModel->select(childIndex, QItemSelectionModel::Select);            
                 }
                 else {
                     selectionModel->select(childIndex, QItemSelectionModel::Deselect);            
                 }
             }
+                }
+                else {
+                    // uDebug() << "deselect all children";
+                    selectionModel->select(childIndex, QItemSelectionModel::Deselect);
+                }
+            }
             // keep the latest clicked directory
             s_recentPath = fileInfo.filePath();
         }
+        updateSelectionCounter();
+        emit selectionChanged();
     }
     else {
         uWarning() << "Index not valid!";
     }
-    emit selectionChanged();
-
-    // if is directory then select all children
-    //:TODO: disconnect clicked signal / select children / count children / connect clicked signal
-    // update label
 }
 
 /**
@@ -348,33 +356,18 @@
 {
     QList<QFileInfo> fileList;
     QFileSystemModel* model = (QFileSystemModel*)ui_treeView->model();
-#if 0
-    //:TODO: Remove the following - it is not used.
-    QModelIndexList indexList = ui_treeView->selectionModel()->selectedRows();
-    foreach(QModelIndex index, indexList) {
-        QMap<int, QVariant> map = model->itemData(index);
-        QString fileName = map.value(0).toString();
-        foreach(const QFileInfo& fileInfo, m_fileList) {
-            if (fileInfo.fileName() == fileName) {
-                fileList.append(fileInfo);
-            }
-        }
-    }
-    return fileList;
-#else
     QModelIndexList list = ui_treeView->selectionModel()->selectedIndexes();
     int row = -1;
     foreach (QModelIndex idx, list) {
         if (idx.row() != row && idx.column() == 0) {
             QFileInfo fileInfo = model->fileInfo(idx);
-            if (fileInfo.isFile()) {
+            if (fileInfo.isFile() && matchFilter(fileInfo)) {
                 fileList.append(fileInfo);
             }
             row = idx.row();
         }
     }
     return fileList;
-#endif
 }
 
 /**
@@ -422,40 +415,8 @@
  */
 void CodeImpSelectPage::updateSelectionCounter()
 {
-    QModelIndexList list = ui_treeView->selectionModel()->selectedRows();
-    ui_filesNumLabel->setText(QString::number(list.size()));
+    QList<QFileInfo> files = selectedFiles();
+    ui_filesNumLabel->setText(QString::number(files.size()));
 }
 
-/**
- * Assumes that path and rootPath use the same dir separator and the same letter case.
- * :TODO: Remove the following - it is not used.
- */
-/*void CodeImpSelectPage::populatePath(const QString& path, const QString& rootPath)
-{
-    QStringList parts = path.split(QDir::separator());
-
-    QString currPath;
-    foreach (const QString& part, parts) {
-        if (!currPath.isEmpty()) {
-            currPath += QDir::separator();
-        }
-        currPath += part;
-
-        // no need to populate dirs outside of our area of interest
-        if (!currPath.startsWith(rootPath)) {
-            continue;
-        }
-
-        if (QFileInfo(currPath).isDir()) {
-            QFileSystemModel* model = (QFileSystemModel*)ui_treeView->model();
-            QModelIndex idx = model->index(currPath);
-            if (idx.isValid()) {
-                while (model->canFetchMore(idx)) {
-                    model->fetchMore(idx);
-                }
-            }
-        }
-    }
-}*/
-
 #include "codeimpselectpage.moc"




More information about the umbrello-devel mailing list