extended double click functionality in tables

loadfix
Marc Zinnschlag 10 years ago
parent 6ff41c6a00
commit a9f5632afd

@ -182,11 +182,71 @@ void CSVWorld::Table::mouseDoubleClickEvent (QMouseEvent *event)
Qt::KeyboardModifiers modifiers =
event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier);
if (!modifiers)
DragRecordTable::mouseDoubleClickEvent (event);
else
QModelIndex index = currentIndex();
selectionModel()->select (index,
QItemSelectionModel::Clear | QItemSelectionModel::Select | QItemSelectionModel::Rows);
std::map<Qt::KeyboardModifiers, DoubleClickAction>::iterator iter =
mDoubleClickActions.find (modifiers);
if (iter==mDoubleClickActions.end())
{
event->accept();
return;
}
switch (iter->second)
{
case Action_None:
event->accept();
break;
case Action_InPlaceEdit:
DragRecordTable::mouseDoubleClickEvent (event);
break;
case Action_EditRecord:
event->accept();
editRecord();
break;
case Action_View:
event->accept();
viewRecord();
break;
case Action_Revert:
event->accept();
if (mDispatcher->canRevert())
mDispatcher->executeRevert();
break;
case Action_Delete:
event->accept();
if (mDispatcher->canDelete())
mDispatcher->executeDelete();
break;
case Action_EditRecordAndClose:
event->accept();
editRecord();
emit closeRequest();
break;
case Action_ViewAndClose:
event->accept();
viewRecord();
emit closeRequest();
break;
}
}
@ -297,6 +357,11 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id,
this, SLOT (selectionSizeUpdate ()));
setAcceptDrops(true);
mDoubleClickActions.insert (std::make_pair (0, Action_InPlaceEdit));
mDoubleClickActions.insert (std::make_pair (Qt::ShiftModifier, Action_EditRecord));
mDoubleClickActions.insert (std::make_pair (Qt::ControlModifier, Action_View));
mDoubleClickActions.insert (std::make_pair (Qt::ShiftModifier | Qt::ControlModifier, Action_EditRecordAndClose));
}
void CSVWorld::Table::setEditLock (bool locked)
@ -417,6 +482,9 @@ void CSVWorld::Table::editCell()
void CSVWorld::Table::viewRecord()
{
if (!(mModel->getFeatures() & CSMWorld::IdTableBase::Feature_View))
return;
QModelIndexList selectedRows = selectionModel()->selectedRows();
if (selectedRows.size()==1)

@ -36,6 +36,18 @@ namespace CSVWorld
{
Q_OBJECT
enum DoubleClickAction
{
Action_None,
Action_InPlaceEdit,
Action_EditRecord,
Action_View,
Action_Revert,
Action_Delete,
Action_EditRecordAndClose,
Action_ViewAndClose
};
std::vector<CommandDelegate *> mDelegates;
QAction *mEditAction;
QAction *mCreateAction;
@ -53,8 +65,8 @@ namespace CSVWorld
CSMWorld::IdTableBase *mModel;
int mRecordStatusDisplay;
CSMWorld::CommandDispatcher *mDispatcher;
CSMWorld::UniversalId mEditCellId;
std::map<Qt::KeyboardModifiers, DoubleClickAction> mDoubleClickActions;
private:
@ -98,6 +110,8 @@ namespace CSVWorld
void cloneRequest(const CSMWorld::UniversalId&);
void closeRequest();
private slots:
void editCell();

@ -69,6 +69,8 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
connect(mFilterBox, SIGNAL(recordDropped(std::vector<CSMWorld::UniversalId>&, Qt::DropAction)),
this, SLOT(createFilterRequest(std::vector<CSMWorld::UniversalId>&, Qt::DropAction)));
connect (mTable, SIGNAL (closeRequest()), this, SLOT (closeRequest()));
}
void CSVWorld::TableSubView::setEditLock (bool locked)
@ -150,3 +152,8 @@ bool CSVWorld::TableSubView::eventFilter (QObject* object, QEvent* event)
}
return false;
}
void CSVWorld::TableSubView::closeRequest()
{
deleteLater();
}

@ -63,6 +63,8 @@ namespace CSVWorld
void cloneRequest (const CSMWorld::UniversalId& toClone);
void createFilterRequest(std::vector< CSMWorld::UniversalId >& types,
Qt::DropAction action);
void closeRequest();
};
}

Loading…
Cancel
Save