Permalink
Browse files

Fix in FtpModel::refresh

Refresh didn't emit rowsRemoved although it did remove all children
for a short period of time. Added button to refresh a folder to the
example as well.
  • Loading branch information...
1 parent 4c2911b commit c8c190b17682c7d669bbc1a0077d0e88a0bce3cc atamanroman committed with atamanroman Nov 24, 2011
Showing with 88 additions and 64 deletions.
  1. +5 −0 .gitignore
  2. +1 −1 example/example.pro
  3. +6 −0 example/main.cpp
  4. +66 −58 example/mainwindow.ui
  5. +10 −5 src/ftpmodel.cpp
View
@@ -1,2 +1,7 @@
Makefile
*.o
+debug
+release
+*.release
+*.debug
+*.user
View
@@ -1,6 +1,6 @@
CONFIG += debug
QT += network
-INTERFACES += mainwindow.ui
+FORMS += mainwindow.ui
SOURCES += main.cpp
TARGET = example
View
@@ -45,6 +45,7 @@ Q_OBJECT
connect(ui.leftUrl, SIGNAL(textChanged(const QString& )),
this, SLOT(leftPathChanged(const QString &)));
connect(ui.connectButton, SIGNAL(clicked()), this, SLOT(connectToHost()));
+ connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(refresh()));
}
private slots:
@@ -58,6 +59,11 @@ private slots:
ftpModel.setUrl(url);
}
+ void refresh()
+ {
+ ftpModel.refresh(ui.rightView->currentIndex());
+ }
+
private:
FtpModel ftpModel;
QDirModel dirModel;
View
@@ -1,132 +1,140 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>MainWindow</class>
- <widget class="QWidget" name="MainWindow" >
- <property name="geometry" >
+ <widget class="QWidget" name="MainWindow">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>652</width>
<height>419</height>
</rect>
</property>
- <property name="windowTitle" >
+ <property name="windowTitle">
<string>MainWindow</string>
</property>
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
+ <layout class="QVBoxLayout">
+ <property name="spacing">
<number>6</number>
</property>
+ <property name="margin">
+ <number>9</number>
+ </property>
<item>
- <widget class="QSplitter" name="splitter" >
- <property name="orientation" >
+ <widget class="QSplitter" name="splitter">
+ <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <widget class="QWidget" name="" >
- <layout class="QGridLayout" >
- <property name="margin" >
+ <widget class="QWidget" name="layoutWidget">
+ <layout class="QGridLayout" name="leftLayout">
+ <property name="margin">
<number>0</number>
</property>
- <property name="spacing" >
+ <property name="spacing">
<number>6</number>
</property>
- <item row="0" column="0" >
- <widget class="QLabel" name="label_4" >
- <property name="text" >
+ <item row="0" column="0">
+ <widget class="QLabel" name="localLbl">
+ <property name="text">
<string>Local:</string>
</property>
</widget>
</item>
- <item row="0" column="1" >
- <widget class="QLineEdit" name="leftUrl" />
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="leftUrl"/>
</item>
- <item row="1" column="0" colspan="2" >
- <widget class="QTreeView" name="leftView" >
- <property name="acceptDrops" >
+ <item row="1" column="0" colspan="2">
+ <widget class="QTreeView" name="leftView">
+ <property name="acceptDrops">
<bool>true</bool>
</property>
- <property name="showDropIndicator" stdset="0" >
+ <property name="showDropIndicator" stdset="0">
<bool>true</bool>
</property>
- <property name="dragEnabled" >
+ <property name="dragEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
- <widget class="QWidget" name="layoutWidget" >
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
- <property name="spacing" >
+ <widget class="QWidget" name="layoutWidget">
+ <layout class="QVBoxLayout" name="rightLayout">
+ <property name="spacing">
<number>6</number>
</property>
+ <property name="margin">
+ <number>0</number>
+ </property>
<item>
- <widget class="QGroupBox" name="groupBox" >
- <layout class="QGridLayout" >
- <property name="margin" >
+ <widget class="QGroupBox" name="groupBox">
+ <layout class="QGridLayout">
+ <property name="margin">
<number>9</number>
</property>
- <property name="spacing" >
+ <property name="spacing">
<number>6</number>
</property>
- <item row="2" column="1" >
- <widget class="QLineEdit" name="host" />
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="host"/>
</item>
- <item row="1" column="0" >
- <widget class="QLabel" name="label_2" >
- <property name="text" >
+ <item row="1" column="0">
+ <widget class="QLabel" name="passLbl">
+ <property name="text">
<string>Password:</string>
</property>
</widget>
</item>
- <item row="0" column="0" >
- <widget class="QLabel" name="label" >
- <property name="text" >
+ <item row="0" column="0">
+ <widget class="QLabel" name="userLbl">
+ <property name="text">
<string>User:</string>
</property>
</widget>
</item>
- <item row="1" column="1" >
- <widget class="QLineEdit" name="password" >
- <property name="echoMode" >
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="password">
+ <property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
- <item row="2" column="0" >
- <widget class="QLabel" name="label_3" >
- <property name="text" >
+ <item row="2" column="0">
+ <widget class="QLabel" name="hostLbl">
+ <property name="text">
<string>Host:</string>
</property>
</widget>
</item>
- <item row="0" column="1" >
- <widget class="QLineEdit" name="username" />
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="username"/>
</item>
- <item row="3" column="1" >
- <widget class="QPushButton" name="connectButton" >
- <property name="text" >
+ <item row="4" column="1">
+ <widget class="QPushButton" name="connectButton">
+ <property name="text">
<string>&amp;Connect</string>
</property>
</widget>
</item>
+ <item row="5" column="1">
+ <widget class="QPushButton" name="refreshButton">
+ <property name="text">
+ <string>Refresh</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
<item>
- <widget class="QTreeView" name="rightView" >
- <property name="acceptDrops" >
+ <widget class="QTreeView" name="rightView">
+ <property name="acceptDrops">
<bool>true</bool>
</property>
- <property name="showDropIndicator" stdset="0" >
+ <property name="showDropIndicator" stdset="0">
<bool>true</bool>
</property>
- <property name="dragEnabled" >
+ <property name="dragEnabled">
<bool>true</bool>
</property>
</widget>
View
@@ -296,11 +296,11 @@ QVariant FtpModel::headerData(int section, Qt::Orientation orientation, int role
switch (section) {
case 0: return tr("Name");
case 1: return tr("Size");
- #ifdef Q_OS_MAC
+#ifdef Q_OS_MAC
case 2: return tr("Kind");
- #else
+#else
case 2: return tr("Type");
- #endif
+#endif
case 3: return tr("Date Modified");
default : return QVariant();
}
@@ -421,7 +421,12 @@ void FtpModel::refresh(const QModelIndex &parent)
return;
FtpItem *item = parent.isValid() ? static_cast<FtpItem*>(parent.internalPointer()) : root;
- item->children.clear();
+ if(!item->children.isEmpty())
+ {
+ beginRemoveRows(parent, 0, item->children.count() - 1);
+ item->children.clear();
+ endRemoveRows();
+ }
item->fetchedChildren = false;
fetchMore(parent);
}
@@ -517,7 +522,7 @@ QMimeData *FtpModel::mimeData(const QModelIndexList &indexes) const
\reimp
*/
bool FtpModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &parent)
+ int row, int column, const QModelIndex &parent)
{
if (!connected() || action != Qt::CopyAction && action != Qt::MoveAction)
return false;

0 comments on commit c8c190b

Please sign in to comment.