mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-28 11:36:26 -05:00
Port changes from Custom Attributes redesign
This commit is contained in:
34
include/ui/customattributesdialog.h
Normal file
34
include/ui/customattributesdialog.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef CUSTOMATTRIBUTESDIALOG_H
|
||||
#define CUSTOMATTRIBUTESDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QAbstractButton>
|
||||
|
||||
#include "customattributestable.h"
|
||||
|
||||
namespace Ui {
|
||||
class CustomAttributesDialog;
|
||||
}
|
||||
|
||||
class CustomAttributesDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CustomAttributesDialog(CustomAttributesTable *table);
|
||||
~CustomAttributesDialog();
|
||||
|
||||
private:
|
||||
Ui::CustomAttributesDialog *ui;
|
||||
CustomAttributesTable *const m_table;
|
||||
|
||||
void setInputType(int inputType);
|
||||
void onNameChanged(const QString &);
|
||||
bool validateName(bool allowEmpty = false);
|
||||
void clickedButton(QAbstractButton *button);
|
||||
void addNewAttribute();
|
||||
QVariant getValue() const;
|
||||
};
|
||||
|
||||
|
||||
#endif // CUSTOMATTRIBUTESDIALOG_H
|
||||
36
include/ui/customattributesframe.h
Normal file
36
include/ui/customattributesframe.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef CUSTOMATTRIBUTESFRAME_H
|
||||
#define CUSTOMATTRIBUTESFRAME_H
|
||||
|
||||
/*
|
||||
The frame containing the Custom Attributes table and its Add/Delete buttons.
|
||||
Shared by the map's Header tab and Events.
|
||||
*/
|
||||
|
||||
#include "customattributestable.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QFrame>
|
||||
|
||||
namespace Ui {
|
||||
class CustomAttributesFrame;
|
||||
}
|
||||
|
||||
class CustomAttributesFrame : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CustomAttributesFrame(QWidget *parent = nullptr);
|
||||
~CustomAttributesFrame();
|
||||
|
||||
CustomAttributesTable* table() const;
|
||||
|
||||
private:
|
||||
Ui::CustomAttributesFrame *ui;
|
||||
|
||||
void addAttribute();
|
||||
void deleteAttribute();
|
||||
void updateDeleteButton();
|
||||
};
|
||||
|
||||
#endif // CUSTOMATTRIBUTESFRAME_H
|
||||
@@ -1,25 +1,44 @@
|
||||
#ifndef CUSTOMATTRIBUTESTABLE_H
|
||||
#define CUSTOMATTRIBUTESTABLE_H
|
||||
|
||||
#include "events.h"
|
||||
#include <QObject>
|
||||
#include <QFrame>
|
||||
#include <QJsonValue>
|
||||
#include <QTableWidget>
|
||||
|
||||
class CustomAttributesTable : public QFrame
|
||||
class CustomAttributesTable : public QTableWidget
|
||||
{
|
||||
public:
|
||||
explicit CustomAttributesTable(Event *event, QWidget *parent = nullptr);
|
||||
~CustomAttributesTable();
|
||||
Q_OBJECT
|
||||
|
||||
static const QMap<QString, QJsonValue> getAttributes(QTableWidget * table);
|
||||
static QJsonValue pickType(QWidget * parent, bool * ok = nullptr);
|
||||
static void addAttribute(QTableWidget * table, QString key, QJsonValue value, bool isNew = false);
|
||||
static bool deleteSelectedAttributes(QTableWidget * table);
|
||||
public:
|
||||
explicit CustomAttributesTable(QWidget *parent = nullptr);
|
||||
~CustomAttributesTable() {};
|
||||
|
||||
QMap<QString, QJsonValue> getAttributes() const;
|
||||
void setAttributes(const QMap<QString, QJsonValue> &attributes);
|
||||
|
||||
void addNewAttribute(const QString &key, const QJsonValue &value);
|
||||
bool deleteSelectedAttributes();
|
||||
|
||||
bool isEmpty() const;
|
||||
bool isSelectionEmpty() const;
|
||||
|
||||
QSet<QString> keys() const { return m_keys; }
|
||||
QSet<QString> restrictedKeys() const { return m_restrictedKeys; }
|
||||
void setRestrictedKeys(const QSet<QString> &keys) { m_restrictedKeys = keys; }
|
||||
|
||||
signals:
|
||||
void edited();
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private:
|
||||
Event *event;
|
||||
QTableWidget *table;
|
||||
QSet<QString> m_keys; // All keys currently in the table
|
||||
QSet<QString> m_restrictedKeys; // All keys not allowed in the table
|
||||
|
||||
QPair<QString, QJsonValue> getAttribute(int row) const;
|
||||
int addAttribute(const QString &key, const QJsonValue &value);
|
||||
void removeAttribute(const QString &key);
|
||||
void resizeVertically();
|
||||
};
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ public:
|
||||
QFrame *frame_contents;
|
||||
QVBoxLayout *layout_contents;
|
||||
|
||||
CustomAttributesFrame *custom_attributes;
|
||||
|
||||
protected:
|
||||
bool populated = false;
|
||||
bool initialized = false;
|
||||
|
||||
Reference in New Issue
Block a user