20 return plist.at(index.row());
30 const QModelIndex &si = index(r, 0);
31 const QModelIndex &ei = index(r, 2);
32 emit dataChanged(si, ei);
42 beginInsertRows(QModelIndex(), r, r);
43 QModelIndex i = index(r, 0);
51 beginRemoveRows(QModelIndex(), r, r);
59 if ((row = plist.indexOf(phr)) == -1)
77 if ((role == Qt::DisplayRole) && (orientation == Qt::Horizontal)) {
80 return tr(
"Source phrase");
82 return tr(
"Translation");
84 return tr(
"Definition");
95 Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
97 if (plist.at(index.row())->phraseBook()
98 && (index.column() != 2))
99 flags |= Qt::ItemIsEditable;
105 int row = index.row();
106 int column = index.column();
108 if (!index.isValid() || row >= plist.size() || role != Qt::EditRole)
111 Phrase *phrase = plist.at(row);
115 phrase->setSource(value.toString());
118 phrase->setTarget(value.toString());
121 phrase->setDefinition(value.toString());
127 emit dataChanged(index, index);
133 int row = index.row();
134 int column = index.column();
136 if (row >= plist.size() || !index.isValid())
139 Phrase *phrase = plist.at(row);
141 if (role == Qt::DisplayRole || (role == Qt::ToolTipRole && column != 2)) {
144 return phrase->source().simplified();
146 return phrase->target().simplified();
148 return phrase->definition();
151 else if (role == Qt::EditRole && column != 2) {
154 return phrase->source();
156 return phrase->target();
Phrase * phrase(const QModelIndex &index) const
int rowCount(const QModelIndex &) const override
Returns the number of rows under the given parent.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Sets the role data for the item at index to value.
void setPhrase(const QModelIndex &indx, Phrase *ph)
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the item flags for the given index.
QModelIndex addPhrase(Phrase *p)
int columnCount(const QModelIndex &) const override
Returns the number of columns for the children of the given parent.
QModelIndex index(Phrase *const phr) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns the data for the given role and section in the header with the specified orientation.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
void removePhrase(const QModelIndex &index)
Combined button and popup list for selecting options.