Skip to content

Commit

Permalink
Merge pull request #281 from Krakonos/changeset-source
Browse files Browse the repository at this point in the history
Implemented a source field in the upload dialog.
  • Loading branch information
Krakonos committed Sep 18, 2023
2 parents 46b3fa1 + f519888 commit adfc1bf
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 41 deletions.
5 changes: 3 additions & 2 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4289,9 +4289,10 @@ void MainWindow::syncOSM(const QString& aWeb, const QString& aUser, const QStrin
DirtyListBuild Future;
theDocument->history().buildDirtyList(Future);
DirtyListDescriber Describer(theDocument,Future);
if (Describer.showChanges(this) && Describer.tasks()) {
ChangesetInfo changesetInfo = {aWeb, "", ""};
if (Describer.showChanges(this, changesetInfo) && Describer.tasks()) {
Future.resetUpdates();
DirtyListExecutorOSC Exec(theDocument,Future,aWeb,aUser,aPwd,Describer.tasks());
DirtyListExecutorOSC Exec(theDocument,Future,changesetInfo,aWeb,aUser,aPwd,Describer.tasks());
if (Exec.executeChanges(this)) {
if (M_PREFS->getAutoHistoryCleanup() && !theDocument->getDirtyOrOriginLayer()->getDirtySize())
theDocument->history().cleanup();
Expand Down
2 changes: 1 addition & 1 deletion src/Preferences/MerkaartorPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ M_PARAM_IMPLEMENT_INT_DELAYED(TagListFirstColumnWidth, visual, 20)
M_PARAM_IMPLEMENT_BOOL(TranslateTags, locale, true)

/* Background */
M_PARAM_IMPLEMENT_BOOL(AutoSourceTag, backgroundImage, true)
M_PARAM_IMPLEMENT_BOOL(AutoSourceTag, backgroundImage, false)

/* Data */
M_PARAM_IMPLEMENT_STRING(MapdustUrl, data, "http://www.mapdust.com/feed?lang=en&ft=wrong_turn,bad_routing,oneway_road,blocked_street,missing_street,wrong_roundabout,missing_speedlimit,other&fd=1&minR=&maxR=")
Expand Down
11 changes: 5 additions & 6 deletions src/Sync/DirtyList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ int glbNodesAdded, glbNodesUpdated, glbNodesDeleted;
int glbWaysAdded, glbWaysUpdated, glbWaysDeleted;
int glbRelationsAdded, glbRelationsUpdated, glbRelationsDeleted;

QString glbChangeSetComment;

QString stripToOSMId(const IFeature::FId& id)
{
return QString::number(id.numId);
Expand Down Expand Up @@ -293,7 +291,7 @@ int DirtyListDescriber::tasks() const
return Task;
}

bool DirtyListDescriber::showChanges(QWidget* aParent)
bool DirtyListDescriber::showChanges(QWidget* aParent, ChangesetInfo& changesetInfo)
{
QDialog* dlg = new QDialog(aParent);
Ui.setupUi(dlg);
Expand All @@ -314,16 +312,17 @@ bool DirtyListDescriber::showChanges(QWidget* aParent)
Ui.lblAdded->setText(QString::number(glbAdded));
Ui.lblUpdated->setText(QString::number(glbUpdated));
Ui.lblDeleted->setText(QString::number(glbDeleted));
Ui.lblServerUrl->setText(changesetInfo.serverUrl);

//Ui.edChangesetComment->setText(glbChangeSetComment);
//Ui.edChangesetComment->selectAll();
Ui.edSources->setText(theDocument->getCurrentSourceTags().join(";"));

bool ok = false;
while (!ok) {
if (dlg->exec() == QDialog::Accepted) {
/* Dialog was accepted, check for non-empty comment */
if (!Ui.edChangesetComment->text().isEmpty()) {
glbChangeSetComment = Ui.edChangesetComment->text();
changesetInfo.comment = Ui.edChangesetComment->text();
changesetInfo.source = Ui.edSources->text();
ok = true;
} else if (QMessageBox::question(NULL,
QApplication::tr("Use empty changeset comment?"),
Expand Down
21 changes: 20 additions & 1 deletion src/Sync/DirtyList.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class QWidget;
#include <utility>
#include <QList>

/** Changeset information container class. */
class ChangesetInfo {
public:
QString serverUrl;
QString comment;
QString source;
};

class DirtyList
{
public:
Expand Down Expand Up @@ -107,7 +115,18 @@ class DirtyListDescriber : public DirtyListVisit
virtual bool eraseRoad(Way* R);
virtual bool eraseRelation(Relation* R);

bool showChanges(QWidget* Parent);
/**
* Display changeset upload dialog. If approved by user, returns true
* and info will be filled-in with dialog data. Returns false
* otherwise.
*
* @param Parent Qt parent window
* @param info Changeset info filled with `comment` and `source`
* in by the user (left as is if cancelled).
*
* @return true if changes approved by user
*/
bool showChanges(QWidget* Parent, ChangesetInfo& info);
int tasks() const;

private:
Expand Down
39 changes: 28 additions & 11 deletions src/Sync/DirtyListExecutorOSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <QRegExp>

extern int glbAdded, glbUpdated, glbDeleted;
extern QString glbChangeSetComment;

DirtyListExecutorOSC::DirtyListExecutorOSC(Document* aDoc, const DirtyListBuild& aFuture)
: DirtyListVisit(aDoc, aFuture, false)
Expand All @@ -35,8 +34,8 @@ DirtyListExecutorOSC::DirtyListExecutorOSC(Document* aDoc, const DirtyListBuild&
{
}

DirtyListExecutorOSC::DirtyListExecutorOSC(Document* aDoc, const DirtyListBuild& aFuture, const QString& aWeb, const QString& aUser, const QString& aPwd, int aTasks)
: DirtyListVisit(aDoc, aFuture, false), Tasks(aTasks), Done(0), Web(aWeb), User(aUser), Pwd(aPwd), theDownloader(0)
DirtyListExecutorOSC::DirtyListExecutorOSC(Document* aDoc, const DirtyListBuild& aFuture, const ChangesetInfo& info, const QString& aWeb, const QString& aUser, const QString& aPwd, int aTasks)
: DirtyListVisit(aDoc, aFuture, false), changesetInfo(info), Tasks(aTasks), Done(0), Web(aWeb), User(aUser), Pwd(aPwd), theDownloader(0)
{
theDownloader = new Downloader(User, Pwd);
}
Expand Down Expand Up @@ -184,14 +183,32 @@ bool DirtyListExecutorOSC::start()
Progress->setLabelText(tr("OPEN changeset"));
QEventLoop L; L.processEvents(QEventLoop::ExcludeUserInputEvents);

QString DataIn(
"<osm>"
"<changeset>"
"<tag k=\"created_by\" v=\"Merkaartor %1 (%2)\"/>"
"<tag k=\"comment\" v=\"%3\"/>"
"</changeset>"
"</osm>");
DataIn = DataIn.arg(BuildMetadata::VERSION).arg(QLocale::system().name().split("_")[0]).arg(Utils::encodeAttributes(glbChangeSetComment));
QString DataIn;
{
QXmlStreamWriter stream(&DataIn);
stream.writeStartElement("osm");
stream.writeStartElement("changeset");
stream.writeStartElement("tag");
stream.writeAttribute("k", "created_by");
stream.writeAttribute("v",
QString("Merkaartor %1 (%2)").arg(BuildMetadata::VERSION).arg(QLocale::system().name().split("_")[0]));
stream.writeEndElement();
if (changesetInfo.comment.length()) {
stream.writeStartElement("tag");
stream.writeAttribute("k", "comment");
stream.writeAttribute("v", changesetInfo.comment);
stream.writeEndElement();
}
if (changesetInfo.source.length()) {
stream.writeStartElement("tag");
stream.writeAttribute("k", "source");
stream.writeAttribute("v", changesetInfo.source);
stream.writeEndElement();
}
stream.writeEndDocument();
}
qDebug() << DataIn;

QString DataOut;
QString URL = theDownloader->getURLToOpenChangeSet();
if (sendRequest("PUT",URL,DataIn, DataOut) != 200)
Expand Down
3 changes: 2 additions & 1 deletion src/Sync/DirtyListExecutorOSC.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DirtyListExecutorOSC : public QObject, public DirtyListVisit

public:
DirtyListExecutorOSC(Document* aDoc, const DirtyListBuild& aFuture);
DirtyListExecutorOSC(Document* aDoc, const DirtyListBuild& aFuture, const QString& aWeb, const QString& aUser, const QString& aPwd, int aTasks);
DirtyListExecutorOSC(Document* aDoc, const DirtyListBuild& aFuture, const ChangesetInfo& info, const QString& aWeb, const QString& aUser, const QString& aPwd, int aTasks);
virtual ~DirtyListExecutorOSC();

void OscCreate(Feature* F);
Expand Down Expand Up @@ -61,6 +61,7 @@ class DirtyListExecutorOSC : public QObject, public DirtyListVisit
Downloader* theDownloader;
QString ChangeSetId;
QString LastAction;
ChangesetInfo changesetInfo;
};


Expand Down
94 changes: 77 additions & 17 deletions src/Sync/SyncListDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,86 @@
<property name="spacing">
<number>4</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="horizontalSpacing">
<number>12</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="lblChangesetComment">
<property name="text">
<string>Comment</string>
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="QLineEdit" name="edChangesetComment"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>A good comment should concisely and adequately describe the edit.</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="edSources"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Sources</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Server URL</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="lblServerUrl">
<property name="text">
<string notr="true">....</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_11">
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Semicolon separated list of sources for these changes. See &lt;a href=&quot;https://wiki.openstreetmap.org/wiki/Key:source&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;source=*&lt;/span&gt;&lt;/a&gt; for possible values.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>A good comment should concisely and adequately describe the edit.</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
Expand Down Expand Up @@ -247,7 +298,16 @@
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down
5 changes: 3 additions & 2 deletions src/common/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,9 @@ QStringList Document::getCurrentSourceTags()
for (LayerIterator<ImageMapLayer*> ImgIt(this); !ImgIt.isEnd(); ++ImgIt) {
if (ImgIt.get()->isVisible()) {
QString s = ImgIt.get()->getMapAdapter()->getSourceTag();
if (!s.isEmpty())
theSrc << ImgIt.get()->getMapAdapter()->getSourceTag();
if ((!s.isEmpty()) && (!theSrc.contains(s))) {
theSrc << s;
}
}
}
return theSrc;
Expand Down

0 comments on commit adfc1bf

Please sign in to comment.