~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/itemviews/qdirmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-08-01 11:30:30 UTC
  • mto: (15.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 55.
  • Revision ID: james.westby@ubuntu.com-20080801113030-c33y1z0l21t6cj5r
Tags: upstream-4.4.1
ImportĀ upstreamĀ versionĀ 4.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
185
185
}
186
186
 
187
187
/*!
188
 
  \class QDirModel qdirmodel.h
189
 
 
190
 
  \brief The QDirModel class provides a data model for the local filesystem.
191
 
 
192
 
  \ingroup model-view
193
 
 
194
 
  This class provides access to the local filesystem, providing functions
195
 
  for renaming and removing files and directories, and for creating new
196
 
  directories. In the simplest case, it can be used with a suitable display
197
 
  widget as part of a browser or filer.
198
 
 
199
 
  QDirModel keeps a cache with file information. The cache needs to be
200
 
  updated with refresh().
201
 
 
202
 
  A directory model that displays the contents of a default directory
203
 
  is usually constructed with a parent object:
204
 
 
205
 
  \snippet doc/src/snippets/shareddirmodel/main.cpp 2
206
 
 
207
 
  A tree view can be used to display the contents of the model
208
 
 
209
 
  \snippet doc/src/snippets/shareddirmodel/main.cpp 4
210
 
 
211
 
  and the contents of a particular directory can be displayed by
212
 
  setting the tree view's root index:
213
 
 
214
 
  \snippet doc/src/snippets/shareddirmodel/main.cpp 7
215
 
 
216
 
  The view's root index can be used to control how much of a
217
 
  hierarchical model is displayed. QDirModel provides a convenience
218
 
  function that returns a suitable model index for a path to a
219
 
  directory within the model.
220
 
 
221
 
  QDirModel can be accessed using the standard interface provided by
222
 
  QAbstractItemModel, but it also provides some convenience functions
223
 
  that are specific to a directory model. The fileInfo() and isDir()
224
 
  functions provide information about the underlying files and directories
225
 
  related to items in the model.
226
 
  
227
 
  Directories can be created and removed using mkdir(), rmdir(), and the
228
 
  model will be automatically updated to take the changes into account.
229
 
 
230
 
  \sa nameFilters(), setFilter(), filter(), QListView, QTreeView,
231
 
      {Dir View Example}, {Model Classes}
 
188
    \class QDirModel qdirmodel.h
 
189
 
 
190
    \brief The QDirModel class provides a data model for the local filesystem.
 
191
 
 
192
    \ingroup model-view
 
193
 
 
194
    This class provides access to the local filesystem, providing functions
 
195
    for renaming and removing files and directories, and for creating new
 
196
    directories. In the simplest case, it can be used with a suitable display
 
197
    widget as part of a browser or filer.
 
198
 
 
199
    QDirModel keeps a cache with file information. The cache needs to be
 
200
    updated with refresh().
 
201
 
 
202
    A directory model that displays the contents of a default directory
 
203
    is usually constructed with a parent object:
 
204
 
 
205
    \snippet doc/src/snippets/shareddirmodel/main.cpp 2
 
206
 
 
207
    A tree view can be used to display the contents of the model
 
208
 
 
209
    \snippet doc/src/snippets/shareddirmodel/main.cpp 4
 
210
 
 
211
    and the contents of a particular directory can be displayed by
 
212
    setting the tree view's root index:
 
213
 
 
214
    \snippet doc/src/snippets/shareddirmodel/main.cpp 7
 
215
 
 
216
    The view's root index can be used to control how much of a
 
217
    hierarchical model is displayed. QDirModel provides a convenience
 
218
    function that returns a suitable model index for a path to a
 
219
    directory within the model.
 
220
 
 
221
    QDirModel can be accessed using the standard interface provided by
 
222
    QAbstractItemModel, but it also provides some convenience functions
 
223
    that are specific to a directory model. The fileInfo() and isDir()
 
224
    functions provide information about the underlying files and directories
 
225
    related to items in the model.
 
226
 
 
227
    Directories can be created and removed using mkdir(), rmdir(), and the
 
228
    model will be automatically updated to take the changes into account.
 
229
 
 
230
    \note QDirModel requires an instance of a GUI application.
 
231
 
 
232
    \sa nameFilters(), setFilter(), filter(), QListView, QTreeView,
 
233
    {Dir View Example}, {Model Classes}
232
234
*/
233
235
 
234
236
/*!
592
594
 
593
595
    bool success = true;
594
596
    QString to = filePath(parent) + QDir::separator();
 
597
    QModelIndex _parent = parent;
595
598
 
596
599
    QList<QUrl> urls = data->urls();
597
600
    QList<QUrl>::const_iterator it = urls.constBegin();
615
618
            if(QFile::copy(path, to + QFileInfo(path).fileName())
616
619
               && QFile::remove(path)) {
617
620
                QModelIndex idx=index(QFileInfo(path).path());
618
 
                if(idx.isValid())
 
621
                if(idx.isValid()) {
619
622
                    refresh(idx);
 
623
                    //the previous call to refresh may invalidate the _parent. so recreate a new QModelIndex
 
624
                    _parent = index(to);
 
625
                }
620
626
            } else {
621
627
                success = false;
622
628
            }
627
633
    }
628
634
 
629
635
    if (success)
630
 
        refresh(parent);
 
636
        refresh(_parent);
631
637
 
632
638
    return success;
633
639
}