added search to project toolbar
This commit is contained in:
+5
-1
@@ -130,7 +130,11 @@ Project::Project(QWidget *parent) :
|
||||
connect(toolbar_redo, SIGNAL(clicked(bool)), mainWindow, SLOT(redo()));
|
||||
toolbar->addWidget(toolbar_redo);
|
||||
|
||||
toolbar->addStretch();
|
||||
QLineEdit* toolbar_search = new QLineEdit();
|
||||
toolbar_search->setPlaceholderText(tr("Search media, markers, etc."));
|
||||
connect(toolbar_search, SIGNAL(textChanged(QString)), sorter, SLOT(update_search_filter(const QString&)));
|
||||
toolbar->addWidget(toolbar_search);
|
||||
|
||||
QPushButton* toolbar_tree_view = new QPushButton();
|
||||
QIcon icon6;
|
||||
icon6.addFile(QStringLiteral(":/icons/treeview.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "projectfilter.h"
|
||||
|
||||
#include "project/media.h"
|
||||
#include "project/sequence.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@@ -15,17 +16,49 @@ bool ProjectFilter::get_show_sequences() {
|
||||
|
||||
void ProjectFilter::set_show_sequences(bool b) {
|
||||
show_sequences = b;
|
||||
invalidateFilter();
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void ProjectFilter::update_search_filter(const QString &s) {
|
||||
search_filter = s;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
bool ProjectFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
|
||||
// retrieve media object from index
|
||||
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
|
||||
Media* media = static_cast<Media*>(index.internalPointer());
|
||||
|
||||
// hide sequences if show_sequences is false
|
||||
if (!show_sequences) {
|
||||
// hide sequences if show_sequences is false
|
||||
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
|
||||
Media* media = static_cast<Media*>(index.internalPointer());
|
||||
if (media != nullptr && media->get_type() == MEDIA_TYPE_SEQUENCE) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// filter by search filter string
|
||||
if (!search_filter.isEmpty()) {
|
||||
// search markers if media is a sequene
|
||||
bool marker_contains_search = false;
|
||||
|
||||
if (media->get_type() == MEDIA_TYPE_SEQUENCE) {
|
||||
Sequence* s = media->to_sequence();
|
||||
for (int i=0;i<s->markers.size();i++) {
|
||||
qDebug() << "marker name:" << s->markers.at(i).name;
|
||||
if (s->markers.at(i).name.contains(search_filter, Qt::CaseInsensitive)) {
|
||||
marker_contains_search = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hide any rows that don't contain the search string (unless it's a folder)
|
||||
if (!marker_contains_search
|
||||
&& media->get_type() != MEDIA_TYPE_FOLDER
|
||||
&& !media->get_name().contains(search_filter, Qt::CaseInsensitive)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
||||
}
|
||||
|
||||
+19
-1
@@ -7,13 +7,31 @@ class ProjectFilter : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectFilter(QObject *parent = nullptr);
|
||||
|
||||
// are sequences visible
|
||||
bool get_show_sequences();
|
||||
|
||||
public slots:
|
||||
|
||||
// set whether sequences are visible
|
||||
void set_show_sequences(bool b);
|
||||
|
||||
// update search filter
|
||||
void update_search_filter(const QString& s);
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
||||
|
||||
// function that filters whether rows are displayed or not
|
||||
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
||||
|
||||
private:
|
||||
|
||||
// internal variable for whether to show sequences
|
||||
bool show_sequences;
|
||||
|
||||
// search filter variable
|
||||
QString search_filter;
|
||||
|
||||
};
|
||||
|
||||
#endif // PROJECTFILTER_H
|
||||
|
||||
@@ -842,6 +842,7 @@ void AddMarkerAction::redo() {
|
||||
if (index == -1) {
|
||||
Marker m;
|
||||
m.frame = time;
|
||||
m.name = name;
|
||||
markers.append(m);
|
||||
} else {
|
||||
old_name = markers.at(index).name;
|
||||
|
||||
Reference in New Issue
Block a user