summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2012-03-02 20:57:55 +0100
committerArno <am@disconnect.de>2012-03-02 20:57:55 +0100
commit8b0aca608140c72fb7d60f7b821f78a86848a70a (patch)
treea6bf1ccef9f4b2021e92695c7459ae72859a86b7
parent6e03469151a2a3eae6e54dd1e138a2628d51eab3 (diff)
downloadSheMov-8b0aca608140c72fb7d60f7b821f78a86848a70a.tar.gz
SheMov-8b0aca608140c72fb7d60f7b821f78a86848a70a.tar.bz2
SheMov-8b0aca608140c72fb7d60f7b821f78a86848a70a.zip
Make add mapping item a context menu entry
Remove the QLineEdit and QPushButtons from the bottom of MappingTreeWidget and make adding mapping items available in the context menu.
-rw-r--r--mappingtreemodel.cpp4
-rw-r--r--mappingtreewidget.cpp22
-rw-r--r--mappingtreewidget.h4
3 files changed, 8 insertions, 22 deletions
diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp
index 3dabe16..8651a4a 100644
--- a/mappingtreemodel.cpp
+++ b/mappingtreemodel.cpp
@@ -226,7 +226,9 @@ bool MappingTreeModel::addChild(const QVariant &name, const QModelIndex &parent)
int where = lowerBound(pItem, mSelectChildQ->value(1), Name);
if(insertRows(where, 1, parent)){
QModelIndex newIdx = index(where, 0, parent);
- setData(newIdx, mSelectChildQ->value(1), NameRole);
+ if(!setData(newIdx, mSelectChildQ->value(1), NameRole)){
+ return false;
+ }
setData(newIdx, mSelectChildQ->value(0), IdRole);
setData(newIdx, mSelectChildQ->value(2), AddedRole);
}
diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp
index 41aa6e2..ba175ba 100644
--- a/mappingtreewidget.cpp
+++ b/mappingtreewidget.cpp
@@ -49,18 +49,9 @@ MappingTreeWidget::MappingTreeWidget(QWidget *parent) : QWidget(parent){
connect(mAddType, SIGNAL(clicked()), this, SLOT(addType()));
mDeleteType = new QPushButton(tr("Delete type"));
connect(mDeleteType, SIGNAL(clicked()), this, SLOT(deleteType()));
- mEdit = new QLineEdit;
- mAddChild = new QPushButton(tr("&Add"));
- connect(mAddChild, SIGNAL(clicked()), this, SLOT(addChild()));
- mDeleteChild = new QPushButton(tr("Delete"));
- connect(mDeleteChild, SIGNAL(clicked()), this, SLOT(deleteChild()));
QHBoxLayout *typesButtonLayout = new QHBoxLayout;
typesButtonLayout->addWidget(mDeleteType);
typesButtonLayout->addWidget(mAddType);
- QHBoxLayout *buttonLayout = new QHBoxLayout;
- buttonLayout->addStretch();
- buttonLayout->addWidget(mDeleteChild);
- buttonLayout->addWidget(mAddChild);
//select type and populate model
QSettings s;
@@ -78,6 +69,9 @@ MappingTreeWidget::MappingTreeWidget(QWidget *parent) : QWidget(parent){
}
//setup actions
+ mAddChildA = new QAction(tr("Add..."), this);
+ connect(mAddChildA, SIGNAL(triggered()), this, SLOT(addChild()));
+ mTree->addAction(mAddChildA);
mDeleteChildA = new QAction(tr("Delete"), this);
connect(mDeleteChildA, SIGNAL(triggered()), this, SLOT(deleteChild()));
mTree->addAction(mDeleteChildA);
@@ -93,11 +87,7 @@ MappingTreeWidget::MappingTreeWidget(QWidget *parent) : QWidget(parent){
mainLayout->addWidget(mTypeBox);
mainLayout->addLayout(typesButtonLayout);
mainLayout->addWidget(mTree);
- mainLayout->addWidget(mEdit);
- mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
- mEdit->setFocus();
- setTabOrder(mEdit, mAddChild);
}
MappingData MappingTreeWidget::selectedItem() const {
@@ -127,11 +117,7 @@ MappingData MappingTreeWidget::selectedItem() const {
void MappingTreeWidget::addChild(){
QModelIndex sel = selected();
- if(!sel.isValid()){
- QMessageBox::critical(this, tr("Error"), tr("No parent item selected!"));
- return;
- }
- QString value = mEdit->text().toLower().trimmed();
+ QString value = QInputDialog::getText(this, tr("Mapping name"), tr("Enter mapping name"));
if(value.isEmpty()){
return;
}
diff --git a/mappingtreewidget.h b/mappingtreewidget.h
index 76e7585..f8c463b 100644
--- a/mappingtreewidget.h
+++ b/mappingtreewidget.h
@@ -55,11 +55,9 @@ class MappingTreeWidget : public QWidget {
QSortFilterProxyModel *mProxy;
QStringListModel *mTypesModel;
QComboBox *mTypeBox;
- QPushButton *mAddChild;
- QPushButton *mDeleteChild;
QPushButton *mAddType;
QPushButton *mDeleteType;
- QLineEdit *mEdit;
+ QAction *mAddChildA;
QAction *mDeleteChildA;
QAction *mEditChildA;
QAction *mMoveChildA;