summaryrefslogtreecommitdiffstats
path: root/examples/widgets/itemviews/fetchmore/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/itemviews/fetchmore/window.cpp')
-rw-r--r--examples/widgets/itemviews/fetchmore/window.cpp48
1 files changed, 27 insertions, 21 deletions
diff --git a/examples/widgets/itemviews/fetchmore/window.cpp b/examples/widgets/itemviews/fetchmore/window.cpp
index fa23bddc73..64746c18f8 100644
--- a/examples/widgets/itemviews/fetchmore/window.cpp
+++ b/examples/widgets/itemviews/fetchmore/window.cpp
@@ -56,37 +56,43 @@
Window::Window(QWidget *parent)
: QWidget(parent)
{
- FileListModel *model = new FileListModel(this);
- model->setDirPath(QLibraryInfo::path(QLibraryInfo::PrefixPath));
+ model = new FileListModel(this);
+ model->setDirPath(QDir::rootPath());
- QLabel *label = new QLabel(tr("&Directory:"));
- QLineEdit *lineEdit = new QLineEdit;
- label->setBuddy(lineEdit);
-
- QListView *view = new QListView;
+ view = new QListView;
view->setModel(model);
- logViewer = new QTextBrowser(this);
- logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
+ logViewer = new QPlainTextEdit(this);
+ logViewer->setReadOnly(true);
+ logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
+ QSizePolicy::Preferred));
- connect(lineEdit, &QLineEdit::textChanged,
- model, &FileListModel::setDirPath);
- connect(lineEdit, &QLineEdit::textChanged,
- logViewer, &QTextEdit::clear);
connect(model, &FileListModel::numberPopulated,
this, &Window::updateLog);
+ connect(view, &QAbstractItemView::activated,
+ this, &Window::activated);
- QGridLayout *layout = new QGridLayout;
- layout->addWidget(label, 0, 0);
- layout->addWidget(lineEdit, 0, 1);
- layout->addWidget(view, 1, 0, 1, 2);
- layout->addWidget(logViewer, 2, 0, 1, 2);
+ auto *layout = new QVBoxLayout(this);
+ layout->addWidget(view);
+ layout->addWidget(logViewer);
- setLayout(layout);
setWindowTitle(tr("Fetch More Example"));
}
-void Window::updateLog(int number)
+void Window::updateLog(const QString &path, int start, int number, int total)
+{
+ const int last = start + number - 1;
+ const QString nativePath = QDir::toNativeSeparators(path);
+ const QString message = tr("%1..%2/%3 items from \"%4\" added.")
+ .arg(start).arg(last).arg(total).arg(nativePath);
+ logViewer->appendPlainText(message);
+}
+
+void Window::activated(const QModelIndex &index)
{
- logViewer->append(tr("%1 items added.").arg(number));
+ const QFileInfo fi = model->fileInfoAt(index);
+ if (fi.isDir()) {
+ logViewer->clear();
+ model->setDirPath(fi.absoluteFilePath());
+ }
}