| 1848 | } |
| 1849 | |
| 1850 | QWidget *UBDocumentTreeItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| 1851 | { |
| 1852 | Q_UNUSED(option); |
| 1853 | //N/C - NNE - 20140407 : Add the test for the index column. |
| 1854 | if(index.column() == 0){ |
| 1855 | mExistingFileNames.clear(); |
| 1856 | const UBDocumentTreeModel *docModel = 0; |
| 1857 | |
| 1858 | const UBSortFilterProxyModel *proxy = dynamic_cast<const UBSortFilterProxyModel*>(index.model()); |
| 1859 | QModelIndex sourceIndex; |
| 1860 | |
| 1861 | if(proxy){ |
| 1862 | docModel = dynamic_cast<UBDocumentTreeModel*>(proxy->sourceModel()); |
| 1863 | sourceIndex = proxy->mapToSource(index); |
| 1864 | }else{ |
| 1865 | docModel = dynamic_cast<const UBDocumentTreeModel*>(index.model()); |
| 1866 | } |
| 1867 | |
| 1868 | if (docModel) |
| 1869 | { |
| 1870 | mExistingFileNames = docModel->nodeNameList(sourceIndex.parent()); |
| 1871 | mExistingFileNames.removeOne(sourceIndex.data().toString()); |
| 1872 | |
| 1873 | UBDocumentTreeNode* sourceNode = docModel->nodeFromIndex(sourceIndex); |
| 1874 | |
| 1875 | if (sourceNode) |
| 1876 | { |
| 1877 | QLineEdit *nameEditor = new QLineEdit(parent); |
| 1878 | QList<UBDocumentTreeNode*> nodeChildren = docModel->nodeChildrenFromIndex(sourceIndex.parent()); |
| 1879 | nodeChildren.removeOne(sourceNode); |
| 1880 | |
| 1881 | UBValidator* validator = new UBValidator(nodeChildren, sourceNode->nodeType()); |
| 1882 | nameEditor->setValidator(validator); |
| 1883 | connect(nameEditor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); |
| 1884 | connect(nameEditor, SIGNAL(textChanged(QString)), this, SLOT(processChangedText(QString))); |
| 1885 | |
| 1886 | return nameEditor; |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | return nullptr; |
| 1891 | } |
| 1892 | |
| 1893 | //N/C - NNe - 20140407 : the other column are not editable. |
| 1894 | return 0; |
| 1895 | } |
| 1896 | |
| 1897 | void UBDocumentTreeItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const |
| 1898 | { |
nothing calls this directly
no test coverage detected