ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RListWidget Class Reference

#include <src/ckb/rlistwidget.h>

+ Inheritance diagram for RListWidget:
+ Collaboration diagram for RListWidget:

Signals

void orderChanged ()
 

Public Member Functions

 RListWidget (QWidget *parent=0)
 

Private Slots

void timerTick ()
 
void enter (QListWidgetItem *item)
 
void change (QListWidgetItem *item)
 

Private Member Functions

void rescanItems ()
 

Private Attributes

QVariant currentData
 
QList< QVariant > previousItems
 
QVariant dragged
 
QTimer reorderTimer
 

Static Private Attributes

static const int DATA_ROLE = Qt::UserRole + 100
 

Detailed Description

Definition at line 9 of file rlistwidget.h.

Constructor & Destructor Documentation

RListWidget::RListWidget ( QWidget parent = 0)
explicit

Definition at line 4 of file rlistwidget.cpp.

References change(), enter(), reorderTimer, and timerTick().

4  :
5  QListWidget(parent)
6 {
7  setDragDropMode(QAbstractItemView::InternalMove);
8  setMovement(QListView::Snap);
9 
10  reorderTimer.setSingleShot(true);
11  reorderTimer.setInterval(100);
12  connect(&reorderTimer, SIGNAL(timeout()), this, SLOT(timerTick()));
13 
14  connect(this, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(enter(QListWidgetItem*)));
15  connect(this, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(change(QListWidgetItem*)));
16 }
void timerTick()
Definition: rlistwidget.cpp:18
QTimer reorderTimer
Definition: rlistwidget.h:27
void change(QListWidgetItem *item)
Definition: rlistwidget.cpp:54
void enter(QListWidgetItem *item)
Definition: rlistwidget.cpp:47

+ Here is the call graph for this function:

Member Function Documentation

void RListWidget::change ( QListWidgetItem *  item)
privateslot

Definition at line 54 of file rlistwidget.cpp.

References reorderTimer.

Referenced by RListWidget().

54  {
55  reorderTimer.stop();
56  reorderTimer.start();
57 }
QTimer reorderTimer
Definition: rlistwidget.h:27

+ Here is the caller graph for this function:

void RListWidget::enter ( QListWidgetItem *  item)
privateslot

Definition at line 47 of file rlistwidget.cpp.

References DATA_ROLE, dragged, and rescanItems().

Referenced by RListWidget().

47  {
48  rescanItems();
49  // Check for drag+drop setup
50  if(item)
51  dragged = item->data(DATA_ROLE);
52 }
QVariant dragged
Definition: rlistwidget.h:26
void rescanItems()
Definition: rlistwidget.cpp:59
static const int DATA_ROLE
Definition: rlistwidget.h:29

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RListWidget::orderChanged ( )
signal

Definition at line 141 of file moc_rlistwidget.cpp.

Referenced by timerTick().

142 {
143  QMetaObject::activate(this, &staticMetaObject, 0, Q_NULLPTR);
144 }

+ Here is the caller graph for this function:

void RListWidget::rescanItems ( )
private

Definition at line 59 of file rlistwidget.cpp.

References DATA_ROLE, and previousItems.

Referenced by enter().

59  {
60  QList<QVariant> newItems;
61  int c = count();
62  for(int i = 0; i < c; i++){
63  QVariant data = this->item(i)->data(DATA_ROLE);
64  if(data.isNull()){
65  // Generate the ID for this item if it doesn't already exist
66  data = QUuid::createUuid();
67  this->item(i)->setData(DATA_ROLE, data);
68  }
69  newItems.append(data);
70  }
71  previousItems = newItems;
72 }
QList< QVariant > previousItems
Definition: rlistwidget.h:25
static const int DATA_ROLE
Definition: rlistwidget.h:29

+ Here is the caller graph for this function:

void RListWidget::timerTick ( )
privateslot

Definition at line 18 of file rlistwidget.cpp.

References DATA_ROLE, dragged, orderChanged(), and previousItems.

Referenced by RListWidget().

18  {
19  bool reordered = false;
20  QListWidgetItem* reselect = 0;
21  QList<QVariant> newItems;
22  // Scan the item list to see if they changed
23  int c = count();
24  for(int i = 0; i < c; i++){
25  QListWidgetItem* itm = item(i);
26  QVariant data = itm->data(DATA_ROLE);
27  newItems.append(data);
28  if(i >= previousItems.count() || data != previousItems[i])
29  reordered = true;
30  // Re-select the dragged item (if any)
31  if(data == dragged)
32  reselect = itm;
33  }
34  if(previousItems.length() != newItems.length())
35  return;
36  if(reordered){
37  previousItems = newItems;
38  emit orderChanged();
39  if(reselect){
40  reselect->setSelected(true);
41  setCurrentItem(reselect);
42  dragged = QVariant();
43  }
44  }
45 }
QVariant dragged
Definition: rlistwidget.h:26
QList< QVariant > previousItems
Definition: rlistwidget.h:25
static const int DATA_ROLE
Definition: rlistwidget.h:29

+ Here is the caller graph for this function:

Field Documentation

QVariant RListWidget::currentData
private

Definition at line 24 of file rlistwidget.h.

const int RListWidget::DATA_ROLE = Qt::UserRole + 100
staticprivate

Definition at line 29 of file rlistwidget.h.

Referenced by enter(), rescanItems(), and timerTick().

QVariant RListWidget::dragged
private

Definition at line 26 of file rlistwidget.h.

Referenced by enter(), and timerTick().

QList<QVariant> RListWidget::previousItems
private

Definition at line 25 of file rlistwidget.h.

Referenced by rescanItems(), and timerTick().

QTimer RListWidget::reorderTimer
private

Definition at line 27 of file rlistwidget.h.

Referenced by change(), and RListWidget().


The documentation for this class was generated from the following files: