# # # patch "src/model/GetAttributes.cpp" # from [3b5ed025eced153309ced638207ef104029a1686] # to [f270dea5c62bba8010b641fc5e2868d4d3db412f] # # patch "src/model/GetAttributes.h" # from [b2b0c44c14875c6f49a32a4e5ca57fe7ae71f4e3] # to [5a6dd679c9422d351eb257d1112b92c66af8ad8f] # # patch "src/view/AttributesView.cpp" # from [0754902971fb811ba3471482eb6557e99676c4f8] # to [1a9ca66bb8fcee26e941b962d4f3d9efe975b417] # # patch "src/view/AttributesView.h" # from [0a971e63c438c084631cb3190355a65967fbbb31] # to [a597ffe195bc7ac5bf32eb627f3c8c9262f3ab84] # ============================================================ --- src/model/GetAttributes.cpp 3b5ed025eced153309ced638207ef104029a1686 +++ src/model/GetAttributes.cpp f270dea5c62bba8010b641fc5e2868d4d3db412f @@ -28,19 +28,13 @@ GetAttributes::GetAttributes(QObject * p GetAttributes::GetAttributes(QObject * parent) : QAbstractItemModel(parent), AutomateCommand(0), workspacePath(), itemPath() -{ - attributes = new AttributeList(); -} +{} -GetAttributes::~GetAttributes() -{ - attributes->clear(); - delete attributes; -} +GetAttributes::~GetAttributes() {} void GetAttributes::revert() { - attributes->clear(); + attributes.clear(); itemPath = QString(); reset(); } @@ -54,7 +48,7 @@ void GetAttributes::readAttributes(const I(!workspacePath.isEmpty()); // clear current attributes list - attributes->clear(); + attributes.clear(); // reset the view reset(); @@ -140,7 +134,7 @@ void GetAttributes::processTaskResult(co // check if we really processed an item entry if (!isItem) continue; - attributes->append(attr); + attributes.append(attr); } // reset the view @@ -164,9 +158,9 @@ QVariant GetAttributes::data(const QMode } int row = index.row(), col = index.column(); - if (row >= attributes->size()) return QVariant(); + if (row >= attributes.size()) return QVariant(); - Attribute attr = attributes->at(row); + Attribute attr = attributes.at(row); if (role == Qt::DisplayRole) { @@ -260,7 +254,7 @@ int GetAttributes::rowCount(const QModel int GetAttributes::rowCount(const QModelIndex & parent) const { Q_UNUSED(parent); - return attributes->size(); + return attributes.size(); } QModelIndex GetAttributes::index(int row, int column, const QModelIndex & parent) const @@ -292,3 +286,24 @@ bool GetAttributes::dropAttribute(const return out.getReturnCode() == 0; } +bool GetAttributes::dropAllAttributes() +{ + MonotoneTask out = MonotoneUtil::runSynchronousWorkspaceTask( + workspacePath, + MonotoneTask(QStringList() << "drop_attribute" << itemPath) + ); + return out.getReturnCode() == 0; +} + +bool GetAttributes::hasDroppableAttributes() const +{ + foreach(Attribute attr, attributes) + { + if (attr.state != Attribute::Dropped) + { + return true; + } + } + return false; +} + ============================================================ --- src/model/GetAttributes.h b2b0c44c14875c6f49a32a4e5ca57fe7ae71f4e3 +++ src/model/GetAttributes.h 5a6dd679c9422d351eb257d1112b92c66af8ad8f @@ -25,17 +25,16 @@ #include -typedef struct { - enum AttributeState { Added, Dropped, Changed, Unchanged } state; - QString key; - QString value; -} Attribute; -typedef QList AttributeList; - class GetAttributes : public QAbstractItemModel, public AutomateCommand { Q_OBJECT public: + struct Attribute { + enum AttributeState { Added, Dropped, Changed, Unchanged } state; + QString key; + QString value; + }; + GetAttributes(QObject *); virtual ~GetAttributes(); @@ -50,6 +49,9 @@ public: bool setAttribute(const QString &, const QString &); bool dropAttribute(const QString &); + bool dropAllAttributes(); + bool hasDroppableAttributes() const; + inline bool attributesLoaded() const { return !itemPath.isEmpty(); } public slots: @@ -62,7 +64,7 @@ private: private: void processTaskResult(const MonotoneTask &); - AttributeList * attributes; + QList attributes; WorkspacePath workspacePath; QString itemPath; }; ============================================================ --- src/view/AttributesView.cpp 0754902971fb811ba3471482eb6557e99676c4f8 +++ src/view/AttributesView.cpp 1a9ca66bb8fcee26e941b962d4f3d9efe975b417 @@ -92,6 +92,12 @@ void AttributesView::sectionClicked(int popupMenu.addAction( tr("add new attribute"), this, SLOT(addAttribute()) ); + if (attrModel->hasDroppableAttributes()) + { + popupMenu.addAction( + tr("drop all attributes"), this, SLOT(dropAllAttributes()) + ); + } popupMenu.exec(mapToGlobal(QPoint(left, top))); } @@ -174,3 +180,13 @@ void AttributesView::dropAttribute() attrModel->readAttributes(); } +void AttributesView::dropAllAttributes() +{ + GetAttributes * attrModel = qobject_cast(model()); + if (!attrModel->dropAllAttributes()) + { + C(QString("Couldn't drop attributes")); + } + attrModel->readAttributes(); +} + ============================================================ --- src/view/AttributesView.h 0a971e63c438c084631cb3190355a65967fbbb31 +++ src/view/AttributesView.h a597ffe195bc7ac5bf32eb627f3c8c9262f3ab84 @@ -40,6 +40,7 @@ private slots: void editAttribute(); void aboutToEditAttribute(const QModelIndex &); void dropAttribute(); + void dropAllAttributes(); private: QModelIndex selectedIndex;