ProjectExplorer: Use FilePath in JsonWizard

Also remove m_currentPath and logic around it, as it was unused.

Change-Id: Id32ae2845e3788a3e24bb238005b31e8f174f6b9
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-09-27 17:13:31 +02:00
parent a73338e188
commit 98fad961a6
2 changed files with 14 additions and 22 deletions

View File

@@ -62,6 +62,8 @@
using namespace Utils; using namespace Utils;
namespace ProjectExplorer {
const char NAME_KEY[] = "name"; const char NAME_KEY[] = "name";
const char DISPLAY_NAME_KEY[] = "trDisplayName"; const char DISPLAY_NAME_KEY[] = "trDisplayName";
const char TOOLTIP_KEY[] = "trToolTip"; const char TOOLTIP_KEY[] = "trToolTip";
@@ -75,8 +77,7 @@ const char DATA_KEY[] = "data";
const char IS_COMPLETE_KEY[] = "isComplete"; const char IS_COMPLETE_KEY[] = "isComplete";
const char IS_COMPLETE_MESSAGE_KEY[] = "trIncompleteMessage"; const char IS_COMPLETE_MESSAGE_KEY[] = "trIncompleteMessage";
namespace { static QVariant consumeValue(QVariantMap &map, const QString &key, const QVariant &defaultValue = {})
QVariant consumeValue(QVariantMap &map, const QString &key, const QVariant &defaultValue = QVariant())
{ {
QVariantMap::iterator i = map.find(key); QVariantMap::iterator i = map.find(key);
if (i != map.end()) { if (i != map.end()) {
@@ -87,7 +88,7 @@ QVariant consumeValue(QVariantMap &map, const QString &key, const QVariant &defa
return defaultValue; return defaultValue;
} }
void warnAboutUnsupportedKeys(const QVariantMap &map, const QString &name, const QString &type = QString()) static void warnAboutUnsupportedKeys(const QVariantMap &map, const QString &name, const QString &type = {})
{ {
if (!map.isEmpty()) { if (!map.isEmpty()) {
@@ -98,9 +99,7 @@ void warnAboutUnsupportedKeys(const QVariantMap &map, const QString &name, const
qWarning().noquote() << QString("Field %1 has unsupported keys: %2").arg(typeAndName, map.keys().join(", ")); qWarning().noquote() << QString("Field %1 has unsupported keys: %2").arg(typeAndName, map.keys().join(", "));
} }
} }
} // namespace
namespace ProjectExplorer {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Helper: // Helper:
@@ -811,8 +810,8 @@ bool PathChooserField::parseData(const QVariant &data, QString *errorMessage)
QVariantMap tmp = data.toMap(); QVariantMap tmp = data.toMap();
m_path = consumeValue(tmp, "path").toString(); m_path = FilePath::fromVariant(consumeValue(tmp, "path"));
m_basePath = consumeValue(tmp, "basePath").toString(); m_basePath = FilePath::fromVariant(consumeValue(tmp, "basePath"));
m_historyId = consumeValue(tmp, "historyId").toString(); m_historyId = consumeValue(tmp, "historyId").toString();
QString kindStr = consumeValue(tmp, "kind", "existingDirectory").toString(); QString kindStr = consumeValue(tmp, "kind", "existingDirectory").toString();
@@ -851,7 +850,7 @@ QWidget *PathChooserField::createWidget(const QString &displayName, JsonFieldPag
if (!m_historyId.isEmpty()) if (!m_historyId.isEmpty())
w->setHistoryCompleter(m_historyId); w->setHistoryCompleter(m_historyId);
QObject::connect(w, &PathChooser::pathChanged, [this, w] { QObject::connect(w, &PathChooser::pathChanged, [this, w] {
if (w->filePath().toString() != m_path) if (w->filePath() != m_path)
setHasUserChanges(); setHasUserChanges();
}); });
return w; return w;
@@ -887,23 +886,19 @@ void PathChooserField::initializeData(MacroExpander *expander)
{ {
auto w = qobject_cast<PathChooser *>(widget()); auto w = qobject_cast<PathChooser *>(widget());
QTC_ASSERT(w, return); QTC_ASSERT(w, return);
w->setBaseDirectory(expander->expand(FilePath::fromString(m_basePath))); w->setBaseDirectory(expander->expand(m_basePath));
w->setExpectedKind(m_kind); w->setExpectedKind(m_kind);
w->setFilePath(expander->expand(m_path));
if (m_currentPath.isNull())
w->setPath(expander->expand(m_path));
else
w->setPath(m_currentPath);
} }
void PathChooserField::fromSettings(const QVariant &value) void PathChooserField::fromSettings(const QVariant &value)
{ {
m_path = value.toString(); m_path = FilePath::fromVariant(value);
} }
QVariant PathChooserField::toSettings() const QVariant PathChooserField::toSettings() const
{ {
return qobject_cast<PathChooser *>(widget())->filePath().toString(); return qobject_cast<PathChooser *>(widget())->filePath().toVariant();
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@@ -216,21 +216,18 @@ private:
{ {
QString result; QString result;
QTextStream out(&result); QTextStream out(&result);
out << "PathChooser{path:" << m_path out << "PathChooser{path:" << m_path.toString()
<< "; base:" << m_basePath << "; base:" << m_basePath
<< "; historyId:" << m_historyId << "; historyId:" << m_historyId
<< "; kind:" << (int)Utils::PathChooser::ExistingDirectory << "; kind:" << (int)Utils::PathChooser::ExistingDirectory
<< "; currentPath:" << m_currentPath
<< "}"; << "}";
return result; return result;
} }
QString m_path; Utils::FilePath m_path;
QString m_basePath; Utils::FilePath m_basePath;
QString m_historyId; QString m_historyId;
Utils::PathChooser::Kind m_kind = Utils::PathChooser::ExistingDirectory; Utils::PathChooser::Kind m_kind = Utils::PathChooser::ExistingDirectory;
QString m_currentPath;
}; };
class CheckBoxField : public JsonFieldPage::Field class CheckBoxField : public JsonFieldPage::Field