* [Companion] Refactor MdiChild & TreeModel, restore drag/drop, and more:
* Add full drag-and-drop functions to the models list, including model copy, move, and insert actions (also between windows);
* Add general radio settings copy/paste across file windows;
* Full MIME support with distinct types for various data (eg. models vs. general settings), also add new type for metadata (header);
* Copied/cut models can now be inserted in any spot (similar to drop-insert);
* Deleted/cut models can now be removed entirely (including the empty slot) for all radio types (any models after the removed one move up, like for Horus) (may need to make this an option);
* Empty model slots can now also be removed (any models after the removed slot move up) (but total # of slots is still maintained);
* Default model can be deleted (new default is picked);
* Completely revamp the actions system (copy/paste/edit/etc) to make it fully functional:
* Actions exist in the window, not just context menu, therefore all keyboard shortcuts actually work, w/out any duplicated code;
* Provides access from MainWindow in a comprehensive manner: all actions are available and properly updated based on selections in current editor window, w/out awkward event monitoring;
* More actions available from context menu, and somewhat reorganized;
* Also show all actions on mini toolbars right in the MDI window (possibly make optional later);
* Updated English localization file to account for plurals usage in new action item names (other languages need to be updated);
* Keyboard navigation in the model list now works/practical;
* MDI window uses all available height by default;
* Newly added models/categories are selected and highlighted; Category names are immediately editable; Model editor is/can be launched if wizard is not (need to make option);
* MainWindow updates:
* Edit toolbar and menu now showing all available edit actions, with proper context;
* File menu properly updates with all "general" radio actions: edit/copy/paste settings and simulate radio;
* Added Windows menu showing list of open windows (eg. to switch when full screen) and tabbed window option (need to make persistent setting);
* Immediate update of icon size preference;
* Do not delete toolbars when re-translating UI (they don't lose assigned position);
* [Companion] Restore model compare functionality by using new MIME data exchange system; Add ability to compare any number of models at a time; Multi-model printer now shows custom hardware settings for each dropped model (even from different radios).
* [Companion] Add missing monoblue & monowhite theme sdsync icons.
* [Companion] Model wizard starts with default model name populated.
* [Companion] Properly re-translate UI instead of recreating all the actions/etc.; Tell Mac specifically where to put our actions (seems to make it happier too).
* [Companion] Further improve handling of Window menu items/detection of sub-window changes.
* [Companion] Add file-close action.
* [Companion] Add user options and save preferences:
* Option to use wizard, open editor, or do nothing on new model creation;
* Option to remove empty model slots when deleting/moving models (in non-Horus radios);
* Options to hide toolbars in document windows (r-click on TBs);
* Save/restore size of document windows, and maximized/tabbed state;
* Save/restore size/position of model compare window;
* Add shortcuts for model compare, FW download, log viewer;
* [Companion] Disable being able to "delete" empty model slots (more awkward than helpful).
157 lines
6.3 KiB
C++
157 lines
6.3 KiB
C++
/*
|
|
* Copyright (C) OpenTX
|
|
*
|
|
* Based on code named
|
|
* th9x - http://code.google.com/p/th9x
|
|
* er9x - http://code.google.com/p/er9x
|
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
|
*
|
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#ifndef _MODELSLIST_H_
|
|
#define _MODELSLIST_H_
|
|
|
|
#include "eeprominterface.h"
|
|
#include <QAbstractItemModel>
|
|
#include <QMimeData>
|
|
#include <QUuid>
|
|
|
|
class TreeItem
|
|
{
|
|
public:
|
|
enum TreeItemFlags { MarkedForCut = 0x01 };
|
|
|
|
explicit TreeItem(const QVector<QVariant> & itemData);
|
|
explicit TreeItem(TreeItem * parent, int categoryIndex, int modelIndex);
|
|
~TreeItem();
|
|
|
|
TreeItem * child(int number);
|
|
int childCount() const;
|
|
int columnCount() const;
|
|
QVariant data(int column) const;
|
|
TreeItem * appendChild(int categoryIndex, int modelIndex);
|
|
TreeItem * insertChild(const int row, int categoryIndex, int modelIndex);
|
|
bool removeChildren(int position, int count);
|
|
bool insertChildren(int row, int count);
|
|
|
|
int childNumber() const;
|
|
bool setData(int column, const QVariant &value);
|
|
|
|
TreeItem * parent() { return parentItem; }
|
|
void setParent(TreeItem * p) { parentItem = p; }
|
|
int getModelIndex() const { return modelIndex; }
|
|
void setModelIndex(int value) { modelIndex = value; }
|
|
int getCategoryIndex() const { return categoryIndex; }
|
|
void setCategoryIndex(int value) { categoryIndex = value; }
|
|
|
|
quint16 getFlags() const { return flags; }
|
|
void setFlags(const quint16 & value) { flags = value; }
|
|
void setFlag(const quint16 & flag, const bool on = true);
|
|
|
|
bool isCategory() const;
|
|
bool isModel() const;
|
|
|
|
private:
|
|
QList<TreeItem*> childItems;
|
|
QVector<QVariant> itemData;
|
|
TreeItem * parentItem;
|
|
int categoryIndex;
|
|
int modelIndex;
|
|
quint16 flags;
|
|
};
|
|
|
|
|
|
class TreeModel : public QAbstractItemModel
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
struct MimeHeaderData {
|
|
QUuid instanceId;
|
|
quint16 dataVersion;
|
|
};
|
|
|
|
TreeModel(RadioData * radioData, QObject *parent = 0);
|
|
virtual ~TreeModel();
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
|
|
|
|
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
virtual QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
|
|
|
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
virtual bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
|
|
//virtual bool insertRows(int row, int count, const QModelIndex & parent) Q_DECL_OVERRIDE;
|
|
|
|
virtual QStringList mimeTypes() const Q_DECL_OVERRIDE;
|
|
virtual Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
|
|
virtual Qt::DropActions supportedDragActions() const Q_DECL_OVERRIDE;
|
|
virtual QMimeData * mimeData(const QModelIndexList & indexes) const Q_DECL_OVERRIDE;
|
|
virtual bool canDropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) const Q_DECL_OVERRIDE;
|
|
virtual bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) Q_DECL_OVERRIDE;
|
|
|
|
void encodeModelsData(const QModelIndexList & indexes, QByteArray * data) const;
|
|
void encodeGeneralData(QByteArray * data) const;
|
|
void encodeHeaderData(QByteArray * data) const;
|
|
QMimeData * getModelsMimeData(const QModelIndexList & indexes, QMimeData * mimeData = NULL) const;
|
|
QMimeData * getGeneralMimeData(QMimeData * mimeData = NULL) const;
|
|
QMimeData * getHeaderMimeData(QMimeData * mimeData = NULL) const;
|
|
QUuid getMimeDataSourceId(const QMimeData * mimeData) const;
|
|
bool hasSupportedMimeData(const QMimeData * mimeData) const;
|
|
bool hasModelsMimeData(const QMimeData * mimeData) const;
|
|
bool hasGenralMimeData(const QMimeData * mimeData) const;
|
|
bool hasHeaderMimeData(const QMimeData * mimeData) const;
|
|
bool hasOwnMimeData(const QMimeData * mimeData) const;
|
|
|
|
static bool decodeHeaderData(const QMimeData * mimeData, MimeHeaderData * header);
|
|
static bool decodeMimeData(const QMimeData * mimeData, QVector<ModelData> * models = NULL, GeneralSettings * gs = NULL, bool * hasGenSet = NULL);
|
|
static int countModelsInMimeData(const QMimeData * mimeData);
|
|
|
|
QModelIndex getIndexForModel(const int modelIndex, QModelIndex parent = QModelIndex());
|
|
QModelIndex getIndexForCategory(const int categoryIndex);
|
|
int getAvailableEEpromSize();
|
|
int getModelIndex(const QModelIndex & index) const;
|
|
int getCategoryIndex(const QModelIndex & index) const;
|
|
int rowNumber(const QModelIndex & index = QModelIndex()) const;
|
|
bool isCategoryType(const QModelIndex & index) const;
|
|
bool isModelType(const QModelIndex & index) const;
|
|
|
|
public slots:
|
|
void markItemForCut(const QModelIndex & index, bool on = true);
|
|
void markItemsForCut(const QModelIndexList & indexes, bool on = true);
|
|
void refresh();
|
|
|
|
signals:
|
|
void modelsDropped(const QMimeData * mimeData, const QModelIndex toRowIdx, const bool insert, const bool move);
|
|
void modelsRemoved(const QVector<int> modelIndices);
|
|
void refreshRequested();
|
|
|
|
private slots:
|
|
//void onRowsAboutToBeRemoved(const QModelIndex & parent, int first, int last);
|
|
void onRowsRemoved(const QModelIndex & parent, int first, int last);
|
|
|
|
private:
|
|
TreeItem * getItem(const QModelIndex & index) const;
|
|
|
|
TreeItem * rootItem;
|
|
RadioData * radioData;
|
|
int availableEEpromSize;
|
|
MimeHeaderData mimeHeaderData;
|
|
};
|
|
|
|
#endif // _MODELSLIST_H_
|