| 93 | |
| 94 | |
| 95 | QValidator::State ProjectItemValidator::validate(QString& input, int& pos) const |
| 96 | { |
| 97 | Q_UNUSED( pos ); |
| 98 | KDevelop::ProjectModel* model = KDevelop::ICore::self()->projectController()->projectModel(); |
| 99 | QStringList path = joinProjectBasePath( KDevelop::splitWithEscaping( input, sep, escape ), mBase ); |
| 100 | QModelIndex idx = model->pathToIndex( path ); |
| 101 | QValidator::State state = input.isEmpty() ? QValidator::Intermediate : QValidator::Invalid; |
| 102 | if( idx.isValid() ) |
| 103 | { |
| 104 | state = QValidator::Acceptable; |
| 105 | } else if( path.count() > 1 ) |
| 106 | { |
| 107 | // Check beginning of path and if that is ok, then try to find a child |
| 108 | QString end = path.takeLast(); |
| 109 | idx = model->pathToIndex( path ); |
| 110 | if( idx.isValid() ) |
| 111 | { |
| 112 | for( int i = 0; i < model->rowCount( idx ); i++ ) |
| 113 | { |
| 114 | if( model->data( model->index( i, 0, idx ) ).toString().startsWith( end, Qt::CaseInsensitive ) ) |
| 115 | { |
| 116 | state = QValidator::Intermediate; |
| 117 | break; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } else if( path.count() == 1 ) |
| 122 | { |
| 123 | // Check for a project whose name beings with the input |
| 124 | QString first = path.first(); |
| 125 | const auto projects = KDevelop::ICore::self()->projectController()->projects(); |
| 126 | bool matchesAnyName = std::any_of(projects.begin(), projects.end(), [&](KDevelop::IProject* project) { |
| 127 | return (project->name().startsWith(first, Qt::CaseInsensitive)); |
| 128 | }); |
| 129 | if (matchesAnyName) { |
| 130 | state = QValidator::Intermediate; |
| 131 | } |
| 132 | } |
| 133 | return state; |
| 134 | } |
| 135 | |
| 136 | class ProjectItemLineEditPrivate |
| 137 | { |
no test coverage detected