unknownfilelookuptask.cpp \
renameutils.cpp \
directorywatcher.cpp \
- addrelatedepisodestask.cpp \
+ addrelatedepisodestask.cpp
HEADERS += \
localmylist_global.h \
void MyListModel::fetchMore(const QModelIndex &parent)
{
- int newrows = 0;
+ MyListNode *node;
if (parent.isValid())
- newrows = static_cast<MyListNode *>(parent.internalPointer())->fetchMore();
+ node = static_cast<MyListNode *>(parent.internalPointer());
else
- newrows = rootItem->fetchMore();
+ node = rootItem;
- if (!newrows)
- return;
-
- beginInsertRows(parent, rowCount(parent) - newrows, rowCount(parent) - 1);
+ int nextFetchSize = node->nextFetchSize();
+ beginInsertRows(parent, rowCount(parent), rowCount(parent) + nextFetchSize - 1);
+ int newrows = node->fetchMore();
+ Q_ASSERT(newrows == nextFetchSize);
endInsertRows();
qDebug() << "added" << newrows << "new rows";
return;
itemData << "Title" << "Episode / Version" << "Rating / Quality" << "Vote" << "Watched / Renamed";
-
}
MyListNode::~MyListNode()
return m_totalRowCount;
}
+int MyListNode::nextFetchSize() const
+{
+ return qMin(LIMIT, totalRowCount() - childCount());
+}
+
bool MyListNode::canFetchMore() const
{
if (m_type != FileLocation && childCount() < totalRowCount())
<< QObject::tr("%1 of %2").arg(q.value(5).toInt()).arg(q.value(2).toInt());
childItems << new MyListAnimeNode(id, data, this);
}
+ qDebug() << "root" << q.size();
return q.size();
}
MyListNode(NodeType type = Root, int m_id = 0, const QList<QVariant> &data = QList<QVariant>(), MyListNode *parent = 0);
virtual ~MyListNode();
- void appendChild(MyListNode *child);
-
MyListNode *child(int row);
int childCount() const;
int columnCount() const;
MyListNode *parent();
int totalRowCount() const;
+ int nextFetchSize() const;
bool canFetchMore() const;
virtual int fetchMore();
QList<QVariant> itemData;
MyListNode *parentItem;
- static const int LIMIT = 100;
+ static const int LIMIT = 200;
};
class MyListAnimeNode : public MyListNode
#include "database.h"
#include "settings.h"
#include "mylistmodel.h"
+#include "mylistfiltermodel.h"
#include "unknownfilelookuptask.h"
#include "addrelatedepisodestask.h"
#include "renamesettingsdialog.h"
MyList::instance()->database()->connect();
myListModel = new MyListModel(this);
- ui->myListView->setModel(myListModel);
+ myListFilterModel = new MyListFilterModel(this);
+ myListFilterModel->setSourceModel(myListModel);
+ ui->myListView->setModel(myListFilterModel);
ui->myListView->header()->setResizeMode(0, QHeaderView::Stretch);
ui->myListView->header()->setStretchLastSection(false);
}
event->acceptProposedAction();
}
+
+void MainWindow::on_filterInput_textChanged(const QString &filter)
+{
+ myListFilterModel->setFilterFixedString(filter);
+}
class MyListModel;
}
class QLabel;
-class QSortFilterProxyModel;
class RenameSettingsDialog;
+class MyListFilterModel;
class MainWindow : public QMainWindow
{
void on_actionRenameScript_triggered();
void on_actionStartDirectoryWatcher_triggered();
void on_actionAddRelatedEpisodeInfo_triggered();
+ void on_filterInput_textChanged(const QString &filter);
protected:
void dragEnterEvent(QDragEnterEvent *event);
QLabel *taskCountLabel;
LocalMyList::MyListModel *myListModel;
- QSortFilterProxyModel *myListFilterModel;
+ MyListFilterModel *myListFilterModel;
};
#endif // MAINWINDOW_H
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLineEdit" name="filterInput"/>
+ </item>
<item>
<widget class="MyListView" name="myListView"/>
</item>
mainwindow.cpp \
databaseconnectiondialog.cpp \
mylistview.cpp \
- renamesettingsdialog.cpp
+ renamesettingsdialog.cpp \
+ mylistfiltermodel.cpp
HEADERS += mainwindow.h \
databaseconnectiondialog.h \
mylistview.h \
- renamesettingsdialog.h
+ renamesettingsdialog.h \
+ mylistfiltermodel.h
FORMS += mainwindow.ui \
databaseconnectiondialog.ui \
--- /dev/null
+#include "mylistfiltermodel.h"
+
+#include <QDebug>
+
+MyListFilterModel::MyListFilterModel(QObject *parent) :
+ QSortFilterProxyModel(parent)
+{
+ setFilterCaseSensitivity(Qt::CaseInsensitive);
+}
+
+bool MyListFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
+{
+ if (source_parent.isValid())
+ return true;
+
+ QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
+ return sourceModel()->data(idx).toString().contains(filterRegExp());
+}
--- /dev/null
+#ifndef MYLISTFILTERMODEL_H
+#define MYLISTFILTERMODEL_H
+
+#include <QSortFilterProxyModel>
+
+class MyListFilterModel : public QSortFilterProxyModel
+{
+ Q_OBJECT
+public:
+ explicit MyListFilterModel(QObject *parent = 0);
+
+protected:
+ bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
+};
+
+#endif // MYLISTFILTERMODEL_H