Skip to content

Commit

Permalink
Address branch review
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Dec 14, 2023
1 parent 8833d9f commit 07f0ace
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 58 deletions.
5 changes: 2 additions & 3 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<qresource prefix="/">
<file>themes/qfield/nodpi/ic_3x3_grid_white_24dp.svg</file>
<file>themes/qfield/nodpi/ic_digitizing_settings_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_undo_white_24dp.svg</file>
<file>themes/qfield/nodpi/ic_undo_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_redo_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_flash_auto_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_flash_on_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_flash_off_black_24dp.svg</file>
Expand Down Expand Up @@ -531,8 +532,6 @@
<file>themes/qfield/nodpi/ic_hide_green_48dp.svg</file>
<file>themes/qfield/nodpi/ic_chevron_down.svg</file>
<file>themes/qfield/nodpi/ic_chevron_up.svg</file>
<file>themes/qfield/nodpi/ic_undo.svg</file>
<file>themes/qfield/nodpi/ic_redo.svg</file>
<file>themes/qfield/nodpi/ic_arrow_left_white_24dp.svg</file>
<file>themes/qfield/nodpi/ic_opacity_black_24dp.svg</file>
<file>themes/qfield/nodpi/ic_common_angle_white_24dp.svg</file>
Expand Down
File renamed without changes
File renamed without changes
4 changes: 0 additions & 4 deletions images/themes/qfield/nodpi/ic_undo_white_24dp.svg

This file was deleted.

21 changes: 9 additions & 12 deletions src/core/featurehistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void FeatureHistory::onBeforeCommitChanges()
QMap<QgsFeatureId, QgsFeature> modifiedFeatures;
QgsFeature f;

// ? is it possible to use the iterator in a less ugly way? something like normal `for ( QgsFeature &f : it ) {}`
while ( featuresIt.nextFeature( f ) )
modifiedFeatures.insert( f.id(), f );

Expand All @@ -125,7 +124,7 @@ void FeatureHistory::onCommittedFeaturesAdded( const QString &localLayerId, cons
return;
}

qInfo() << "FeatureHistory::onCommittedFeaturesAdded: adding create committed features";
qDebug() << "FeatureHistory::onCommittedFeaturesAdded: adding create committed features";

FeatureModifications modifications = mTempHistoryStep.take( vl->id() );

Expand Down Expand Up @@ -203,8 +202,8 @@ void FeatureHistory::onTimerTimeout()
mTempHistoryStep.clear();
mRedoHistory.clear();

emit isUndoEnabledChanged();
emit isRedoEnabledChanged();
emit isUndoAvailableChanged();
emit isRedoAvailableChanged();
}

QMap<QString, FeatureHistory::FeatureModifications> FeatureHistory::reverseModifications( QMap<QString, FeatureModifications> &modificationsByLayerId )
Expand Down Expand Up @@ -320,8 +319,6 @@ bool FeatureHistory::applyModifications( QMap<QString, FeatureModifications> &mo
QgsMessageLog::logMessage( tr( "Failed to rollback undo featurue modifications in layer \"%1\"" ).arg( vl->name() ) );
}

// OGR error creating feature -4: failed to execute insert : UNIQUE constraint failed: area.fid

return false;
}
}
Expand All @@ -348,8 +345,8 @@ bool FeatureHistory::undo()

mRedoHistory.append( reversedModifications );

emit isUndoEnabledChanged();
emit isRedoEnabledChanged();
emit isUndoAvailableChanged();
emit isRedoAvailableChanged();

return true;
}
Expand All @@ -372,20 +369,20 @@ bool FeatureHistory::redo()

mUndoHistory.append( reversedModifications );

emit isUndoEnabledChanged();
emit isRedoEnabledChanged();
emit isUndoAvailableChanged();
emit isRedoAvailableChanged();

return true;
}


bool FeatureHistory::isUndoEnabled()
bool FeatureHistory::isUndoAvailable()
{
return !mUndoHistory.isEmpty();
}


