30 #include <QJsonDocument> 31 #include <QJsonObject> 50 QMetaObject::Connection connection = connect(
m_watcher,
54 zCritical() <<
"Data file object watcher connection failed.";
61 "ZTableFile - Programming error: object not initialized");
66 bool ZTableFile::open(
int openMode)
69 ZBLQ_INVOKABLE_SLOT_BEGIN_TRY
71 retValue = m_f->open(QFile::OpenMode(openMode));
83 bool pathChanged =
false;
87 zWarning() <<
"Can't read data file for empty path.";
103 zDebug() <<
"Writing data file: " << filePath;
113 bool ok = in.open(QIODevice::ReadOnly | QIODevice::Text);
118 zWarning() <<
"File error status: " << in.errorString();
126 if(in.error() == QFile::NoError)
133 zWarning() <<
"File error status: " << in.errorString();
141 QJsonParseError error;
143 QJsonDocument doc = QJsonDocument::fromJson(ba, &error);
145 if(error.error != QJsonParseError::NoError)
148 zWarning() <<
"JSON error status: " << error.errorString();
174 QString previousFilePath;
176 if(!filePath.isEmpty())
188 bool ok = sf.open(QIODevice::WriteOnly | QIODevice::Text);
192 zWarning() <<
"Can't open data file for writing: " 199 QJsonDocument jd(jo);
201 QByteArray ba = jd.toBinaryData();
203 qint64 bytesOut = sf.write(ba);
219 if(!previousFilePath.isEmpty())
Q_INVOKABLE bool writeFile(const QString &filePath)
Writes the data table to the specified file. Returns true if successful; otherwise returns false...
Q_INVOKABLE bool open(int openMode)
Opens the device and sets its open mode to openMode. Returns true if successful; otherwise returns fa...
Q_INVOKABLE QJsonObject getJsonData() const
Copies data from the table model into a newly created JSON object and returns it. ...
QFileSystemWatcher * m_watcher
Monitors table data file for updates from this and other applications.
#define ZBL_REGISTER_LOGGED_OBJECT
ZTableFile(QObject *parent=0)
Q_INVOKABLE bool readFile(const QString &filePath)
Reads the specified table file into the data table. Previous data in the table is discarded...
ZBL_DECLARE_LOGGED_OBJECT void validateWatcher()
ZTableModel * m_data
The data model that will send or receive data.
static qint64 m_maxFileBytes
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
This two dimensional table model is used to store and manipulate data.
void fileModified(const QString &path)
Sent whenever the data file is modified by this or other programs.
Q_INVOKABLE void clearRoles()
Removes all roles, role names and data from the model.
Q_INVOKABLE void putJsonData(QJsonObject data)
Writes data from the specified JSON object into the data table. Previous contents of the data table a...
QString m_filePath
Path to the file that was last read or written.
This class in theory allows reading and writing of ZTableModel objects to JSON files. (TBD: currently unused/untested?)
Zuble's Qt Exception Object.
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)