summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno Moeller <am@mindwerk.de>2010-06-17 17:59:39 +0200
committerArno Moeller <am@mindwerk.de>2010-06-17 17:59:39 +0200
commita4e40f771e7f6df9dc8d7e63c5460761eb0e33c0 (patch)
tree2c4585a84ba9179aea8309960e6824bb7f6ec6b4
parentb503c9e9a29c41b4e0d5e6c43af42b6dc135b9c8 (diff)
downloadSheMov-a4e40f771e7f6df9dc8d7e63c5460761eb0e33c0.tar.gz
SheMov-a4e40f771e7f6df9dc8d7e63c5460761eb0e33c0.tar.bz2
SheMov-a4e40f771e7f6df9dc8d7e63c5460761eb0e33c0.zip
Partial implementation of adding new Series
Adding an item to the TreeView works, but it doesn't get focus after inserting. Also the data is not shown. And setting the title of the new item should make the database puke.
-rw-r--r--archivetreeview.h1
-rw-r--r--seriestreemodel.cpp2
-rw-r--r--seriestreemodel.h2
-rw-r--r--seriestreewidget.cpp28
-rw-r--r--seriestreewidget.h13
-rw-r--r--shemov.cpp6
-rw-r--r--shemov.h3
-rw-r--r--smtreemodel.cpp2
8 files changed, 49 insertions, 8 deletions
diff --git a/archivetreeview.h b/archivetreeview.h
index ef0e51a..fc3e2fe 100644
--- a/archivetreeview.h
+++ b/archivetreeview.h
@@ -19,6 +19,7 @@ class ArchiveTreeView : public QWidget
Q_OBJECT
public:
explicit ArchiveTreeView(QWidget *parent = 0);
+ SeriesTreeWidget *seriesWidget() { return mSeriesWidget; }
private:
//widgets
diff --git a/seriestreemodel.cpp b/seriestreemodel.cpp
index 390f19c..0edbd8e 100644
--- a/seriestreemodel.cpp
+++ b/seriestreemodel.cpp
@@ -41,7 +41,7 @@ Qt::ItemFlags SeriesTreeModel::flags(const QModelIndex &index) const{
return 0;
}
Qt::ItemFlags retval = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
- if(index.data(TypeRole).toInt() == Series){
+ if(index.data(TypeRole).toInt() == Series || index.data(TypeRole).toInt() == NewSeries){
return retval | Qt::ItemIsEditable;
}
return retval;
diff --git a/seriestreemodel.h b/seriestreemodel.h
index 74bb53c..507761c 100644
--- a/seriestreemodel.h
+++ b/seriestreemodel.h
@@ -19,7 +19,7 @@ class SeriesTreeModel : public SmTreeModel {
public:
enum CustomRoles { NameRole = Qt::UserRole + 1, SeriesIdRole = Qt::UserRole + 2, SeriesPartIdRole = Qt::UserRole + 3, SeriesPartRole = Qt::UserRole + 4, TypeRole = Qt::UserRole + 5 };
enum Fields { Name = 0, SeriesId = 1, SeriesPartId = 2, SeriesPart = 3, Type = 4 };
- enum Types { Series, Part };
+ enum Types { Series, Part, NewSeries };
explicit SeriesTreeModel(QStringList &headers, QObject *parent = 0);
~SeriesTreeModel();
diff --git a/seriestreewidget.cpp b/seriestreewidget.cpp
index d440140..5fb7d2c 100644
--- a/seriestreewidget.cpp
+++ b/seriestreewidget.cpp
@@ -12,6 +12,9 @@
#include <QLabel>
#include <QSortFilterProxyModel>
#include <QRegExp>
+#include <QContextMenuEvent>
+#include <QMenu>
+#include <QAction>
#include "seriestreewidget.h"
#include "smubermodel.h"
@@ -35,15 +38,15 @@ SeriesTreeWidget::SeriesTreeWidget(QWidget *parent) : QWidget(parent){
//the view
mView = new SeriesTreeView;
mProxy = new QSortFilterProxyModel;
- SeriesTreeModel *sourceModel = SmUberModelSingleton::instance()->seriesModel();
- mProxy->setSourceModel(sourceModel);
+ 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(sourceModel, SIGNAL(needResort()), this, SLOT(resort()));
+ connect(mModel, SIGNAL(needResort()), this, SLOT(resort()));
//layout
QVBoxLayout *mainLayout = new QVBoxLayout;
@@ -53,6 +56,17 @@ SeriesTreeWidget::SeriesTreeWidget(QWidget *parent) : QWidget(parent){
}
+void SeriesTreeWidget::newSeries(){
+ QList<QVariant> data;
+ data << tr("<New series>") << -1 << -1 << 0 << SeriesTreeModel::NewSeries;
+ if(mModel->addRow(data, QModelIndex())){
+ QModelIndex newRow = mModel->index(mModel->rowCount(QModelIndex()) - 1, 0, QModelIndex());
+ if(newRow.isValid()){
+ mView->edit(newRow);
+ }
+ }
+}
+
void SeriesTreeWidget::filter(){
mProxy->setFilterRegExp(mFilterEdit->text());
}
@@ -62,3 +76,11 @@ void SeriesTreeWidget::resort(){
}
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());
+}
diff --git a/seriestreewidget.h b/seriestreewidget.h
index fa84419..6e949b2 100644
--- a/seriestreewidget.h
+++ b/seriestreewidget.h
@@ -13,13 +13,18 @@
class QLineEdit;
class QPushButton;
-class QTreeView;
class QSortFilterProxyModel;
+class SeriesTreeModel;
+class SeriesTreeView;
class SeriesTreeWidget : public QWidget {
Q_OBJECT
public:
explicit SeriesTreeWidget(QWidget *parent = 0);
+ SeriesTreeView *seriesTree() { return mView; }
+
+ public slots:
+ void newSeries();
private slots:
void filter();
@@ -28,14 +33,18 @@ class SeriesTreeWidget : public QWidget {
private:
QLineEdit *mFilterEdit;
QPushButton *mFilter;
- QTreeView *mView;
+ SeriesTreeView *mView;
QSortFilterProxyModel *mProxy;
+ SeriesTreeModel *mModel;
};
class SeriesTreeView : public QTreeView {
Q_OBJECT
public:
explicit SeriesTreeView(QWidget *parent = 0);
+
+ protected:
+ virtual void contextMenuEvent(QContextMenuEvent *e);
};
#endif
diff --git a/shemov.cpp b/shemov.cpp
index 4969713..8db4db9 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -47,6 +47,7 @@
#include "archivetreeview.h"
#include "smubermodelsingleton.h"
#include "smubermodel.h"
+#include "seriestreewidget.h"
SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags), mOpenWithGroupFS(0), mOpenWithGroupAV(0) {
qApp->setWindowIcon(QIcon(":/shemov.png"));
@@ -355,6 +356,11 @@ void SheMov::createActions(){
mStatisticsA = new QAction(tr("Some statistics..."), this);
connect(mStatisticsA, SIGNAL(triggered()), this, SLOT(showStatistics()));
+ //Tree context menu
+ mNewSeriesA = new QAction(tr("New series"), this);
+ mATree->seriesWidget()->seriesTree()->addAction(mNewSeriesA);
+ connect(mNewSeriesA, SIGNAL(triggered()), mATree->seriesWidget(), SLOT(newSeries()));
+
// misc
mOpenWithMapperFS = new QSignalMapper(this);
mOpenWithMapperAV = new QSignalMapper(this);
diff --git a/shemov.h b/shemov.h
index 3febc1a..20ab1e9 100644
--- a/shemov.h
+++ b/shemov.h
@@ -95,6 +95,9 @@ class SheMov : public QMainWindow {
QAction *mOpenWithMenuAVA;
QAction *mRenameMenuA;
QAction *mCopyToPartsA;
+
+ //TreeView Actions
+ QAction *mNewSeriesA;
QActionGroup *mOpenWithGroupFS;
QActionGroup *mOpenWithGroupAV;
//EndActions
diff --git a/smtreemodel.cpp b/smtreemodel.cpp
index 292ed20..227c1cb 100644
--- a/smtreemodel.cpp
+++ b/smtreemodel.cpp
@@ -168,7 +168,7 @@ bool SmTreeModel::addRow(const QList<QVariant> &data, const QModelIndex &parent)
SmTreeItem *parentItem = itemAt(parent);
if(insertRows(parentItem->childCount(), 1, parent)){
- SmTreeItem *child = parentItem->child(parentItem->childCount());
+ SmTreeItem *child = parentItem->child(parentItem->childCount() - 1);
delete child;
SmTreeItem *newChild = new SmTreeItem(data, parentItem);
child = newChild;