| 1 |
/****************************************************************************** |
| 2 |
|
| 3 |
This source file is part of the Avogadro project. |
| 4 |
|
| 5 |
Copyright 2015 Marcus Johansson <[email protected]> |
| 6 |
|
| 7 |
This source code is released under the New BSD License, (the "License"). |
| 8 |
|
| 9 |
Unless required by applicable law or agreed to in writing, software |
| 10 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
See the License for the specific language governing permissions and |
| 13 |
limitations under the License. |
| 14 |
|
| 15 |
******************************************************************************/ |
| 16 |
|
| 17 |
#include "operationstablemodel.h" |
| 18 |
#include "symmetryutil.h" |
| 19 |
|
| 20 |
using namespace Avogadro::QtPlugins::SymmetryUtil; |
| 21 |
|
| 22 |
namespace Avogadro::QtPlugins { |
| 23 |
|
| 24 |
OperationsTableModel::OperationsTableModel(QObject* parent) |
| 25 |
: QAbstractTableModel(parent) |
| 26 |
{ |
| 27 |
m_operations = nullptr; |
| 28 |
m_operations_size = 0; |
| 29 |
} |
| 30 |
|
| 31 |
OperationsTableModel::~OperationsTableModel() {} |
| 32 |
|
| 33 |
void OperationsTableModel::setOperations( |
| 34 |
int operations_size, const msym::msym_symmetry_operation_t* operations) |
| 35 |
{ |
| 36 |
beginResetModel(); |
| 37 |
m_operations_size = operations_size; |
| 38 |
m_operations = operations; |
| 39 |
endResetModel(); |
| 40 |
} |
| 41 |
|
| 42 |
/* Qt */ |
| 43 |
|
| 44 |
QVariant OperationsTableModel::headerData(int section, |
| 45 |
Qt::Orientation orientation, |
| 46 |
int role) const |
| 47 |
{ |
| 48 |
|
| 49 |
if (role != Qt::DisplayRole) |
| 50 |
return QVariant(); |
| 51 |
|
| 52 |
QString name; |
| 53 |
|
| 54 |
if (orientation == Qt::Horizontal) { |
| 55 |
switch (Column(section)) { |
| 56 |
case ColumnType: |
| 57 |
return tr("Type"); |
| 58 |
case ColumnClass: |
| 59 |
return tr("Class"); |
| 60 |
case ColumnVector: |
| 61 |
return tr("Element"); |
| 62 |
default: |
| 63 |
return QVariant(); |
| 64 |
} |
| 65 |
} else { |
| 66 |
return QString::number(section + 1); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
QVariant OperationsTableModel::data(const QModelIndex& index, int role) const |
| 71 |
{ |
| 72 |
if (role != Qt::DisplayRole || !index.isValid()) |
| 73 |
return QVariant(); |
| 74 |
|
| 75 |
const msym::msym_symmetry_operation_t* operation = &m_operations[index.row()]; |
| 76 |
|
| 77 |
switch (Column(index.column())) { |
| 78 |
case ColumnType: |
| 79 |
return operationSymbol(operation); |
| 80 |
case ColumnClass: |
| 81 |
return operation->cla; |
| 82 |
case ColumnVector: |
| 83 |
return QString("NA"); |
| 84 |
default: |
| 85 |
return QVariant(); |
| 86 |
} |
| 87 |
} |
| 88 |
} // namespace Avogadro::QtPlugins |