/* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ #include #include #include #include #include #include #include #include #include #include #include "seriestreewidget.h" #include "smubermodel.h" #include "smtreemodel.h" #include "smubermodelsingleton.h" #include "seriestreemodel.h" SeriesTreeWidget::SeriesTreeWidget(QWidget *parent) : QWidget(parent){ //filter bar QLabel *l1 = new QLabel(tr("&Filter:")); mFilterEdit = new QLineEdit; l1->setBuddy(mFilterEdit); mFilter = new QPushButton(tr("Filter")); QHBoxLayout *filterLayout = new QHBoxLayout; connect(mFilter, SIGNAL(clicked()), this, SLOT(filter())); connect(mFilterEdit, SIGNAL(returnPressed()), this, SLOT(filter())); filterLayout->addWidget(l1); filterLayout->addWidget(mFilterEdit); filterLayout->addWidget(mFilter); //the view mView = new SeriesTreeView; mProxy = new QSortFilterProxyModel; mModel = SmUberModelSingleton::instance()->seriesModel(); mProxy->setSourceModel(mModel); mView->setModel(mProxy); mView->setSortingEnabled(true); for(int i = 1; i < 5 ;++i){ mView->setColumnHidden(i, true); } mView->resizeColumnToContents(0); connect(mModel, SIGNAL(needResort()), this, SLOT(resort())); //layout QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(filterLayout); mainLayout->addWidget(mView); setLayout(mainLayout); } void SeriesTreeWidget::newSeries(){ QList data; data << tr("") << QVariant() << QVariant() << QVariant() << SeriesTreeModel::NewSeries; if(mModel->addRow(data, QModelIndex())){ QModelIndex newRow = mModel->index(mModel->rowCount(QModelIndex()) - 1, 0, QModelIndex()); if(newRow.isValid()){ QModelIndex proxyIndex = mProxy->mapFromSource(newRow); mView->selectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect); mView->edit(proxyIndex); } } } void SeriesTreeWidget::filter(){ mProxy->setFilterRegExp(mFilterEdit->text()); } void SeriesTreeWidget::resort(){ mView->sortByColumn(0, mProxy->sortOrder()); mView->scrollTo(mView->selectionModel()->currentIndex(), QAbstractItemView::PositionAtCenter); } SeriesTreeView::SeriesTreeView(QWidget *parent) : QTreeView(parent) {} void SeriesTreeView::contextMenuEvent(QContextMenuEvent *e){ QMenu contextMenu(this); foreach(QAction *a, actions()){ contextMenu.addAction(a); } contextMenu.exec(e->globalPos()); }