mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:25:56 +00:00
UI: RuleEdit: Move Preset Rules
This commit is contained in:
parent
088293b3bb
commit
8d7dcb147b
@ -275,15 +275,12 @@ QLayout *RuleEditDialog::setupRuleSetHeaderLayout()
|
||||
|
||||
// m_ruleSetView->setVisible(false);
|
||||
});
|
||||
m_btRemovePresetRule = ControlUtil::createFlatToolButton(":/icons/delete.png", [&] {
|
||||
ruleSetModel()->remove(ruleSetCurrentIndex());
|
||||
});
|
||||
m_btUpPresetRule = ControlUtil::createIconToolButton(":/icons/bullet_arrow_up.png", [&] {
|
||||
// TODO
|
||||
});
|
||||
m_btDownPresetRule = ControlUtil::createIconToolButton(":/icons/bullet_arrow_down.png", [&] {
|
||||
// TODO
|
||||
});
|
||||
m_btRemovePresetRule = ControlUtil::createFlatToolButton(
|
||||
":/icons/delete.png", [&] { ruleSetModel()->remove(ruleSetCurrentIndex()); });
|
||||
m_btUpPresetRule = ControlUtil::createIconToolButton(
|
||||
":/icons/bullet_arrow_up.png", [&] { ruleSetModel()->moveUp(ruleSetCurrentIndex()); });
|
||||
m_btDownPresetRule = ControlUtil::createIconToolButton(":/icons/bullet_arrow_down.png",
|
||||
[&] { ruleSetModel()->moveDown(ruleSetCurrentIndex()); });
|
||||
|
||||
auto layout = ControlUtil::createHLayoutByWidgets(
|
||||
{ m_btAddPresetRule, m_btRemovePresetRule, ControlUtil::createVSeparator(),
|
||||
|
@ -53,9 +53,23 @@ void RuleSetModel::addRule(const RuleRow &ruleRow)
|
||||
|
||||
void RuleSetModel::remove(int row)
|
||||
{
|
||||
row = adjustRow(row);
|
||||
|
||||
m_ruleSet.remove(row);
|
||||
|
||||
StringListModel::remove(row);
|
||||
|
||||
setEdited(true);
|
||||
}
|
||||
|
||||
void RuleSetModel::move(int fromRow, int toRow)
|
||||
{
|
||||
if (!StringListModel::canMove(fromRow, toRow))
|
||||
return;
|
||||
|
||||
m_ruleSet.move(fromRow, toRow);
|
||||
|
||||
StringListModel::move(fromRow, toRow);
|
||||
|
||||
setEdited(true);
|
||||
}
|
||||
|
@ -29,6 +29,10 @@ public slots:
|
||||
|
||||
void remove(int row = -1) override;
|
||||
|
||||
void move(int fromRow, int toRow);
|
||||
inline void moveUp(int row) { move(row, row - 1); }
|
||||
inline void moveDown(int row) { move(row, row + 1); }
|
||||
|
||||
private:
|
||||
bool m_edited = false;
|
||||
|
||||
|
@ -66,6 +66,26 @@ void StringListModel::replace(const QString &text, int row)
|
||||
emit dataChanged(modelIndex, modelIndex);
|
||||
}
|
||||
|
||||
bool StringListModel::canMove(int fromRow, int toRow)
|
||||
{
|
||||
if (fromRow == toRow || fromRow < 0 || toRow < 0)
|
||||
return false;
|
||||
|
||||
const int listSize = list().size();
|
||||
if (fromRow >= listSize || toRow >= listSize)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void StringListModel::move(int fromRow, int toRow)
|
||||
{
|
||||
beginMoveRows(
|
||||
QModelIndex(), fromRow, fromRow, QModelIndex(), toRow + (toRow > fromRow ? 1 : 0));
|
||||
m_list.move(fromRow, toRow);
|
||||
endMoveRows();
|
||||
}
|
||||
|
||||
void StringListModel::reset()
|
||||
{
|
||||
if (isChanging())
|
||||
|
@ -26,6 +26,9 @@ public slots:
|
||||
virtual void remove(int row = -1);
|
||||
virtual void replace(const QString &text, int row = -1);
|
||||
|
||||
virtual bool canMove(int fromRow, int toRow);
|
||||
virtual void move(int fromRow, int toRow);
|
||||
|
||||
void reset();
|
||||
void refresh();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user