# # # patch "src/model/GetAttributes.h" # from [12f8e60c5fcb81caacd778b3b99c6da131af706f] # to [de87690563da758329186f4aa44b6dac47d46a45] # # patch "src/view/AttributesView.cpp" # from [e4b0b75ba4c9abd6fa8efa2c6def8a4f2ae6dc96] # to [c31cfb3521fc074633174f088628737a42171506] # ============================================================ --- src/model/GetAttributes.h 12f8e60c5fcb81caacd778b3b99c6da131af706f +++ src/model/GetAttributes.h de87690563da758329186f4aa44b6dac47d46a45 @@ -50,6 +50,7 @@ public: bool setAttribute(const QString &, const QString &); bool dropAttribute(const QString &); + inline bool attributesLoaded() const { return !path.isEmpty(); } public slots: void readAttributes(const QString &); ============================================================ --- src/view/AttributesView.cpp e4b0b75ba4c9abd6fa8efa2c6def8a4f2ae6dc96 +++ src/view/AttributesView.cpp c31cfb3521fc074633174f088628737a42171506 @@ -36,21 +36,21 @@ AttributesView::AttributesView(QWidget * { setRootIsDecorated(false); setItemsExpandable(false); - + QHeaderView * headerView = header(); headerView->setClickable(true); headerView->setResizeMode(QHeaderView::ResizeToContents); - + connect( headerView, SIGNAL(sectionClicked(int)), this, SLOT(sectionClicked(int)) ); - + connect( this, SIGNAL(contextMenuRequested(const QModelIndexList &, const QPoint &)), this, SLOT(menuRequested(const QModelIndexList &, const QPoint &)) ); - + connect( this, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(aboutToEditAttribute(const QModelIndex &)) @@ -62,17 +62,17 @@ void AttributesView::sectionClicked(int void AttributesView::sectionClicked(int logicalIndex) { // do not popup the menu if we haven't focused a valid item - GetAttributes * attrModel = qobject_cast(model()); - if (attrModel->currentPath().isEmpty()) return; - + GetAttributes * attrModel = qobject_cast(model()); + if (attrModel->attributesLoaded()) return; + if (logicalIndex != 0) return; - + QHeaderView * headerView = header(); int visualIndex = headerView->visualIndex(logicalIndex); - + int left = 0; int top = headerView->height(); - + if (visualIndex > 0) { for (int i=0; isectionSize(headerView->logicalIndex(i)); } } - + if (left > headerView->width()) { left = headerView->width() - headerView->sectionSize(logicalIndex); } - + QMenu popupMenu(this); popupMenu.addAction( tr("add new attribute"), this, SLOT(addAttribute()) @@ -96,50 +96,36 @@ void AttributesView::menuRequested(const void AttributesView::menuRequested(const QModelIndexList & indexes, const QPoint & pt) { if (indexes.size() != 1) return; - + selectedIndex = indexes.at(0); - + QMenu popupMenu(this); - + QFont activeFont; activeFont.setBold(true); - + popupMenu.addAction( tr("edit attribute"), this, SLOT(editAttribute()) )->setFont(activeFont); - + popupMenu.addAction( tr("drop attribute"), this, SLOT(dropAttribute()) ); - + popupMenu.exec(pt); } void AttributesView::addAttribute() { AddEditAttribute dlg(this); - + if (dlg.exec() == QDialog::Accepted) { GetAttributes * attrModel = qobject_cast(model()); - - QStringList cmd; - cmd << "set_attribute"; - cmd << attrModel->currentPath(); - cmd << dlg.getKey() << dlg.getValue(); - - Monotone * mtn = MTN(this); - int cmdNum = 0; - // do not skip empty parameters - mtn->executeCommand(cmd, cmdNum, false); - - if (mtn->getReturnCode(cmdNum) > 0) + if (!attrModel->setAttribute(dlg.getKey(), dlg.getValue())) { C(QString("Couldn't set attribute")); - return; } - - attrModel->readAttributes(attrModel->currentPath()); } } @@ -154,35 +140,21 @@ void AttributesView::editAttribute() { QModelIndex keyIdx = model()->index(selectedIndex.row(), 1, QModelIndex()); QModelIndex valIdx = model()->index(selectedIndex.row(), 2, QModelIndex()); - - // UserRole is overloaded with the actual string value of the + + // UserRole is overloaded with the actual string value of the // key / value pair QString key = model()->data(keyIdx, Qt::UserRole).toString(); QString val = model()->data(valIdx, Qt::UserRole).toString(); - + AddEditAttribute dlg(this, key, val); - + if (dlg.exec() == QDialog::Accepted) { GetAttributes * attrModel = qobject_cast(model()); - - QStringList cmd; - cmd << "set_attribute"; - cmd << attrModel->currentPath(); - cmd << dlg.getKey() << dlg.getValue(); - - Monotone * mtn = MTN(this); - int cmdNum = 0; - // do not skip empty parameters - mtn->executeCommand(cmd, cmdNum, false); - - if (mtn->getReturnCode(cmdNum) > 0) + if (!attrModel->setAttribute(dlg.getKey(), dlg.getValue())) { - C(QString("Couldn't set attribute")); - return; + C(QString("Couldn't set/update attribute")); } - - attrModel->readAttributes(attrModel->currentPath()); } } @@ -190,23 +162,10 @@ void AttributesView::dropAttribute() { GetAttributes * attrModel = qobject_cast(model()); QModelIndex keyIdx = attrModel->index(selectedIndex.row(), 1, QModelIndex()); - - QStringList cmd; - cmd << "drop_attribute"; - cmd << attrModel->currentPath(); - cmd << model()->data(keyIdx, Qt::UserRole).toString(); // the key - Monotone * mtn = MTN(this); - int cmdNum = 0; - // do not skip empty parameters - mtn->executeCommand(cmd, cmdNum, false); - - if (mtn->getReturnCode(cmdNum) > 0) + if (!attrModel->dropAttribute(model()->data(keyIdx, Qt::UserRole).toString())) { C(QString("Couldn't drop attribute")); - return; } - - attrModel->readAttributes(attrModel->currentPath()); }