summaryrefslogtreecommitdiffstats
path: root/api/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2018-11-22 01:50:32 +0100
committerPetr Mrázek <peterix@gmail.com>2018-11-22 01:50:32 +0100
commitc214c13fb353ef68718e7bca6fd784037d262c91 (patch)
tree81dd20e7a685bb249762946b4df5c052555f7569 /api/logic
parentc4a472981f572bfcbd99a9ef74175ebfb3b7924b (diff)
downloadMultiMC-c214c13fb353ef68718e7bca6fd784037d262c91.tar
MultiMC-c214c13fb353ef68718e7bca6fd784037d262c91.tar.gz
MultiMC-c214c13fb353ef68718e7bca6fd784037d262c91.tar.lz
MultiMC-c214c13fb353ef68718e7bca6fd784037d262c91.tar.xz
MultiMC-c214c13fb353ef68718e7bca6fd784037d262c91.zip
GH-2101 POC for inline renaming
Diffstat (limited to 'api/logic')
-rw-r--r--api/logic/InstanceList.cpp23
-rw-r--r--api/logic/InstanceList.h10
2 files changed, 28 insertions, 5 deletions
diff --git a/api/logic/InstanceList.cpp b/api/logic/InstanceList.cpp
index ed4286e3..e568211b 100644
--- a/api/logic/InstanceList.cpp
+++ b/api/logic/InstanceList.cpp
@@ -95,6 +95,7 @@ QVariant InstanceList::data(const QModelIndex &index, int role) const
{
return pdata->id();
}
+ case Qt::EditRole:
case Qt::DisplayRole:
{
return pdata->name();
@@ -118,12 +119,32 @@ QVariant InstanceList::data(const QModelIndex &index, int role) const
return QVariant();
}
+bool InstanceList::setData(const QModelIndex& index, const QVariant& value, int role)
+{
+ if (!index.isValid())
+ {
+ return false;
+ }
+ if(role != Qt::EditRole)
+ {
+ return false;
+ }
+ BaseInstance *pdata = static_cast<BaseInstance *>(index.internalPointer());
+ auto newName = value.toString();
+ if(pdata->name() == newName)
+ {
+ return true;
+ }
+ pdata->setName(newName);
+ return true;
+}
+
Qt::ItemFlags InstanceList::flags(const QModelIndex &index) const
{
Qt::ItemFlags f;
if (index.isValid())
{
- f |= (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ f |= (Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
}
return f;
}
diff --git a/api/logic/InstanceList.h b/api/logic/InstanceList.h
index 5b966b33..5c172e47 100644
--- a/api/logic/InstanceList.h
+++ b/api/logic/InstanceList.h
@@ -58,10 +58,12 @@ public:
virtual ~InstanceList();
public:
- QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- QVariant data(const QModelIndex &index, int role) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
+ QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+ Qt::ItemFlags flags(const QModelIndex &index) const override;
+
+ bool setData(const QModelIndex & index, const QVariant & value, int role) override;
enum AdditionalRoles
{