bool FeatureHistory::isRedoEnabled()
bool FeatureHistory::isRedoAvailable()
{
return !mRedoHistory.isEmpty();
}
Expand Down
68 changes: 34 additions & 34 deletions src/core/featurehistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class FeatureHistory : public QObject
{
Q_OBJECT

Q_PROPERTY( bool isUndoEnabled READ isUndoEnabled NOTIFY isUndoEnabledChanged )
Q_PROPERTY( bool isRedoEnabled READ isRedoEnabled NOTIFY isRedoEnabledChanged )
Q_PROPERTY( bool isUndoAvailable READ isUndoAvailable NOTIFY isUndoAvailableChanged )
Q_PROPERTY( bool isRedoAvailable READ isRedoAvailable NOTIFY isRedoAvailableChanged )

public:
/**
Expand Down Expand Up @@ -48,8 +48,38 @@ class FeatureHistory : public QObject
//! Get the redo message to be show in the UI. NOTE should be called before calling \a redo.
Q_INVOKABLE const QString redoMessage();

bool isUndoEnabled();
bool isRedoEnabled();
bool isUndoAvailable();
bool isRedoAvailable();

signals:
void isUndoAvailableChanged();
void isRedoAvailableChanged();

private slots:
/**
* Monitors the current project for new layers.
*
* @param layers layers added
*/
void onLayersAdded( const QList<QgsMapLayer *> &layers );

//! The project file has been changed
void onHomePathChanged();

//! Called when features are added on the layer
void onCommittedFeaturesAdded( const QString &localLayerId, const QgsFeatureList &addedFeatures );

//! Called after features are committed for deletion.
void onCommittedFeaturesRemoved( const QString &layerId, const QgsFeatureIds &deletedFeatureIds );

//! Called before features are committed. Used to prepare the old state of the features and store it in \a mHistry.
void onBeforeCommitChanges();

//! Called after features are committed. Used because the added features do not have FID before they are committed.
void onAfterCommitChanges();

//! Timer's timeout slot. Used to collect multiple feature changes (calls of \a onBeforeCommitChanges and \a onAfterCommitChanges) into one undo step.
void onTimerTimeout();

private:
static const int sTimeoutMs = 50;
Expand Down Expand Up @@ -89,36 +119,6 @@ class FeatureHistory : public QObject

//! Layer ids being observed for changes. Should reset when the project is changed. Used to prevent double event listeners.
QSet<QString> mObservedLayerIds;

signals:
void isUndoEnabledChanged();
void isRedoEnabledChanged();

private slots:
/**
* Monitors the current project for new layers.
*
* @param layers layers added
*/
void onLayersAdded( const QList<QgsMapLayer *> &layers );

//! The project file has been changed
void onHomePathChanged();

//! Called when features are added on the layer
void onCommittedFeaturesAdded( const QString &localLayerId, const QgsFeatureList &addedFeatures );

//! Called after features are committed for deletion.
void onCommittedFeaturesRemoved( const QString &layerId, const QgsFeatureIds &deletedFeatureIds );

//! Called before features are committed. Used to prepare the old state of the features and store it in \a mHistry.
void onBeforeCommitChanges();

//! Called after features are committed. Used because the added features do not have FID before they are committed.
void onAfterCommitChanges();

//! Timer's timeout slot. Used to collect multiple feature changes (calls of \a onBeforeCommitChanges and \a onAfterCommitChanges) into one undo step.
void onTimerTimeout();
};

#endif // FEATUREHISTORY_H
1 change: 1 addition & 0 deletions src/qml/QFieldCloudPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ Popup {
: qsTr('Reset project')
enabled: cloudProjectsModel.layerObserver.deltaFileWrapper.count > 0 || cloudProjectsModel.layerObserver.deltaFileWrapper.hasError()
icon.source: Theme.getThemeVectorIcon('ic_undo_white_24dp')
icon.color: "white"

onClicked: {
if (!cloudProjectsModel.layerObserver.deltaFileWrapper.hasError()) {
Expand Down
11 changes: 6 additions & 5 deletions src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,6 @@ ApplicationWindow {
spacing: 4

QfToolButtonDrawer {
id: mainToolbarDrawer
name: "digitizingDrawer"
size: 48
round: true
Expand Down Expand Up @@ -2121,10 +2120,11 @@ ApplicationWindow {
bottomPadding: parent.topMargin

QfToolButton {
icon.source: Theme.getThemeVectorIcon( "ic_undo" )
icon.source: Theme.getThemeVectorIcon( "ic_undo_black_24dp" )
iconColor: Theme.mainTextColor
height: 48
width: 48
enabled: featureHistory.isUndoEnabled
enabled: featureHistory.isUndoAvailable
opacity: enabled ? 1 : 0.5

onClicked: {
Expand All @@ -2140,10 +2140,11 @@ ApplicationWindow {
}

QfToolButton {
icon.source: Theme.getThemeVectorIcon( "ic_redo" )
icon.source: Theme.getThemeVectorIcon( "ic_redo_black_24dp" )
iconColor: Theme.mainTextColor
height: 48
width: 48
enabled: featureHistory.isRedoEnabled
enabled: featureHistory.isRedoAvailable
opacity: enabled ? 1 : 0.5

onClicked: {
Expand Down

0 comments on commit 07f0ace

Please sign in to comment.