Based jointly on idempotents and modular Golomb rulers, we construct a class of nonbinary cyclic low-density parity-check (LDPC) codes. The defining parity-check matrix is a sparse circulant, on which we put two constraints: 1) the characteristic polynomial is an idempotent, 2) the nonzero elements of the first row are located on a modular Golomb ruler. We show that the second constraint forms a necessary and sufficient condition for the Tanner graph to have no cycles of length 4. The minimum distance of the code is proved equal to the column weight of the parity-check matrix plus one. A search algorithm is presented, with which we obtain some high rate codes with large minimum distances. The issue of code equivalence is also discussed. Simulation results show that the obtained codes perform well under iterative decoding.