Move limitdata array manipulation from ui to model
This commit is contained in:
@@ -1478,3 +1478,79 @@ bool ModelData::isThrTraceSrcAvailable(const GeneralSettings * generalSettings,
|
|||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelData::limitsClear(const int index)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= CPN_MAX_CHNOUT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!limitData[index].isEmpty()) {
|
||||||
|
limitData[index].clear();
|
||||||
|
updateAllReferences(REF_UPD_TYPE_CHANNEL, REF_UPD_ACT_CLEAR, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelData::limitsClearAll()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < CPN_MAX_CHNOUT; i++) {
|
||||||
|
limitsClear(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelData::limitsDelete(const int index)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= CPN_MAX_CHNOUT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
memmove(&limitData[index], &limitData[index + 1], (CPN_MAX_CHNOUT - (index + 1)) * sizeof(LimitData));
|
||||||
|
limitData[CPN_MAX_CHNOUT - 1].clear();
|
||||||
|
updateAllReferences(REF_UPD_TYPE_CHANNEL, REF_UPD_ACT_SHIFT, index, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelData::limitsGet(const int index, QByteArray & data)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= CPN_MAX_CHNOUT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
data.append((char*)&limitData[index], sizeof(LimitData));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelData::limitsInsert(const int index)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= CPN_MAX_CHNOUT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
memmove(&limitData[index + 1], &limitData[index], (CPN_MAX_CHNOUT - (index + 1)) * sizeof(LimitData));
|
||||||
|
limitData[index].clear();
|
||||||
|
updateAllReferences(REF_UPD_TYPE_CHANNEL, REF_UPD_ACT_SHIFT, index, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelData::limitsMove(const int index, const int offset)
|
||||||
|
{
|
||||||
|
if (index + offset < 0 || index + offset >= CPN_MAX_CHNOUT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int idx1 = index;
|
||||||
|
int idx2;
|
||||||
|
const int direction = offset < 0 ? -1 : 1;
|
||||||
|
const int cnt = abs(offset);
|
||||||
|
|
||||||
|
for (int i = 1; i <= cnt; i++) {
|
||||||
|
idx2 = idx1 + direction;
|
||||||
|
LimitData chntmp = limitData[idx2];
|
||||||
|
LimitData *chn1 = &limitData[idx1];
|
||||||
|
LimitData *chn2 = &limitData[idx2];
|
||||||
|
memcpy(chn2, chn1, sizeof(LimitData));
|
||||||
|
memcpy(chn1, &chntmp, sizeof(LimitData));
|
||||||
|
updateAllReferences(REF_UPD_TYPE_CHANNEL, REF_UPD_ACT_SWAP, idx1, idx2);
|
||||||
|
idx1 += direction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelData::limitsSet(const int index, const QByteArray & data)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= CPN_MAX_CHNOUT || data.size() < (int)sizeof(LimitData))
|
||||||
|
return;
|
||||||
|
|
||||||
|
memcpy(&limitData[index], data.constData(), sizeof(LimitData));
|
||||||
|
}
|
||||||
|
|||||||
@@ -294,6 +294,14 @@ class ModelData {
|
|||||||
int thrTraceSrcCount() const;
|
int thrTraceSrcCount() const;
|
||||||
bool isThrTraceSrcAvailable(const GeneralSettings * generalSettings, const int index) const;
|
bool isThrTraceSrcAvailable(const GeneralSettings * generalSettings, const int index) const;
|
||||||
|
|
||||||
|
void limitsClear(const int index);
|
||||||
|
void limitsClearAll();
|
||||||
|
void limitsDelete(const int index);
|
||||||
|
void limitsGet(const int index, QByteArray & data);
|
||||||
|
void limitsInsert(const int index);
|
||||||
|
void limitsMove(const int index, const int offset);
|
||||||
|
void limitsSet(const int index, const QByteArray & data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void removeGlobalVar(int & var);
|
void removeGlobalVar(int & var);
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ void LimitData::clear()
|
|||||||
|
|
||||||
bool LimitData::isEmpty() const
|
bool LimitData::isEmpty() const
|
||||||
{
|
{
|
||||||
return (min == -1000 && max == 1000 && !revert && !offset && !ppmCenter && !symetrical && name[0] == '\0' && !curve.isSet());
|
LimitData tmp;
|
||||||
|
return !memcmp(this, &tmp, sizeof(LimitData));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LimitData::minToString() const
|
QString LimitData::minToString() const
|
||||||
|
|||||||
@@ -312,10 +312,9 @@ void ChannelsPanel::cmPaste()
|
|||||||
{
|
{
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
if (hasClipboardData(&data)) {
|
if (hasClipboardData(&data)) {
|
||||||
memcpy(&model->limitData[selectedIndex], data.constData(), sizeof(LimitData));
|
model->limitsSet(selectedIndex, data);
|
||||||
updateLine(selectedIndex);
|
updateLine(selectedIndex);
|
||||||
updateItemModels();
|
updateItemModels();
|
||||||
emit modified();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,22 +323,18 @@ void ChannelsPanel::cmDelete()
|
|||||||
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Delete Channel. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Delete Channel. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memmove(&model->limitData[selectedIndex], &model->limitData[selectedIndex + 1], (CPN_MAX_CHNOUT - (selectedIndex + 1)) * sizeof(LimitData));
|
model->limitsDelete(selectedIndex);
|
||||||
model->limitData[chnCapability - 1].clear();
|
|
||||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, -1);
|
|
||||||
|
|
||||||
for (int i = selectedIndex; i < chnCapability; i++) {
|
for (int i = selectedIndex; i < chnCapability; i++) {
|
||||||
updateLine(i);
|
updateLine(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateItemModels();
|
updateItemModels();
|
||||||
emit modified();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelsPanel::cmCopy()
|
void ChannelsPanel::cmCopy()
|
||||||
{
|
{
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
data.append((char*)&model->limitData[selectedIndex], sizeof(LimitData));
|
model->limitsGet(selectedIndex, data);
|
||||||
QMimeData *mimeData = new QMimeData;
|
QMimeData *mimeData = new QMimeData;
|
||||||
mimeData->setData(MIMETYPE_CHANNEL, data);
|
mimeData->setData(MIMETYPE_CHANNEL, data);
|
||||||
QApplication::clipboard()->setMimeData(mimeData,QClipboard::Clipboard);
|
QApplication::clipboard()->setMimeData(mimeData,QClipboard::Clipboard);
|
||||||
@@ -405,12 +400,18 @@ bool ChannelsPanel::moveUpAllowed() const
|
|||||||
|
|
||||||
void ChannelsPanel::cmMoveUp()
|
void ChannelsPanel::cmMoveUp()
|
||||||
{
|
{
|
||||||
swapData(selectedIndex, selectedIndex - 1);
|
model->limitsMove(selectedIndex, -1);
|
||||||
|
updateLine(selectedIndex - 1);
|
||||||
|
updateLine(selectedIndex);
|
||||||
|
updateItemModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelsPanel::cmMoveDown()
|
void ChannelsPanel::cmMoveDown()
|
||||||
{
|
{
|
||||||
swapData(selectedIndex, selectedIndex + 1);
|
model->limitsMove(selectedIndex, 1);
|
||||||
|
updateLine(selectedIndex);
|
||||||
|
updateLine(selectedIndex + 1);
|
||||||
|
updateItemModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelsPanel::cmClear(bool prompt)
|
void ChannelsPanel::cmClear(bool prompt)
|
||||||
@@ -420,11 +421,9 @@ void ChannelsPanel::cmClear(bool prompt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
model->limitData[selectedIndex].clear();
|
model->limitsClear(selectedIndex);
|
||||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_CLEAR, selectedIndex);
|
|
||||||
updateLine(selectedIndex);
|
updateLine(selectedIndex);
|
||||||
updateItemModels();
|
updateItemModels();
|
||||||
emit modified();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelsPanel::cmClearAll()
|
void ChannelsPanel::cmClearAll()
|
||||||
@@ -432,39 +431,19 @@ void ChannelsPanel::cmClearAll()
|
|||||||
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear all Channels. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear all Channels. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < chnCapability; i++) {
|
model->limitsClearAll();
|
||||||
model->limitData[i].clear();
|
update();
|
||||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_CLEAR, i);
|
|
||||||
updateLine(i);
|
|
||||||
}
|
|
||||||
updateItemModels();
|
updateItemModels();
|
||||||
emit modified();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelsPanel::cmInsert()
|
void ChannelsPanel::cmInsert()
|
||||||
{
|
{
|
||||||
memmove(&model->limitData[selectedIndex + 1], &model->limitData[selectedIndex], (CPN_MAX_CHNOUT - (selectedIndex + 1)) * sizeof(LimitData));
|
model->limitsInsert(selectedIndex);
|
||||||
model->limitData[selectedIndex].clear();
|
for (int i = selectedIndex; i < chnCapability; i++) {
|
||||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1);
|
updateLine(i);
|
||||||
update();
|
|
||||||
updateItemModels();
|
|
||||||
emit modified();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChannelsPanel::swapData(int idx1, int idx2)
|
|
||||||
{
|
|
||||||
if ((idx1 != idx2) && (!model->limitData[idx1].isEmpty() || !model->limitData[idx2].isEmpty())) {
|
|
||||||
LimitData chntmp = model->limitData[idx2];
|
|
||||||
LimitData *chn1 = &model->limitData[idx1];
|
|
||||||
LimitData *chn2 = &model->limitData[idx2];
|
|
||||||
memcpy(chn2, chn1, sizeof(LimitData));
|
|
||||||
memcpy(chn1, &chntmp, sizeof(LimitData));
|
|
||||||
model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_SWAP, idx1, idx2);
|
|
||||||
updateLine(idx1);
|
|
||||||
updateLine(idx2);
|
|
||||||
updateItemModels();
|
|
||||||
emit modified();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateItemModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelsPanel::connectItemModelEvents(const FilteredItemModel * itemModel)
|
void ChannelsPanel::connectItemModelEvents(const FilteredItemModel * itemModel)
|
||||||
@@ -487,4 +466,5 @@ void ChannelsPanel::onItemModelUpdateComplete()
|
|||||||
void ChannelsPanel::updateItemModels()
|
void ChannelsPanel::updateItemModels()
|
||||||
{
|
{
|
||||||
sharedItemModels->update(AbstractItemModel::IMUE_Channels);
|
sharedItemModels->update(AbstractItemModel::IMUE_Channels);
|
||||||
|
emit modified();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ class ChannelsPanel : public ModelPanel
|
|||||||
bool insertAllowed() const;
|
bool insertAllowed() const;
|
||||||
bool moveDownAllowed() const;
|
bool moveDownAllowed() const;
|
||||||
bool moveUpAllowed() const;
|
bool moveUpAllowed() const;
|
||||||
void swapData(int idx1, int idx2);
|
|
||||||
QLineEdit *name[CPN_MAX_CHNOUT];
|
QLineEdit *name[CPN_MAX_CHNOUT];
|
||||||
LimitsGroup *chnOffset[CPN_MAX_CHNOUT];
|
LimitsGroup *chnOffset[CPN_MAX_CHNOUT];
|
||||||
LimitsGroup *chnMin[CPN_MAX_CHNOUT];
|
LimitsGroup *chnMin[CPN_MAX_CHNOUT];
|
||||||
|
|||||||
Reference in New Issue
Block a user