src/actions.cc

changeset 787
67cc5b47bbff
parent 786
71d786ce0dcc
child 788
c9d1dad83ad0
equal deleted inserted replaced
786:71d786ce0dcc 787:67cc5b47bbff
287 { 287 {
288 for (LDObjectPtr obj : getCurrentDocument()->objects()) 288 for (LDObjectPtr obj : getCurrentDocument()->objects())
289 obj->select(); 289 obj->select();
290 290
291 ui->objectList->selectAll(); 291 ui->objectList->selectAll();
292 refresh();
292 } 293 }
293 294
294 // ============================================================================= 295 // =============================================================================
295 // 296 //
296 DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) 297 DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A))
297 { 298 {
298 int colnum = getSelectedColor(); 299 if (selection().isEmpty())
299 300 return;
300 if (colnum == -1) 301
301 return; // no consensus on color 302 QList<int> colors;
302 303
304 for (LDObjectPtr obj : selection())
305 {
306 if (obj->isColored())
307 colors << obj->color();
308 }
309
310 removeDuplicates (colors);
303 getCurrentDocument()->clearSelection(); 311 getCurrentDocument()->clearSelection();
304 312
305 for (LDObjectPtr obj : getCurrentDocument()->objects()) 313 for (LDObjectPtr obj : getCurrentDocument()->objects())
306 if (obj->color() == colnum) 314 {
315 if (colors.contains (obj->color()))
307 obj->select(); 316 obj->select();
317 }
308 318
309 updateSelection(); 319 updateSelection();
320 refresh();
310 } 321 }
311 322
312 // ============================================================================= 323 // =============================================================================
313 // 324 //
314 DEFINE_ACTION (SelectByType, 0) 325 DEFINE_ACTION (SelectByType, 0)
315 { 326 {
316 if (selection().isEmpty()) 327 if (selection().isEmpty())
317 return; 328 return;
318 329
319 LDObjectType type = getUniformSelectedType(); 330 QList<LDObjectType> types;
320 331 QStringList subfilenames;
321 if (type == OBJ_Unknown) 332
322 return; 333 for (LDObjectPtr obj : selection())
323 334 {
324 // If we're selecting subfile references, the reference filename must also 335 types << obj->type();
325 // be uniform. 336
326 String refName; 337 if (types.last() == OBJ_Subfile)
327 338 subfilenames << obj.staticCast<LDSubfile>()->fileInfo()->name();
328 if (type == OBJ_Subfile) 339 }
329 { 340
330 refName = selection()[0].staticCast<LDSubfile>()->fileInfo()->name(); 341 removeDuplicates (types);
331 342 removeDuplicates (subfilenames);
332 for (LDObjectPtr obj : selection())
333 if (obj.staticCast<LDSubfile>()->fileInfo()->name() != refName)
334 return;
335 }
336
337 getCurrentDocument()->clearSelection(); 343 getCurrentDocument()->clearSelection();
338 344
339 for (LDObjectPtr obj : getCurrentDocument()->objects()) 345 for (LDObjectPtr obj : getCurrentDocument()->objects())
340 { 346 {
341 if (obj->type() != type) 347 LDObjectType type = obj->type();
348
349 if (not types.contains (type))
342 continue; 350 continue;
343 351
344 if (type == OBJ_Subfile && obj.staticCast<LDSubfile>()->fileInfo()->name() != refName) 352 // For subfiles, type check is not enough, we check the name of the document as well.
353 if (type == OBJ_Subfile && not subfilenames.contains (obj.staticCast<LDSubfile>()->fileInfo()->name()))
345 continue; 354 continue;
346 355
347 obj->select(); 356 obj->select();
348 } 357 }
349 358
350 updateSelection(); 359 updateSelection();
360 refresh();
351 } 361 }
352 362
353 // ============================================================================= 363 // =============================================================================
354 // 364 //
355 DEFINE_ACTION (GridCoarse, 0) 365 DEFINE_ACTION (GridCoarse, 0)

mercurial