Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-2541

[4.4.1] Feature request: QFileSystemModel::touch()

    XMLWordPrintable

Details

    Description

      There's a 'rmdir', 'mkdir' and 'remove' (aka unlink), but no 'touch'. In QFileSystemModel, touch() could be added like this:

      QModelIndex QFileSystemModel::touch(const QModelIndex &parent, const QString &name)
      {
           Q_D(QFileSystemModel);
      
           if (!parent.isValid())
               return QModelIndex();
      
           QDir dir(filePath(parent));
              
            if (QFileInfo(dir.filePath(name)).exists())
                    return index(dir.filePath(name));
              
            QFile file(dir.filePath(name));
            if (!file.open(QIODevice::WriteOnly))
                    return QModelIndex();
            file.close();
      
           QFileSystemModelPrivate::QFileSystemNode *parentNode = d->node(parent);
           d->addNode(parentNode, name);
           int r = d->findChild(parentNode, QFileSystemModelPrivate::QFileSystemNode(name));
           Q_ASSERT(r >= 0);
           QFileSystemModelPrivate::QFileSystemNode *node = &parentNode->children[r];
       
           node->populate(d->fileInfoGatherer.getInfo(QFileInfo(dir.absolutePath() + QDir::separator() + name)));
           d->addVisibleFiles(parentNode, QStringList(name));
           return d->index(node);
      }
      

      Possible use case:

      void Browser::addButtonClicked()
      {
           QModelIndex index = model->touch(parent, newName);
           treeView->setCurrentIndex(index);
           treeView->edit(index);
      }
      

      The user can thereby nicely edit a new file's name directly in the file system view.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            menard Alexis Menard (closed Nokia identity) (Inactive)
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes