Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
9c6436b6
Commit
9c6436b6
authored
Aug 29, 2016
by
LEFEBVREJP email
Browse files
Adding a TableView class that allows for copy functionality.
parent
ead0cd0b
Changes
4
Hide whitespace changes
Inline
Side-by-side
radixwidgets/CMakeLists.txt
View file @
9c6436b6
...
...
@@ -22,6 +22,7 @@ TRIBITS_SUBPACKAGE(widgets)
# C/C++ headers
SET
(
HEADERS
tabwidget.hh
tableview.hh
)
#
# Moc the header files
...
...
@@ -48,6 +49,7 @@ ENDIF()
# C/C++ source
SET
(
SOURCES
tabwidget.cc
tableview.cc
)
##---------------------------------------------------------------------------##
...
...
radixwidgets/cmake/Dependencies.cmake
View file @
9c6436b6
...
...
@@ -10,7 +10,7 @@ ENDIF()
IF
(
USE_QT4
)
SET
(
QT_PACKAGES QT
)
ELSE
()
SET
(
QT_PACKAGES Qt5Gui
)
SET
(
QT_PACKAGES Qt5Gui
Qt5Widgets Qt5Core
)
ENDIF
()
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES
(
...
...
radixwidgets/tableview.cc
0 → 100644
View file @
9c6436b6
#include
"radixwidgets/tableview.hh"
#include
<QApplication>
#include
<QHeaderView>
#include
<QClipBoard>
#include
<QKeyEvent>
namespace
radix
{
TableView
::
TableView
(
QWidget
*
parent
)
:
QTableView
(
parent
)
{
}
void
TableView
::
copy
()
{
// selected items
auto
selected
=
selectionModel
()
->
selectedIndexes
();
// selection is empty
if
(
selected
.
empty
()
)
{
return
;
}
// data cells, unique rows, unique columns
QHash
<
int
,
QHash
<
int
,
QString
>>
cells
;
QList
<
int
>
rows
;
QList
<
int
>
cols
;
// process selected indices
{
// row/column sets
QSet
<
int
>
rs
;
QSet
<
int
>
cs
;
// determine min/max row/columns
for
(
const
auto
&
index
:
selected
)
{
rs
<<
index
.
row
();
cs
<<
index
.
column
();
cells
[
index
.
row
()][
index
.
column
()]
=
index
.
data
().
toString
();
}
rows
=
rs
.
toList
();
cols
=
cs
.
toList
();
qSort
(
rows
);
qSort
(
cols
);
}
// row/column header models
auto
rhmodel
=
verticalHeader
()
->
model
();
auto
chmodel
=
horizontalHeader
()
->
model
();
// table data
QString
data
;
// add column headers
for
(
auto
col
:
cols
)
{
data
.
append
(
'\t'
).
append
(
chmodel
->
headerData
(
col
,
Qt
::
Horizontal
).
toString
());
}
// add cell data
for
(
auto
row
:
rows
)
{
// add row header
data
.
append
(
'\n'
).
append
(
rhmodel
->
headerData
(
row
,
Qt
::
Vertical
).
toString
());
// add row's cells
for
(
auto
col
:
cols
)
{
data
.
append
(
'\t'
);
// row's data
auto
&
rd
=
cells
[
row
];
// current cell is valid
if
(
rd
.
contains
(
col
))
{
data
.
append
(
rd
[
col
]);
}
}
}
// store in clipboard
QApplication
::
clipboard
()
->
setText
(
data
);
}
void
TableView
::
keyPressEvent
(
QKeyEvent
*
event
)
{
if
(
event
->
matches
(
QKeySequence
::
Copy
)
)
{
copy
();
}
else
{
QTableView
::
keyPressEvent
(
event
);
}
}
}
// namespace radix
radixwidgets/tableview.hh
0 → 100644
View file @
9c6436b6
#ifndef RADIX_RADIXWIDGETS_TABLEVIEW_HH_
#define RADIX_RADIXWIDGETS_TABLEVIEW_HH_
#include
<QTableView>
namespace
radix
{
/**
* * @brief The TableWidget class
* * Allows extentions of the QTableWidget
* provides for copy
* */
class
TableView
:
public
QTableView
{
Q_OBJECT
public:
TableView
(
QWidget
*
parent
=
0
);
private:
void
copy
();
public
slots
:
void
keyPressEvent
(
QKeyEvent
*
event
);
};
}
// namespace radix
#endif
/** RADIX_RADIXWIDGETS_TABLEVIEW_HH_ */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment