src/gui/dialogs/qsidebar.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   291 void QUrlModel::setFileSystemModel(QFileSystemModel *model)
   291 void QUrlModel::setFileSystemModel(QFileSystemModel *model)
   292 {
   292 {
   293     if (model == fileSystemModel)
   293     if (model == fileSystemModel)
   294         return;
   294         return;
   295     if (fileSystemModel != 0) {
   295     if (fileSystemModel != 0) {
   296         disconnect(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
   296         disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   297             this, SLOT(dataChanged(const QModelIndex &, const QModelIndex &)));
   297             this, SLOT(dataChanged(QModelIndex,QModelIndex)));
   298         disconnect(model, SIGNAL(layoutChanged()),
   298         disconnect(model, SIGNAL(layoutChanged()),
   299             this, SLOT(layoutChanged()));
   299             this, SLOT(layoutChanged()));
   300         disconnect(model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
   300         disconnect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
   301             this, SLOT(layoutChanged()));
   301             this, SLOT(layoutChanged()));
   302     }
   302     }
   303     fileSystemModel = model;
   303     fileSystemModel = model;
   304     if (fileSystemModel != 0) {
   304     if (fileSystemModel != 0) {
   305         connect(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
   305         connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
   306             this, SLOT(dataChanged(const QModelIndex &, const QModelIndex &)));
   306             this, SLOT(dataChanged(QModelIndex,QModelIndex)));
   307         connect(model, SIGNAL(layoutChanged()),
   307         connect(model, SIGNAL(layoutChanged()),
   308             this, SLOT(layoutChanged()));
   308             this, SLOT(layoutChanged()));
   309         connect(model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
   309         connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
   310             this, SLOT(layoutChanged()));
   310             this, SLOT(layoutChanged()));
   311     }
   311     }
   312     clear();
   312     clear();
   313     insertColumns(0, 1);
   313     insertColumns(0, 1);
   314 }
   314 }
   379     urlModel = new QUrlModel(this);
   379     urlModel = new QUrlModel(this);
   380     urlModel->setFileSystemModel(model);
   380     urlModel->setFileSystemModel(model);
   381     setModel(urlModel);
   381     setModel(urlModel);
   382     setItemDelegate(new QSideBarDelegate(this));
   382     setItemDelegate(new QSideBarDelegate(this));
   383 
   383 
   384     connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
   384     connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
   385             this, SLOT(clicked(const QModelIndex &)));
   385             this, SLOT(clicked(QModelIndex)));
   386 #ifndef QT_NO_DRAGANDDROP
   386 #ifndef QT_NO_DRAGANDDROP
   387     setDragDropMode(QAbstractItemView::DragDrop);
   387     setDragDropMode(QAbstractItemView::DragDrop);
   388 #endif
   388 #endif
   389     setContextMenuPolicy(Qt::CustomContextMenu);
   389     setContextMenuPolicy(Qt::CustomContextMenu);
   390     connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
   390     connect(this, SIGNAL(customContextMenuRequested(QPoint)),
   391             this, SLOT(showContextMenu(const QPoint &)));
   391             this, SLOT(showContextMenu(QPoint)));
   392     urlModel->setUrls(newUrls);
   392     urlModel->setUrls(newUrls);
   393     setCurrentIndex(this->model()->index(0,0));
   393     setCurrentIndex(this->model()->index(0,0));
   394 }
   394 }
   395 
   395 
   396 QSidebar::~QSidebar()
   396 QSidebar::~QSidebar()
   412     return QListView::sizeHint();
   412     return QListView::sizeHint();
   413 }
   413 }
   414 
   414 
   415 void QSidebar::selectUrl(const QUrl &url)
   415 void QSidebar::selectUrl(const QUrl &url)
   416 {
   416 {
   417     disconnect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
   417     disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
   418                this, SLOT(clicked(const QModelIndex &)));
   418                this, SLOT(clicked(QModelIndex)));
   419 
   419 
   420     selectionModel()->clear();
   420     selectionModel()->clear();
   421     for (int i = 0; i < model()->rowCount(); ++i) {
   421     for (int i = 0; i < model()->rowCount(); ++i) {
   422         if (model()->index(i, 0).data(QUrlModel::UrlRole).toUrl() == url) {
   422         if (model()->index(i, 0).data(QUrlModel::UrlRole).toUrl() == url) {
   423             selectionModel()->select(model()->index(i, 0), QItemSelectionModel::Select);
   423             selectionModel()->select(model()->index(i, 0), QItemSelectionModel::Select);
   424             break;
   424             break;
   425         }
   425         }
   426     }
   426     }
   427 
   427 
   428     connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
   428     connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
   429             this, SLOT(clicked(const QModelIndex &)));
   429             this, SLOT(clicked(QModelIndex)));
   430 }
   430 }
   431 
   431 
   432 #ifndef QT_NO_MENU
   432 #ifndef QT_NO_MENU
   433 /*!
   433 /*!
   434     \internal
   434     \internal